Leviathan  0.8.0.0
Leviathan game engine
Leviathan::GeometryHelpers Class Reference

Helpers for generating procedural geometry. More...

#include <GeometryHelpers.h>

Public Member Functions

 GeometryHelpers ()=delete
 

Static Public Member Functions

static DLLEXPORT Ogre::MeshPtr CreateScreenSpaceQuad (const std::string &meshname, float x, float y, float width, float height)
 Creates a screen space plane with UV coordinates. More...
 
static DLLEXPORT Ogre::MeshPtr CreateXZPlane (const std::string &meshname, float width, float height)
 Creates a plane with specific size and UV coordinates with 0, 0 on top left. More...
 

Detailed Description

Helpers for generating procedural geometry.

Definition at line 11 of file GeometryHelpers.h.

Constructor & Destructor Documentation

◆ GeometryHelpers()

Leviathan::GeometryHelpers::GeometryHelpers ( )
delete

Member Function Documentation

◆ CreateScreenSpaceQuad()

DLLEXPORT Ogre::MeshPtr GeometryHelpers::CreateScreenSpaceQuad ( const std::string &  meshname,
float  x,
float  y,
float  width,
float  height 
)
static

Creates a screen space plane with UV coordinates.

The coordinates are in screen space -1 - 1 where -1 is the left and top of the screen so a full screen quad would be CreateScreenSpaceQuad(-1, -1, 2, 2)

Parameters
meshnameThe name of the created mesh, must be unique
Todo:
Parameter to specify if shadow geometry is needed

Definition at line 12 of file GeometryHelpers.cpp.

14 {
15  Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(
16  meshname, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
17 
18  Ogre::SubMesh* subMesh = mesh->createSubMesh();
19 
20  Ogre::RenderSystem* renderSystem = Ogre::Root::getSingleton().getRenderSystem();
21  Ogre::VaoManager* vaoManager = renderSystem->getVaoManager();
22 
23  Ogre::VertexElement2Vec vertexElements;
24  vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3, Ogre::VES_POSITION));
25  vertexElements.push_back(
26  Ogre::VertexElement2(Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES));
27 
28  // This is a fullscreen quad in screenspace (so no transform matrix is used)
29  float vertexData[] = {// First vertex
30  x, y, 0, 0, 1,
31  // Second
32  x + width, y, 0, 1, 1,
33  // Third
34  x + width, y + width, 0, 1, 0,
35  // Fourth
36  x, y + width, 0, 0, 0};
37 
38  Ogre::VertexBufferPacked* vertexBuffer = vaoManager->createVertexBuffer(
39  vertexElements, 4, Ogre::BT_IMMUTABLE, &vertexData, false);
40 
41  Ogre::VertexBufferPackedVec vertexBuffers;
42  vertexBuffers.push_back(vertexBuffer);
43 
44  // 1 to 1 index buffer mapping
45  Ogre::uint16 indices[] = {3, 0, 1, 1, 2, 3};
46 
47  // TODO: check if this is needed (when a 1 to 1 vertex and index mapping is
48  // used)
49  Ogre::IndexBufferPacked* indexBuffer = vaoManager->createIndexBuffer(
50  Ogre::IndexBufferPacked::IT_16BIT, 6, Ogre::BT_IMMUTABLE, &indices, false);
51 
52  Ogre::VertexArrayObject* vao = vaoManager->createVertexArrayObject(
53  vertexBuffers, indexBuffer, Ogre::OT_TRIANGLE_LIST);
54 
55  subMesh->mVao[Ogre::VpNormal].push_back(vao);
56 
57  // This might be needed because we use a v2 mesh
58  // Use the same geometry for shadow casting.
59  // Because the material disables shadows this isn't needed
60  // m_impl->m_microbeBackgroundSubMesh->mVao[Ogre::VpShadow].push_back( vao
61  // );
62 
63  // Set the bounds to get frustum culling and LOD to work correctly.
64  // To infinite to always render
65  mesh->_setBounds(Ogre::Aabb::BOX_INFINITE /*, false*/);
66 
67  return mesh;
68 }

◆ CreateXZPlane()

DLLEXPORT Ogre::MeshPtr GeometryHelpers::CreateXZPlane ( const std::string &  meshname,
float  width,
float  height 
)
static

Creates a plane with specific size and UV coordinates with 0, 0 on top left.

This plane is flat on the Y axis. The actual width of the mesh will be double of width to make it easier to calculate

Todo:

Merge the shared code with CreateScreenSpaceQuad

This needs to be verified that this generates good geometry (currently crashes when recorded with RenderDoc)

Definition at line 70 of file GeometryHelpers.cpp.

72 {
73  Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(
74  meshname, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
75 
76  Ogre::SubMesh* subMesh = mesh->createSubMesh();
77 
78  Ogre::RenderSystem* renderSystem = Ogre::Root::getSingleton().getRenderSystem();
79  Ogre::VaoManager* vaoManager = renderSystem->getVaoManager();
80 
81  Ogre::VertexElement2Vec vertexElements;
82  vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3, Ogre::VES_POSITION));
83  vertexElements.push_back(
84  Ogre::VertexElement2(Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES));
85 
86  // This is a fullscreen quad in screenspace (so no transform matrix is used)
87  float vertexData[] = {// First vertex
88  -width, 0, -height, 0, 0,
89  // Second
90  width, 0, -height, 1, 0,
91  // Third
92  width, 0, height, 1, 1,
93  // Fourth
94  -width, 0, height, 0, 1};
95 
96  Ogre::VertexBufferPacked* vertexBuffer = vaoManager->createVertexBuffer(
97  vertexElements, 4, Ogre::BT_IMMUTABLE, &vertexData, false);
98 
99  Ogre::VertexBufferPackedVec vertexBuffers;
100  vertexBuffers.push_back(vertexBuffer);
101 
102  // 1 to 1 index buffer mapping
103  Ogre::uint16 indices[] = {3, 0, 1, 1, 2, 3};
104 
105  // TODO: check if this is needed (when a 1 to 1 vertex and index mapping is
106  // used)
107  Ogre::IndexBufferPacked* indexBuffer = vaoManager->createIndexBuffer(
108  Ogre::IndexBufferPacked::IT_16BIT, 6, Ogre::BT_IMMUTABLE, &indices, false);
109 
110  Ogre::VertexArrayObject* vao = vaoManager->createVertexArrayObject(
111  vertexBuffers, indexBuffer, Ogre::OT_TRIANGLE_LIST);
112 
113  subMesh->mVao[Ogre::VpNormal].push_back(vao);
114 
115  // This might be needed because we use a v2 mesh
116  // Use the same geometry for shadow casting.
117  // Because the material disables shadows this isn't needed
118  // m_impl->m_microbeBackgroundSubMesh->mVao[Ogre::VpShadow].push_back( vao
119  // );
120 
121  // Set the bounds to get frustum culling and LOD to work correctly.
122  mesh->_setBounds(
123  Ogre::Aabb(Ogre::Vector3(0, 0, 0), Ogre::Vector3(width, 0.1f, height)) /*, false*/);
124  return mesh;
125 }

The documentation for this class was generated from the following files: