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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*!
  2. * \file src/RoomData.cpp
  3. * \brief World Room Mesh
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "World.h"
  9. #include "system/Shader.h"
  10. #include "RoomData.h"
  11. #include <glm/gtc/matrix_transform.hpp>
  12. void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) {
  13. std::vector<glm::vec3> verts;
  14. std::vector<glm::vec3> cols;
  15. std::vector<unsigned short> inds;
  16. for (int i = 0; i < 8; i++) {
  17. verts.push_back(corner[i]);
  18. cols.push_back(colorLine);
  19. }
  20. inds.push_back(0);
  21. inds.push_back(2);
  22. inds.push_back(4);
  23. inds.push_back(1);
  24. inds.push_back(6);
  25. inds.push_back(7);
  26. inds.push_back(5);
  27. inds.push_back(3);
  28. inds.push_back(0);
  29. inds.push_back(1);
  30. inds.push_back(4);
  31. inds.push_back(7);
  32. inds.push_back(6);
  33. inds.push_back(3);
  34. inds.push_back(5);
  35. inds.push_back(2);
  36. static ShaderBuffer vert, col, ind;
  37. vert.bufferData(verts);
  38. col.bufferData(cols);
  39. ind.bufferData(inds);
  40. Shader::drawGL(vert, col, ind, VP, GL_LINE_STRIP);
  41. cols.clear();
  42. inds.clear();
  43. for (int i = 0; i < 8; i++) {
  44. cols.push_back(colorDot);
  45. inds.push_back(i);
  46. }
  47. static ShaderBuffer vert2, col2, ind2;
  48. vert2.bufferData(verts);
  49. col2.bufferData(cols);
  50. ind2.bufferData(inds);
  51. Shader::drawGL(vert2, col2, ind2, VP, GL_POINTS);
  52. }
  53. // ----------------------------------------------------------------------------
  54. StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
  55. glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
  56. glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
  57. model = translate * rotate;
  58. }
  59. void StaticModel::display(glm::mat4 VP) {
  60. if (cache < 0) {
  61. for (int i = 0; i < getWorld().sizeStaticMesh(); i++) {
  62. if (getWorld().getStaticMesh(i).getID() == id) {
  63. cache = i;
  64. }
  65. }
  66. assert(cache >= 0);
  67. }
  68. getWorld().getStaticMesh(cache).display(VP * model);
  69. }
  70. // ----------------------------------------------------------------------------
  71. void Light::getPos(float p[4]) {
  72. p[0] = pos[0];
  73. p[1] = pos[1];
  74. p[2] = pos[2];
  75. p[3] = pos[3];
  76. }
  77. void Light::getDir(float d[3]) {
  78. d[0] = dir[0];
  79. d[1] = dir[1];
  80. d[2] = dir[2];
  81. }
  82. float Light::getAtt() {
  83. return att;
  84. }
  85. void Light::getColor(float c[4]) {
  86. c[0] = color[0];
  87. c[1] = color[1];
  88. c[2] = color[2];
  89. c[3] = color[3];
  90. }
  91. float Light::getCutoff() {
  92. return cutoff;
  93. }
  94. Light::LightType Light::getType() {
  95. return type;
  96. }
  97. // ----------------------------------------------------------------------------
  98. float Sector::getFloor() {
  99. return floor;
  100. }
  101. float Sector::getCeiling() {
  102. return ceiling;
  103. }
  104. bool Sector::isWall() {
  105. return wall;
  106. }