Vertex.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef VERTEX_H_
  2. #define VERTEX_H_
  3. #include "FileIO.h"
  4. #include "Vector2.h"
  5. #include "Vector3.h"
  6. #include "Vector4.h"
  7. namespace gameplay
  8. {
  9. class Vertex
  10. {
  11. public:
  12. static const unsigned int POSITION_COUNT = 3;
  13. static const unsigned int NORMAL_COUNT = 3;
  14. static const unsigned int TANGENT_COUNT = 3;
  15. static const unsigned int BINORMAL_COUNT = 3;
  16. static const unsigned int TEXCOORD_COUNT = 2;
  17. static const unsigned int DIFFUSE_COUNT = 4;
  18. static const unsigned int BLEND_WEIGHTS_COUNT = 4;
  19. static const unsigned int BLEND_INDICES_COUNT = 4;
  20. /**
  21. * Constructor.
  22. */
  23. Vertex(void);
  24. /**
  25. * Destructor.
  26. */
  27. ~Vertex(void);
  28. Vector3 position;
  29. Vector3 normal;
  30. Vector3 tangent;
  31. Vector3 binormal;
  32. Vector2 texCoord;
  33. Vector4 diffuse;
  34. Vector4 blendWeights;
  35. Vector4 blendIndices;
  36. bool hasNormal, hasTangent, hasBinormal, hasTexCoord, hasDiffuse, hasWeights;
  37. inline bool operator<(const Vertex& v) const
  38. {
  39. if (position == v.position)
  40. {
  41. if (normal == v.normal)
  42. {
  43. if (tangent == v.tangent)
  44. {
  45. if (binormal == v.binormal)
  46. {
  47. if (texCoord == v.texCoord)
  48. {
  49. if (diffuse == v.diffuse)
  50. {
  51. if (blendWeights == v.blendWeights)
  52. {
  53. if (blendIndices == v.blendIndices)
  54. {
  55. return false;
  56. }
  57. return blendIndices < v.blendIndices;
  58. }
  59. return blendWeights < v.blendWeights;
  60. }
  61. return diffuse < v.diffuse;
  62. }
  63. return texCoord < v.texCoord;
  64. }
  65. return binormal < v.binormal;
  66. }
  67. return tangent < v.tangent;
  68. }
  69. return normal < v.normal;
  70. }
  71. return position < v.position;
  72. }
  73. inline bool operator==(const Vertex& v) const
  74. {
  75. return position==v.position && normal==v.normal && tangent==v.tangent && binormal==v.binormal && texCoord==v.texCoord &&
  76. diffuse==v.diffuse && blendWeights==v.blendWeights && blendIndices==v.blendIndices;
  77. }
  78. /**
  79. * Returns the size of this vertex in bytes.
  80. */
  81. unsigned int byteSize() const;
  82. /**
  83. * Writes this vertex to the binary file stream.
  84. */
  85. void writeBinary(FILE* file) const;
  86. /**
  87. * Writes this vertex to a text file stream.
  88. */
  89. void writeText(FILE* file) const;
  90. /**
  91. * Normalizes the blend weights of this vertex so that they add up to 1.0.
  92. */
  93. void normalizeBlendWeight();
  94. };
  95. }
  96. #endif