Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RoomData.cpp 6.1KB

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