Leviathan  0.8.0.0
Leviathan game engine
Leviathan::GeometryHelpers Class Reference

Helpers for generating procedural geometry. More...

#include <GeometryHelpers.h>

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...
 

Detailed Description

Helpers for generating procedural geometry.

Definition at line 11 of file GeometryHelpers.h.

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 }

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