Open Source Tomb Raider Engine
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RoomData.cpp 6.0KB

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