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

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