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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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::display(glm::mat4 VP) {
  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. World::getStaticMesh(cache).display(VP * model);
  29. }
  30. void StaticModel::displayUI() {
  31. ImGui::Text("ID %d; No. %d", id, cache);
  32. }
  33. // ----------------------------------------------------------------------------
  34. void RoomSprite::display(glm::mat4 VP) {
  35. glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
  36. //! \fixme Calculate angle between camera and sprite
  37. glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Camera::getRotation().x,
  38. glm::vec3(0.0f, 1.0f, 0.0f));
  39. World::getSprite(sprite).display(VP * (translate * rotate));
  40. }
  41. // ----------------------------------------------------------------------------
  42. bool Portal::showBoundingBox = false;
  43. Portal::Portal(int adj, glm::vec3 n, glm::vec3 v1, glm::vec3 v2, glm::vec3 v3,
  44. glm::vec3 v4) : adjoiningRoom(adj), normal(n), bbox(v1, v3),
  45. bboxNormal(v1 + ((v3 - v1) / 2.0f),
  46. v1 + ((v3 - v1) / 2.0f)
  47. + (normal * 1024.0f)) {
  48. vert[0] = v1; vert[1] = v2;
  49. vert[2] = v3; vert[3] = v4;
  50. }
  51. void Portal::display(glm::mat4 VP) {
  52. if (showBoundingBox) {
  53. bbox.display(VP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
  54. bboxNormal.display(VP, glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f));
  55. }
  56. }
  57. void Portal::displayUI() {
  58. ImGui::Text("To %03d", adjoiningRoom);
  59. }
  60. // ----------------------------------------------------------------------------
  61. float Sector::getFloor() {
  62. return floor;
  63. }
  64. float Sector::getCeiling() {
  65. return ceiling;
  66. }
  67. bool Sector::isWall() {
  68. return wall;
  69. }