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.

RoomData.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*!
  2. * \file src/RoomData.cpp
  3. * \brief World Room Mesh
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Render.h"
  9. #include "SkeletalModel.h"
  10. #include "World.h"
  11. #include "RoomData.h"
  12. BoundingBox::BoundingBox() {
  13. a[0] = a[1] = a[2] = 0;
  14. b[0] = b[1] = b[2] = 0;
  15. }
  16. void BoundingBox::getBoundingBox(vec3_t box[2]) {
  17. box[0][0] = a[0];
  18. box[1][0] = b[0];
  19. box[0][1] = a[1];
  20. box[1][1] = b[1];
  21. box[0][2] = a[2];
  22. box[1][2] = b[2];
  23. }
  24. void BoundingBox::setBoundingBox(vec3_t min, vec3_t max) {
  25. a[0] = min[0];
  26. b[0] = max[0];
  27. a[1] = min[1];
  28. b[1] = max[1];
  29. a[2] = min[2];
  30. b[2] = max[2];
  31. }
  32. bool BoundingBox::inBox(vec_t x, vec_t y, vec_t z) {
  33. return ((y > a[1]) && (y < b[1]) && inBoxPlane(x, z));
  34. }
  35. bool BoundingBox::inBoxPlane(vec_t x, vec_t z) {
  36. return ((x > a[0]) && (x < b[0])
  37. && (z > a[2]) && (z < b[2]));
  38. }
  39. void BoundingBox::display(bool points, const unsigned char c1[4], const unsigned char c2[4]) {
  40. // Bind before entering now
  41. //glBindTexture(GL_TEXTURE_2D, 1);
  42. glPointSize(4.0);
  43. //glLineWidth(1.25);
  44. //! \fixme Need to make custom color key for this
  45. glColor3ubv(c1);
  46. glBegin(GL_POINTS);
  47. glVertex3f(b[0], b[1], b[2]);
  48. glVertex3f(a[0], a[1], a[2]);
  49. if (points)
  50. {
  51. glVertex3f(b[0], a[1], b[2]);
  52. glVertex3f(a[0], b[1], b[2]);
  53. glVertex3f(b[0], b[1], a[2]);
  54. glVertex3f(a[0], a[1], b[2]);
  55. glVertex3f(a[0], b[1], a[2]);
  56. glVertex3f(b[0], a[1], a[2]);
  57. }
  58. glEnd();
  59. glColor3ubv(c2);
  60. glBegin(GL_LINES);
  61. // max, top quad
  62. glVertex3f(b[0], b[1], b[2]);
  63. glVertex3f(b[0], a[1], b[2]);
  64. glVertex3f(b[0], b[1], b[2]);
  65. glVertex3f(a[0], b[1], b[2]);
  66. glVertex3f(b[0], b[1], b[2]);
  67. glVertex3f(b[0], b[1], a[2]);
  68. // max-min, vertical quads
  69. glVertex3f(a[0], b[1], b[2]);
  70. glVertex3f(a[0], b[1], a[2]);
  71. glVertex3f(b[0], a[1], b[2]);
  72. glVertex3f(b[0], a[1], a[2]);
  73. glVertex3f(b[0], a[1], b[2]);
  74. glVertex3f(a[0], a[1], b[2]);
  75. // min-max, vertical quads
  76. glVertex3f(b[0], b[1], a[2]);
  77. glVertex3f(b[0], a[1], a[2]);
  78. glVertex3f(b[0], b[1], a[2]);
  79. glVertex3f(a[0], b[1], a[2]);
  80. glVertex3f(a[0], b[1], b[2]);
  81. glVertex3f(a[0], a[1], b[2]);
  82. // min, bottom quad
  83. glVertex3f(a[0], a[1], a[2]);
  84. glVertex3f(a[0], b[1], a[2]);
  85. glVertex3f(a[0], a[1], a[2]);
  86. glVertex3f(b[0], a[1], a[2]);
  87. glVertex3f(a[0], a[1], a[2]);
  88. glVertex3f(a[0], a[1], b[2]);
  89. glEnd();
  90. glPointSize(1.0);
  91. //glLineWidth(1.0);
  92. }
  93. // ----------------------------------------------------------------------------
  94. Light::Light(TombRaider &tr, unsigned int room, unsigned int index) {
  95. unsigned int lightFlags, lightType;
  96. tr.getRoomLight(room, index, pos, color,
  97. dir, &att, &cutoff, &lightType, &lightFlags);
  98. switch (lightType) {
  99. case tombraiderLight_typeDirectional:
  100. type = Light::typeDirectional;
  101. break;
  102. case tombraiderLight_typeSpot:
  103. type = Light::typeSpot;
  104. break;
  105. case tombraiderLight_typePoint:
  106. default:
  107. type = Light::typePoint;
  108. }
  109. //! \todo Light flags?
  110. }
  111. void Light::getPos(vec4_t p) {
  112. p[0] = pos[0];
  113. p[1] = pos[1];
  114. p[2] = pos[2];
  115. p[3] = pos[3];
  116. }
  117. void Light::getDir(vec3_t d) {
  118. d[0] = dir[0];
  119. d[1] = dir[1];
  120. d[2] = dir[2];
  121. }
  122. vec_t Light::getAtt() {
  123. return att;
  124. }
  125. void Light::getColor(vec4_t c) {
  126. c[0] = color[0];
  127. c[1] = color[1];
  128. c[2] = color[2];
  129. c[3] = color[3];
  130. }
  131. vec_t Light::getCutoff() {
  132. return cutoff;
  133. }
  134. Light::LightType Light::getType() {
  135. return type;
  136. }
  137. // ----------------------------------------------------------------------------
  138. StaticModel::StaticModel(TombRaider &tr, unsigned int room, unsigned int i) {
  139. tr.getRoomModel(room, i, &index, pos, &yaw);
  140. }
  141. void StaticModel::display() {
  142. StaticMesh &mesh = getWorld().getStaticMesh(index);
  143. if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh.getRadius()))
  144. return;
  145. glPushMatrix();
  146. glTranslated(pos[0], pos[1], pos[2]);
  147. glRotated(yaw, 0, 1, 0);
  148. mesh.display();
  149. glPopMatrix();
  150. }
  151. bool StaticModel::operator<(const StaticModel &other) {
  152. vec_t distA, distB;
  153. distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0],
  154. pos[1], pos[2], 128.0f);
  155. distB = getRender().mViewVolume.getDistToSphereFromNear(other.pos[0],
  156. other.pos[1], other.pos[2], 128.0f);
  157. return (distA < distB);
  158. }
  159. // ----------------------------------------------------------------------------
  160. Portal::Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform) {
  161. float portalVertices[12];
  162. tr.getRoomPortal(room, index, &adjoiningRoom, normal, portalVertices);
  163. for (unsigned int j = 0; j < 4; ++j) {
  164. vertices[j][0] = portalVertices[j*3];
  165. vertices[j][1] = portalVertices[j*3+1];
  166. vertices[j][2] = portalVertices[j*3+2];
  167. // Relative coors in vis portals
  168. transform.multiply3v(vertices[j], vertices[j]);
  169. }
  170. }
  171. void Portal::getVertices(vec3_t vert[4]) {
  172. for (unsigned int i = 0; i < 4; i++) {
  173. for (unsigned int j = 0; j < 3; j++) {
  174. vert[i][j] = vertices[i][j];
  175. }
  176. }
  177. }
  178. int Portal::getAdjoiningRoom() {
  179. return adjoiningRoom;
  180. }
  181. // ----------------------------------------------------------------------------
  182. Box::Box(TombRaider &tr, unsigned int room, unsigned int index) {
  183. tr.getRoomBox(room, index, a, b, c, d);
  184. }
  185. // ----------------------------------------------------------------------------
  186. Sector::Sector(TombRaider &tr, unsigned int room, unsigned int index) {
  187. unsigned int sectorFlags;
  188. int floorDataIndex, boxIndex, roomBelow, roomAbove;
  189. tr.getRoomSector(room, index, &sectorFlags,
  190. &ceiling, &floor, &floorDataIndex, &boxIndex,
  191. &roomBelow, &roomAbove);
  192. wall = (sectorFlags & tombraiderSector_wall);
  193. }
  194. vec_t Sector::getFloor() {
  195. return floor;
  196. }
  197. vec_t Sector::getCeiling() {
  198. return ceiling;
  199. }
  200. bool Sector::isWall() {
  201. return wall;
  202. }