Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Mesh.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #include "math/Vec3.h"
  12. /*!
  13. * \brief OpenGL Mesh
  14. */
  15. class Mesh {
  16. public:
  17. struct rectangle_t {
  18. Vec3 a, b, c, d;
  19. uint16_t texture;
  20. float red, green, blue;
  21. rectangle_t(Vec3 _a, Vec3 _b, Vec3 _c, Vec3 _d, uint16_t t,
  22. float re = 0.0f, float gr = 0.0f, float bl = 0.0f)
  23. : a(_a), b(_b), c(_c), d(_d), texture(t), red(re), green(gr), blue(bl) { }
  24. };
  25. Mesh();
  26. ~Mesh();
  27. void drawAlpha();
  28. void drawSolid();
  29. void addTexturedRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d, uint16_t textile);
  30. void addTexturedTriangle(Vec3 a, Vec3 b, Vec3 c, uint16_t textile);
  31. void addColoredRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d, float re, float gr, float bl);
  32. void addColoredTriangle(Vec3 a, Vec3 b, Vec3 c, float re, float gr, float bl);
  33. void addNormal(Vec3 n);
  34. std::vector<rectangle_t> texturedRectangles;
  35. std::vector<rectangle_t> coloredRectangles;
  36. std::vector<rectangle_t> texturedTriangles;
  37. std::vector<rectangle_t> coloredTriangles;
  38. std::vector<Vec3> normals;
  39. // Old API
  40. typedef enum {
  41. MeshModeSolid,
  42. MeshModeWireframe,
  43. MeshModeTexture,
  44. MeshModeMultiTexture
  45. } MeshMode;
  46. typedef enum {
  47. fMesh_UseVertexArray = (1 << 0)
  48. } MeshFlags;
  49. typedef struct {
  50. int texture;
  51. #ifdef MULTITEXTURE
  52. int bumpmap;
  53. #endif
  54. unsigned int cnum_triangles;
  55. unsigned int cnum_alpha_triangles;
  56. unsigned int num_texcoors;
  57. float** texcoors; // 2D
  58. unsigned int num_texcoors2;
  59. float** texcoors2; // 2D
  60. //! Arrays of triangle indices sorted by texture
  61. unsigned int num_triangles;
  62. unsigned int* triangles; //!< ABCABCABC...
  63. //! Arrays of alpha triangle indices sorted by texture
  64. unsigned int num_alpha_triangles;
  65. unsigned int* alpha_triangles; //!< ABCABCABC...
  66. } tris_t;
  67. typedef struct {
  68. int texture;
  69. #ifdef MULTITEXTURE
  70. int bumpmap;
  71. #endif
  72. unsigned int cnum_quads;
  73. unsigned int cnum_alpha_quads;
  74. unsigned int num_texcoors;
  75. float** texcoors; // 2D
  76. unsigned int num_texcoors2;
  77. float** texcoors2; // 2D
  78. //! Arrays of rectangle indices sorted by texture
  79. unsigned int num_quads;
  80. unsigned int* quads; //!< ABCDABCDABCD...
  81. //! Arrays of alpha rectangle indices sorted by texture
  82. unsigned int num_alpha_quads;
  83. unsigned int* alpha_quads; //!< ABCDABCDABCD...
  84. } rect_t;
  85. void drawAlphaOld();
  86. void drawSolidOld();
  87. void allocateColors(unsigned int n);
  88. void allocateNormals(unsigned int n);
  89. void allocateRectangles(unsigned int n);
  90. void allocateTriangles(unsigned int n);
  91. void allocateVertices(unsigned int n);
  92. void bufferColorArray(unsigned int colorCount, float* colors);
  93. void bufferNormalArray(unsigned int normalCount, float* normals);
  94. void bufferTriangles(unsigned int count,
  95. unsigned int* indices, float* texCoords,
  96. int* textures, unsigned int* flags);
  97. void bufferVertexArray(unsigned int vertexCount, float* vertices);
  98. void setColor(unsigned int index, float r, float g, float b, float a);
  99. void setColor(unsigned int index, float rgba[4]);
  100. void setNormal(unsigned int index, float i, float j, float k);
  101. void setVertex(unsigned int index, float x, float y, float z);
  102. #if 0
  103. void sortFacesByTexture();
  104. void addFace(int textureIndex, int textureIndexB, unsigned int flags,
  105. unsigned int vertexIndexCount, float* vertexIndices);
  106. void addTexTiledFace(int textureIndex, int textureIndexB,
  107. unsigned int flags, unsigned int indexCount,
  108. float* vertexIndices, float* texcoords);
  109. void bufferTexcoords(unsigned int texcoordCount, float* texcoords);
  110. void duplicateArraysForTexTiledTexcoords();
  111. #endif
  112. unsigned int mFlags;
  113. MeshMode mMode;
  114. unsigned int mNumVertices;
  115. float** mVertices; //!< XYZ
  116. unsigned int mNumNormals;
  117. float** mNormals; //!< IJK
  118. unsigned int mNumColors;
  119. float** mColors; //!< RGBA
  120. unsigned int mNumTris;
  121. tris_t* mTris;
  122. unsigned int mNumQuads;
  123. rect_t* mQuads;
  124. unsigned int mTriangleCount;
  125. int* mTriangleTextures;
  126. unsigned int* mTriangleIndices;
  127. unsigned int* mTriangleFlags;
  128. float* mTriangleTexCoordArray;
  129. float* mVertexArray;
  130. float* mNormalArray;
  131. float* mColorArray;
  132. };
  133. #endif