Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Mesh.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*!
  2. * \file include/Mesh.h
  3. * \brief OpenGL Mesh
  4. *
  5. * \author Mongoose
  6. *
  7. * \todo Unify the parallel systems here, arrays and the allocate/set
  8. */
  9. #ifndef _MESH_H_
  10. #define _MESH_H_
  11. /*!
  12. * \brief OpenGL Mesh
  13. */
  14. class Mesh {
  15. public:
  16. typedef enum {
  17. MeshModeSolid,
  18. MeshModeWireframe,
  19. MeshModeTexture,
  20. MeshModeMultiTexture
  21. } MeshMode;
  22. typedef enum {
  23. fMesh_UseVertexArray = (1 << 0)
  24. } MeshFlags;
  25. typedef struct {
  26. int texture;
  27. #ifdef MULTITEXTURE
  28. int bumpmap;
  29. #endif
  30. unsigned int cnum_triangles;
  31. unsigned int cnum_alpha_triangles;
  32. unsigned int num_texcoors;
  33. float **texcoors; // 2D
  34. unsigned int num_texcoors2;
  35. float **texcoors2; // 2D
  36. //! Arrays of triangle indices sorted by texture
  37. unsigned int num_triangles;
  38. unsigned int *triangles; //!< ABCABCABC...
  39. //! Arrays of alpha triangle indices sorted by texture
  40. unsigned int num_alpha_triangles;
  41. unsigned int *alpha_triangles; //!< ABCABCABC...
  42. } tris_t;
  43. typedef struct {
  44. int texture;
  45. #ifdef MULTITEXTURE
  46. int bumpmap;
  47. #endif
  48. unsigned int cnum_quads;
  49. unsigned int cnum_alpha_quads;
  50. unsigned int num_texcoors;
  51. float **texcoors; // 2D
  52. unsigned int num_texcoors2;
  53. float **texcoors2; // 2D
  54. //! Arrays of rectangle indices sorted by texture
  55. unsigned int num_quads;
  56. unsigned int *quads; //!< ABCDABCDABCD...
  57. //! Arrays of alpha rectangle indices sorted by texture
  58. unsigned int num_alpha_quads;
  59. unsigned int *alpha_quads; //!< ABCDABCDABCD...
  60. } rect_t;
  61. /*!
  62. * \brief Constructs an object of Mesh
  63. */
  64. Mesh();
  65. /*!
  66. * \brief Deconstructs an object of Mesh
  67. */
  68. ~Mesh();
  69. void drawAlpha();
  70. void drawSolid();
  71. void allocateColors(unsigned int n);
  72. void allocateNormals(unsigned int n);
  73. void allocateRectangles(unsigned int n);
  74. void allocateTriangles(unsigned int n);
  75. void allocateVertices(unsigned int n);
  76. void bufferColorArray(unsigned int colorCount, float *colors);
  77. void bufferNormalArray(unsigned int normalCount, float *normals);
  78. void bufferTriangles(unsigned int count,
  79. unsigned int *indices, float *texCoords,
  80. int *textures, unsigned int *flags);
  81. void bufferVertexArray(unsigned int vertexCount, float *vertices);
  82. void setColor(unsigned int index, float r, float g, float b, float a);
  83. void setColor(unsigned int index, float rgba[4]);
  84. void setNormal(unsigned int index, float i, float j, float k);
  85. void setVertex(unsigned int index, float x, float y, float z);
  86. #ifdef NOT_IMPLEMENTED
  87. void sortFacesByTexture();
  88. void addFace(int textureIndex, int textureIndexB, unsigned int flags,
  89. unsigned int vertexIndexCount, float *vertexIndices);
  90. void addTexTiledFace(int textureIndex, int textureIndexB,
  91. unsigned int flags, unsigned int indexCount,
  92. float *vertexIndices, float *texcoords);
  93. void bufferTexcoords(unsigned int texcoordCount, float *texcoords);
  94. void duplicateArraysForTexTiledTexcoords();
  95. #endif
  96. unsigned int mFlags;
  97. MeshMode mMode;
  98. unsigned int mNumVertices;
  99. float **mVertices; //!< XYZ
  100. unsigned int mNumNormals;
  101. float **mNormals; //!< IJK
  102. unsigned int mNumColors;
  103. float **mColors; //!< RGBA
  104. unsigned int mNumTris;
  105. tris_t *mTris;
  106. unsigned int mNumQuads;
  107. rect_t *mQuads;
  108. unsigned int mTriangleCount;
  109. int *mTriangleTextures;
  110. unsigned int *mTriangleIndices;
  111. unsigned int *mTriangleFlags;
  112. float *mTriangleTexCoordArray;
  113. float *mVertexArray;
  114. float *mNormalArray;
  115. float *mColorArray;
  116. };
  117. #endif