Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* In the samples DynamicGeometryGameState.cpp, vertex elements are
- defined as follows.
- */
- struct CubeVertices
- {
- float px, py, pz; //Position
- float nx, ny, nz; //Normals
- CubeVertices() {}
- CubeVertices(float _px, float _py, float _pz,
- float _nx, float _ny, float _nz ) :
- px( _px ), py( _py ), pz( _pz ),
- nx( _nx ), ny( _ny ), nz( _nz ) { }
- };
- const CubeVertices c_originalVertices[8] =
- {
- CubeVertices( -1, -1, 1, -0.57737, -0.57737, 0.57737 ),
- CubeVertices( 1, -1, 1, 0.57737, -0.57737, 0.57737 ),
- CubeVertices( 1, 1, 1, 0.57737, 0.57737, 0.57737 ),
- CubeVertices( -1, 1, 1, -0.57737, 0.57737, 0.57737 ),
- CubeVertices( -1, -1, -1, -0.57737, -0.57737, -0.57737 ),
- CubeVertices( 1, -1, -1, 0.57737, -0.57737, -0.57737 ),
- CubeVertices( 1, 1, -1, 0.57737, 0.57737, -0.57737 ),
- CubeVertices( -1, 1, -1, -0.57737, 0.57737, -0.57737 )
- };
- /* Then the example in the createStaticMesh function is ... */
- // Create the mesh ...
- // create a submesh ...
- // vertex declaration ...
- CubeVertices *cubeVertices =
- reinterpret_cast<CubeVertices*>(OGRE_MALLOC_SIMD(
- sizeof(CubeVertices) * 8, Ogre::MEMCATEGORY_GEOMETRY));
- // fill the data.
- memcpy(cubeVertices, c_originalVertices, sizeof(CubeVertices) * 8 );
- Ogre::VertexBufferPacked *vertexBuffer = nullptr;
- try {
- // Create the actual vertex buffer.
- vertexBuffer = vaoManager->createVertexBuffer(vertexElements,
- 8, Ogre::BT_IMMUTABLE, cubeVertices, true);
- } // ...
- /*
- I think my question is, after the memcpy, how does createVertexBuffer use the CubeVertices members px, py, pz, nx, ny, and nz?
- I ask because I'm using something similar to this because it was said that it doesn't matter whether you give a class or a struct ... but I don't understand how it accesses the member fields for the coord and normals data.
- */
- class CubeVertices
- {
- private:
- std::vector<float> coords;
- std::vector<float> normals;
- public:
- CubeVertices() {}
- // ...
- };
Advertisement
Add Comment
Please, Sign In to add comment