Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RoomData.cpp 2.8KB

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