SRD

verts

SRD
Nov 30th, 2017
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. /* In the samples DynamicGeometryGameState.cpp, vertex elements are
  2. defined as follows.
  3. */
  4.     struct CubeVertices
  5.     {  
  6.         float px, py, pz;   //Position
  7.         float nx, ny, nz;   //Normals
  8.  
  9.         CubeVertices() {}
  10.         CubeVertices(float _px, float _py, float _pz,
  11.         float _nx, float _ny, float _nz ) :
  12.             px( _px ), py( _py ), pz( _pz ),
  13.             nx( _nx ), ny( _ny ), nz( _nz ) { }
  14.     };  
  15.  
  16.     const CubeVertices c_originalVertices[8] =
  17.     {  
  18.         CubeVertices( -1, -1,  1, -0.57737, -0.57737,  0.57737 ),
  19.         CubeVertices(  1, -1,  1,  0.57737, -0.57737,  0.57737 ),
  20.         CubeVertices(  1,  1,  1,  0.57737,  0.57737,  0.57737 ),
  21.         CubeVertices( -1,  1,  1, -0.57737,  0.57737,  0.57737 ),
  22.         CubeVertices( -1, -1, -1, -0.57737, -0.57737, -0.57737 ),
  23.         CubeVertices(  1, -1, -1,  0.57737, -0.57737, -0.57737 ),
  24.         CubeVertices(  1,  1, -1,  0.57737,  0.57737, -0.57737 ),
  25.         CubeVertices( -1,  1, -1, -0.57737,  0.57737, -0.57737 )
  26.     };
  27.  
  28. /* Then the example in the createStaticMesh function is ... */
  29.     // Create the mesh ...
  30.     // create a submesh ...
  31.     // vertex declaration ...
  32.  
  33.     CubeVertices *cubeVertices =
  34.     reinterpret_cast<CubeVertices*>(OGRE_MALLOC_SIMD(
  35.     sizeof(CubeVertices) * 8, Ogre::MEMCATEGORY_GEOMETRY));
  36.  
  37.     // fill the data.
  38.     memcpy(cubeVertices, c_originalVertices, sizeof(CubeVertices) * 8 );    
  39.  
  40.     Ogre::VertexBufferPacked *vertexBuffer = nullptr;
  41.  
  42.     try {
  43.         // Create the actual vertex buffer.
  44.         vertexBuffer = vaoManager->createVertexBuffer(vertexElements,
  45.             8, Ogre::BT_IMMUTABLE, cubeVertices, true);
  46.     } // ...
  47.  
  48. /*
  49. I think my question is, after the memcpy, how does createVertexBuffer use the CubeVertices members px, py, pz, nx, ny, and nz?
  50.  
  51. 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.
  52. */
  53.  
  54.     class CubeVertices
  55.     {  
  56.         private:
  57.             std::vector<float> coords;
  58.             std::vector<float> normals;
  59.  
  60.         public:
  61.             CubeVertices() {}
  62.             // ...
  63.     };
Advertisement
Add Comment
Please, Sign In to add comment