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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*!
  2. * \file src/RoomData.cpp
  3. * \brief Auxiliary Room classes
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Camera.h"
  9. #include "World.h"
  10. #include "system/Shader.h"
  11. #include "RoomData.h"
  12. #include "imgui/imgui.h"
  13. #include <glm/gtc/matrix_transform.hpp>
  14. StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
  15. glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
  16. glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
  17. model = translate * rotate;
  18. }
  19. void StaticModel::find() {
  20. if (cache < 0) {
  21. for (int i = 0; i < World::sizeStaticMesh(); i++) {
  22. if (World::getStaticMesh(i).getID() == id) {
  23. cache = i;
  24. }
  25. }
  26. orAssertGreaterThanEqual(cache, 0);
  27. }
  28. }
  29. glm::vec3 StaticModel::getCenter() {
  30. find();
  31. glm::vec3 center = World::getStaticMesh(cache).getBoundingSphere().getPosition();
  32. glm::vec4 tmp = model * glm::vec4(center, 1.0f);
  33. return glm::vec3(tmp) / tmp.w;
  34. }
  35. float StaticModel::getRadius() {
  36. find();
  37. return World::getStaticMesh(cache).getBoundingSphere().getRadius();
  38. }
  39. void StaticModel::displayBoundingSphere(glm::mat4 VP, glm::vec3 color) {
  40. find();
  41. World::getStaticMesh(cache).getBoundingSphere().display(VP * model, color);
  42. }
  43. void StaticModel::display(glm::mat4 VP) {
  44. find();
  45. World::getStaticMesh(cache).display(VP * model);
  46. }
  47. void StaticModel::displayUI() {
  48. ImGui::Text("ID %d; No. %d", id, cache);
  49. }
  50. // ----------------------------------------------------------------------------
  51. glm::vec3 RoomSprite::getCenter() {
  52. glm::vec3 center = World::getSprite(sprite).getBoundingSphere().getPosition();
  53. glm::vec4 tmp = glm::translate(glm::mat4(1.0f), pos) * glm::vec4(center, 1.0f);
  54. return glm::vec3(tmp) / tmp.w;
  55. }
  56. float RoomSprite::getRadius() {
  57. return World::getSprite(sprite).getBoundingSphere().getRadius();
  58. }
  59. void RoomSprite::displayBoundingSphere(glm::mat4 VP, glm::vec3 color) {
  60. World::getSprite(sprite).getBoundingSphere().display(VP * glm::translate(glm::mat4(1.0f), pos),
  61. color);
  62. }
  63. void RoomSprite::display(glm::mat4 VP) {
  64. glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
  65. glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), -Camera::getRotation().x,
  66. glm::vec3(0.0f, 1.0f, 0.0f));
  67. World::getSprite(sprite).display(VP * (translate * rotate));
  68. }
  69. void RoomSprite::displayUI() {
  70. ImGui::Text("Sprite %d", sprite);
  71. }
  72. // ----------------------------------------------------------------------------
  73. bool Portal::showBoundingBox = false;
  74. Portal::Portal(int adj, glm::vec3 n, glm::vec3 v1, glm::vec3 v2, glm::vec3 v3,
  75. glm::vec3 v4) : adjoiningRoom(adj), normal(n), bbox(v1, v3),
  76. bboxNormal(v1 + ((v3 - v1) / 2.0f),
  77. v1 + ((v3 - v1) / 2.0f)
  78. + (normal * 1024.0f)) {
  79. vert[0] = v1; vert[1] = v2;
  80. vert[2] = v3; vert[3] = v4;
  81. }
  82. void Portal::display(glm::mat4 VP) {
  83. if (showBoundingBox) {
  84. bbox.display(VP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
  85. bboxNormal.display(VP, glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f));
  86. }
  87. }
  88. void Portal::displayUI() {
  89. ImGui::Text("To %03d", adjoiningRoom);
  90. }
  91. // ----------------------------------------------------------------------------
  92. float Sector::getFloor() {
  93. return floor;
  94. }
  95. float Sector::getCeiling() {
  96. return ceiling;
  97. }
  98. bool Sector::isWall() {
  99. return wall;
  100. }