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.

ViewVolume.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*!
  2. * \file include/ViewVolume.h
  3. * \brief Viewing Volume for culling use
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _VIEWVOLUME_H_
  8. #define _VIEWVOLUME_H_
  9. #include "math/Matrix.h"
  10. #include "RoomData.h"
  11. /*!
  12. * \brief Viewing Volume for culling use
  13. */
  14. class ViewVolume {
  15. public:
  16. /*!
  17. * \brief Sides of the view volume
  18. */
  19. enum ViewVolumeSide {
  20. rightSide = 0, //!< Right
  21. leftSide = 1, //!< Left
  22. bottomSide = 2, //!< Bottom
  23. topSide = 3, //!< Top
  24. farSide = 4, //!< Back
  25. nearSide = 5 //!< Front
  26. };
  27. /*!
  28. * \brief Planes of the view volume
  29. */
  30. enum ViewVolumePlane {
  31. planeA = 0, //!< X value of normal
  32. planeB = 1, //!< Y value of normal
  33. planeC = 2, //!< Z value of normal
  34. planeD = 3 //!< Distance to origin
  35. };
  36. /*!
  37. * \brief Constructs an object of ViewVolume
  38. */
  39. ViewVolume();
  40. /*!
  41. * \brief Check if point is in view volume
  42. * \param x X coordinate of point
  43. * \param y Y coordinate of point
  44. * \param z Z coordinate of point
  45. * \returns true if point in view volume
  46. */
  47. bool isPointInFrustum(vec_t x, vec_t y, vec_t z);
  48. /*!
  49. * \brief Check if bounding sphere is in view volume
  50. * \param x X coordinate of a valid abstract sphere
  51. * \param y Y coordinate of a valid abstract sphere
  52. * \param z Z coordinate of a valid abstract sphere
  53. * \param radius radius of a valid abstract sphere
  54. * \returns true if abstract sphere in view volume
  55. */
  56. bool isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius);
  57. /*!
  58. * \brief Check if bounding box is in view volume
  59. * \param min minimum point of valid abstract bounding box
  60. * \param max maximum point of valid abstract bounding box
  61. * \returns true if abstract bounding box in view volume
  62. */
  63. bool isBboxInFrustum(vec3_t min, vec3_t max);
  64. /*!
  65. * \brief Distance to Bounding sphere
  66. * \param x X coordinate of a valid abstract sphere
  67. * \param y Y coordinate of a valid abstract sphere
  68. * \param z Z coordinate of a valid abstract sphere
  69. * \param radius radius of a valid abstract sphere
  70. * \returns distance to abstract sphere bounding volume
  71. */
  72. vec_t getDistToSphereFromNear(vec_t x, vec_t y, vec_t z, vec_t radius);
  73. /*!
  74. * \brief Distance to Bounding box
  75. * \param min minimum point of a valid abstract bounding box
  76. * \param max maximum point of a valid abstract bounding box
  77. * \returns distance to abstract box bounding volume
  78. */
  79. vec_t getDistToBboxFromNear(const vec3_t min, const vec3_t max);
  80. /*!
  81. * \brief Get a copy of the view volume
  82. * \param frustum where frustum will be stored
  83. */
  84. void getFrustum(vec_t frustum[6][4]);
  85. /*!
  86. * \brief Get a copy of a given plane in view volume
  87. * \param p side
  88. * \param plane wher plane will be stored
  89. */
  90. void getPlane(ViewVolumeSide p, vec4_t plane);
  91. /*!
  92. * \brief Updates view volume for this frame.
  93. * \param proj new projection matrix
  94. * \param mdl new model matrix
  95. */
  96. void updateFrame(matrix_t proj, matrix_t mdl);
  97. /*!
  98. * \brief Updates view volume for this frame.
  99. *
  100. * Model & Projection Matrices must be set.
  101. */
  102. void updateFrame();
  103. /*!
  104. * \brief Set this class' model matrix
  105. * \param mdl new model matrix
  106. */
  107. void setModel(matrix_t mdl);
  108. /*!
  109. * \brief Set this class' projection matrix
  110. * \param proj new projection matrix
  111. */
  112. void setProjection(matrix_t proj);
  113. private:
  114. /*!
  115. * \brief Computes clipping matrix.
  116. *
  117. * Model & Projection matrices must be set!
  118. */
  119. void updateClip();
  120. /*!
  121. * \brief Computes planes of frustum.
  122. *
  123. * Model, Projection & Clip matrices must be set!
  124. */
  125. void updateFrustum();
  126. Matrix mProjection; //!< Projection matrix
  127. Matrix mModel; //!< Model matrix
  128. Matrix mClip; //!< Clipping matrix
  129. vec_t mFrustum[6][4]; //!< View volume
  130. };
  131. #endif