Triangle.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LightMap *
  23. * *
  24. * $Archive:: /Commando/Code/Tool $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 8/10/00 4:10p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef _TRIANGLE_H
  36. #define _TRIANGLE_H
  37. // Includes.
  38. #include "vector3.h"
  39. #include "vector2.h"
  40. class TextureNameNode;
  41. class Triangle
  42. {
  43. public:
  44. enum VerticesCountEnum {
  45. VERTICES_COUNT = 3 // No. of vertices in a triangle. Fixed for this class.
  46. };
  47. struct TriangleVertices
  48. {
  49. Vector3 Point;
  50. Vector2 UV;
  51. bool operator == (const TriangleVertices &t) {
  52. return ((Point == t.Point) && (UV == t.UV));
  53. }
  54. };
  55. // Equality operator.
  56. bool operator == (const Triangle &t) {
  57. return ((Normal == t.Normal) &&
  58. (Vertices [0] == t.Vertices [0]) &&
  59. (Vertices [1] == t.Vertices [1]) &&
  60. (Vertices [2] == t.Vertices [2]));
  61. }
  62. // Inequality operator.
  63. bool operator != (const Triangle &t) {
  64. return (!(*this == t));
  65. }
  66. bool Is_Equivalent (const Triangle &triangle) const;
  67. bool Abuts (const Triangle &triangle) const;
  68. Vector3 Normal; // Face normal.
  69. TriangleVertices Vertices [VERTICES_COUNT]; // Location of triangle in object space and texture space.
  70. TextureNameNode *TextureNameNodePtr; // List of textures associated with this triangle.
  71. unsigned TextureID; // ID to uniquely identify the texture.
  72. };
  73. /***********************************************************************************************
  74. * Triangle::Is_Equivalent -- *
  75. * *
  76. * INPUT: *
  77. * *
  78. * OUTPUT: *
  79. * *
  80. * WARNINGS: *
  81. * *
  82. * HISTORY: *
  83. * 06/13/00 IML : Created. *
  84. *=============================================================================================*/
  85. inline bool Triangle::Is_Equivalent (const Triangle &triangle) const
  86. {
  87. bool foundequivalent;
  88. bool hasequivalent [VERTICES_COUNT];
  89. // Rules for equivalence are:
  90. // (a) Normal vectors must match
  91. // (b) Points must match (but may not necessarily be in the same order).
  92. if (Normal != triangle.Normal) return (false);
  93. hasequivalent [0] = false;
  94. hasequivalent [1] = false;
  95. hasequivalent [2] = false;
  96. for (unsigned a = 0; a < VERTICES_COUNT; a++) {
  97. foundequivalent = false;
  98. for (unsigned b = 0; b < VERTICES_COUNT; b++) {
  99. if (!hasequivalent [b]) {
  100. if (Vertices [a].Point == triangle.Vertices [b].Point) {
  101. hasequivalent [b] = true;
  102. foundequivalent = true;
  103. break;
  104. }
  105. }
  106. }
  107. if (!foundequivalent) return (false);
  108. }
  109. // Triangles are equivalent.
  110. return (true);
  111. }
  112. /***********************************************************************************************
  113. * Triangle::Abuts -- *
  114. * *
  115. * INPUT: *
  116. * *
  117. * OUTPUT: *
  118. * *
  119. * WARNINGS: *
  120. * *
  121. * HISTORY: *
  122. * 08/03/00 IML : Created. *
  123. *=============================================================================================*/
  124. inline bool Triangle::Abuts (const Triangle &triangle) const
  125. {
  126. bool iscoincident [VERTICES_COUNT];
  127. unsigned coincidentcount;
  128. // Rules for abutting are:
  129. // (1) Exactly two points must match.
  130. iscoincident [0] = false;
  131. iscoincident [1] = false;
  132. iscoincident [2] = false;
  133. coincidentcount = 0;
  134. for (unsigned a = 0; a < VERTICES_COUNT; a++) {
  135. for (unsigned b = 0; b < VERTICES_COUNT; b++) {
  136. if (!iscoincident [b]) {
  137. if (Vertices [a].Point == triangle.Vertices [b].Point) {
  138. iscoincident [b] = true;
  139. coincidentcount++;
  140. break;
  141. }
  142. }
  143. }
  144. }
  145. return (coincidentcount == 2);
  146. }
  147. class PackingTriangle : public Triangle
  148. {
  149. public:
  150. // Public data.
  151. Vector2 PackedUVs [Triangle::VERTICES_COUNT];
  152. unsigned PackedTextureID;
  153. };
  154. #endif // _TRIANGLE_H