Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BoundingSphere.cpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*!
  2. * \file src/BoundingSphere.cpp
  3. * \brief 3D Axis Aligned Bounding Sphere
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Camera.h"
  9. #include "World.h"
  10. #include "system/Shader.h"
  11. #include "BoundingSphere.h"
  12. #include <glbinding/gl/gl.h>
  13. std::vector<glm::vec4> BoundingSphere::vertices;
  14. std::vector<glm::vec3> BoundingSphere::colors;
  15. void BoundingSphere::display(glm::mat4 VP, glm::vec3 color) {
  16. for (int w = 0; w < resolution; w++) {
  17. for (int h = (-resolution / 2); h < (resolution / 2); h++) {
  18. float inc1 = (w / float(resolution)) * 2.0f * glm::pi<float>();
  19. float inc2 = ((w + 1) / float(resolution)) * 2.0f * glm::pi<float>();
  20. float inc3 = (h / float(resolution)) * glm::pi<float>();
  21. float inc4 = ((h + 1) / float(resolution)) * glm::pi<float>();
  22. float x1 = glm::sin(inc1);
  23. float y1 = glm::cos(inc1);
  24. float x2 = glm::sin(inc2);
  25. float y2 = glm::cos(inc2);
  26. float radius1 = radius * glm::cos(inc3);
  27. float radius2 = radius * glm::cos(inc4);
  28. float z1 = radius * glm::sin(inc3);
  29. float z2 = radius * glm::sin(inc4);
  30. vertices.emplace_back(VP * (glm::vec4(radius1 * x1, z1, radius1 * y1, 1.0f) + glm::vec4(pos,
  31. 0.0f)));
  32. vertices.emplace_back(VP * (glm::vec4(radius1 * x2, z1, radius1 * y2, 1.0f) + glm::vec4(pos,
  33. 0.0f)));
  34. vertices.emplace_back(VP * (glm::vec4(radius2 * x2, z2, radius2 * y2, 1.0f) + glm::vec4(pos,
  35. 0.0f)));
  36. vertices.emplace_back(VP * (glm::vec4(radius1 * x1, z1, radius1 * y1, 1.0f) + glm::vec4(pos,
  37. 0.0f)));
  38. vertices.emplace_back(VP * (glm::vec4(radius2 * x2, z2, radius2 * y2, 1.0f) + glm::vec4(pos,
  39. 0.0f)));
  40. vertices.emplace_back(VP * (glm::vec4(radius2 * x1, z2, radius2 * y1, 1.0f) + glm::vec4(pos,
  41. 0.0f)));
  42. for (int i = 0; i < 6; i++) {
  43. colors.emplace_back(color);
  44. }
  45. }
  46. }
  47. }
  48. void BoundingSphere::display() {
  49. if (vertices.size() > 0) {
  50. Shader::drawGL(vertices, colors, gl::GL_POINTS);
  51. }
  52. vertices.clear();
  53. colors.clear();
  54. }