Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RoomData.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*!
  2. * \file src/RoomData.cpp
  3. * \brief World Room Mesh
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "SkeletalModel.h"
  9. #include "World.h"
  10. #include "RoomData.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(float box[2][3]) {
  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(float min[3], float max[3]) {
  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(float x, float y, float z) {
  32. return ((y > a[1]) && (y < b[1]) && inBoxPlane(x, z));
  33. }
  34. bool BoundingBox::inBoxPlane(float x, float z) {
  35. return ((x > a[0]) && (x < b[0])
  36. && (z > a[2]) && (z < b[2]));
  37. }
  38. void BoundingBox::display(bool points, const unsigned char c1[4], const unsigned char c2[4]) {
  39. /*
  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. 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. glColor3ubv(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. // ----------------------------------------------------------------------------
  94. void Light::getPos(float p[4]) {
  95. p[0] = pos[0];
  96. p[1] = pos[1];
  97. p[2] = pos[2];
  98. p[3] = pos[3];
  99. }
  100. void Light::getDir(float d[3]) {
  101. d[0] = dir[0];
  102. d[1] = dir[1];
  103. d[2] = dir[2];
  104. }
  105. float Light::getAtt() {
  106. return att;
  107. }
  108. void Light::getColor(float c[4]) {
  109. c[0] = color[0];
  110. c[1] = color[1];
  111. c[2] = color[2];
  112. c[3] = color[3];
  113. }
  114. float Light::getCutoff() {
  115. return cutoff;
  116. }
  117. Light::LightType Light::getType() {
  118. return type;
  119. }
  120. // ----------------------------------------------------------------------------
  121. void StaticModel::display() {
  122. StaticMesh& mesh = getWorld().getStaticMesh(index);
  123. //if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh.getRadius()))
  124. // return;
  125. /*
  126. glPushMatrix();
  127. glTranslated(pos[0], pos[1], pos[2]);
  128. glRotated(yaw, 0, 1, 0);
  129. mesh.display();
  130. glPopMatrix();
  131. */
  132. }
  133. // ----------------------------------------------------------------------------
  134. Portal::Portal(glm::vec3 vert[4], float norm[3], int adj) {
  135. for (unsigned int i = 0; i < 4; i++) {
  136. for (unsigned int j = 0; j < 3; j++) {
  137. vertices[i][j] = vert[i][j];
  138. }
  139. if (i < 3) {
  140. normal[i] = norm[i];
  141. }
  142. }
  143. adjoiningRoom = adj;
  144. }
  145. void Portal::getVertices(float vert[4][3]) {
  146. for (unsigned int i = 0; i < 4; i++) {
  147. for (unsigned int j = 0; j < 3; j++) {
  148. vert[i][j] = vertices[i][j];
  149. }
  150. }
  151. }
  152. int Portal::getAdjoiningRoom() {
  153. return adjoiningRoom;
  154. }
  155. // ----------------------------------------------------------------------------
  156. float Sector::getFloor() {
  157. return floor;
  158. }
  159. float Sector::getCeiling() {
  160. return ceiling;
  161. }
  162. bool Sector::isWall() {
  163. return wall;
  164. }