Open Source Tomb Raider Engine
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Room.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*!
  2. * \file src/Room.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 <algorithm>
  15. #include "main.h"
  16. #include "Room.h"
  17. StaticModel::StaticModel(int _index, vec_t _yaw, vec3_t _pos) {
  18. index = _index;
  19. yaw = _yaw;
  20. for (unsigned int i = 0; i < 3; i++)
  21. pos[i] = _pos[i];
  22. }
  23. void StaticModel::display() {
  24. model_mesh_t *mesh = getWorld().getMesh(index);
  25. if (!mesh)
  26. return;
  27. if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh->radius))
  28. return;
  29. glPushMatrix();
  30. glTranslated(pos[0], pos[1], pos[2]);
  31. glRotated(yaw, 0, 1, 0);
  32. getRender().drawModelMesh(mesh, Render::roomMesh);
  33. glPopMatrix();
  34. }
  35. bool StaticModel::operator<(const StaticModel &other) {
  36. vec_t distA, distB;
  37. distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0],
  38. pos[1], pos[2], 128.0f);
  39. distB = getRender().mViewVolume.getDistToSphereFromNear(other.pos[0],
  40. other.pos[1], other.pos[2], 128.0f);
  41. return (distA < distB);
  42. }
  43. Portal::Portal(vec3_t _vertices[4], vec3_t _normal, int _adjoiningRoom) {
  44. for (unsigned int i = 0; i < 3; i++) {
  45. vertices[0][i] = _vertices[0][i];
  46. vertices[1][i] = _vertices[1][i];
  47. vertices[2][i] = _vertices[2][i];
  48. vertices[3][i] = _vertices[3][i];
  49. normal[i] = _normal[i];
  50. }
  51. adjoiningRoom = _adjoiningRoom;
  52. }
  53. Box::Box(vec3_t _a, vec3_t _b, vec3_t _c, vec3_t _d) {
  54. for (unsigned int i = 0; i < 3; i++) {
  55. a[i] = _a[i];
  56. b[i] = _b[i];
  57. c[i] = _c[i];
  58. d[i] = _d[i];
  59. }
  60. }
  61. Sector::Sector(vec_t _floor, vec_t _ceiling, bool _wall) {
  62. floor = _floor;
  63. ceiling = _ceiling;
  64. wall = _wall;
  65. }
  66. Room::Room(int _id) {
  67. id = _id;
  68. flags = 0;
  69. numXSectors = 0;
  70. numZSectors = 0;
  71. pos[0] = pos[1] = pos[2] = 0.0f;
  72. bbox[0][0] = bbox[0][1] = bbox[0][2] = 0.0f;
  73. bbox[1][0] = bbox[1][1] = bbox[1][2] = 0.0f;
  74. }
  75. Room::~Room() {
  76. unsigned long i;
  77. for (i = 0; i < sprites.size(); i++)
  78. delete sprites[i];
  79. for (i = 0; i < models.size(); i++)
  80. delete models[i];
  81. for (i = 0; i < portals.size(); i++)
  82. delete portals[i];
  83. for (i = 0; i < boxes.size(); i++)
  84. delete boxes[i];
  85. for (i = 0; i < sectors.size(); i++)
  86. delete sectors[i];
  87. for (i = 0; i < lights.size(); i++) {
  88. delete lights[i];
  89. }
  90. }
  91. void Room::sortModels() {
  92. std::sort(models.begin(), models.end());
  93. }