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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /*!
  11. * \brief Defines a 3D sphere.
  12. */
  13. class BoundingSphere {
  14. public:
  15. vec3_t mCenter; //!< Center of bounding sphere
  16. vec_t mRadius; //!< Raduis of bounding sphere
  17. };
  18. /*!
  19. * \brief Defines a 3D rectangle.
  20. */
  21. class BoundingBox {
  22. public:
  23. vec3_t mMin; //!< Bounding box MIN point
  24. vec3_t mMax; //!< Bounding box MAX point
  25. };
  26. /*!
  27. * \brief Defines a 3D sphere and/or rectangle.
  28. */
  29. class BoundingVolume {
  30. public:
  31. BoundingSphere mSphere; //!< Bounding sphere of this volume
  32. BoundingBox mBox; //!< Bounding box of this volume
  33. };
  34. /*!
  35. * \brief Viewing Volume for culling use
  36. */
  37. class ViewVolume {
  38. public:
  39. /*!
  40. * \brief Sides of the view volume
  41. */
  42. enum ViewVolumeSide {
  43. rightSide = 0, //!< Right
  44. leftSide = 1, //!< Left
  45. bottomSide = 2, //!< Bottom
  46. topSide = 3, //!< Top
  47. farSide = 4, //!< Back
  48. nearSide = 5 //!< Front
  49. };
  50. /*!
  51. * \brief Planes of the view volume
  52. */
  53. enum ViewVolumePlane {
  54. planeA = 0, //!< X value of normal
  55. planeB = 1, //!< Y value of normal
  56. planeC = 2, //!< Z value of normal
  57. planeD = 3 //!< Distance to origin
  58. };
  59. /*!
  60. * \brief Constructs an object of ViewVolume
  61. */
  62. ViewVolume();
  63. /*!
  64. * \brief Check if bounding volume is in view volume
  65. * \param bvol bounding volume to check
  66. * \returns true if frustum contains the given bounding volume
  67. */
  68. bool isBoundingVolumeInFrustum(BoundingVolume bvol);
  69. /*!
  70. * \brief Check if bounding sphere is in view volume
  71. * \param bvol bounding sphere to check
  72. * \returns true if frustum contains the given bounding volume
  73. */
  74. bool isBoundingSphereInFrustum(BoundingSphere bvol);
  75. /*!
  76. * \brief Check if bounding box is in view volume
  77. * \param bvol bounding box to check
  78. * \returns true if frustum contains the given bounding volume
  79. */
  80. bool isBoundingBoxInFrustum(BoundingBox bvol);
  81. /*!
  82. * \brief Check if point is in view volume
  83. * \param x X coordinate of point
  84. * \param y Y coordinate of point
  85. * \param z Z coordinate of point
  86. * \returns true if point in view volume
  87. */
  88. bool isPointInFrustum(vec_t x, vec_t y, vec_t z);
  89. /*!
  90. * \brief Check if bounding sphere is in view volume
  91. * \param x X coordinate of a valid abstract sphere
  92. * \param y Y coordinate of a valid abstract sphere
  93. * \param z Z coordinate of a valid abstract sphere
  94. * \param radius radius of a valid abstract sphere
  95. * \returns true if abstract sphere in view volume
  96. */
  97. bool isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius);
  98. /*!
  99. * \brief Check if bounding box is in view volume
  100. * \param min minimum point of valid abstract bounding box
  101. * \param max maximum point of valid abstract bounding box
  102. * \returns true if abstract bounding box in view volume
  103. */
  104. bool isBboxInFrustum(vec3_t min, vec3_t max);
  105. /*!
  106. * \brief Distance to Bounding sphere
  107. * \param x X coordinate of a valid abstract sphere
  108. * \param y Y coordinate of a valid abstract sphere
  109. * \param z Z coordinate of a valid abstract sphere
  110. * \param radius radius of a valid abstract sphere
  111. * \returns distance to abstract sphere bounding volume
  112. */
  113. vec_t getDistToSphereFromNear(vec_t x, vec_t y, vec_t z, vec_t radius);
  114. /*!
  115. * \brief Distance to Bounding box
  116. * \param min minimum point of a valid abstract bounding box
  117. * \param max maximum point of a valid abstract bounding box
  118. * \returns distance to abstract box bounding volume
  119. */
  120. vec_t getDistToBboxFromNear(vec3_t min, vec3_t max);
  121. /*!
  122. * \brief Get a copy of the view volume
  123. * \param frustum where frustum will be stored
  124. */
  125. void getFrustum(vec_t frustum[6][4]);
  126. /*!
  127. * \brief Get a copy of a given plane in view volume
  128. * \param p side
  129. * \param plane wher plane will be stored
  130. */
  131. void getPlane(ViewVolumeSide p, vec4_t plane);
  132. /*!
  133. * \brief Updates view volume for this frame.
  134. * \param proj new projection matrix
  135. * \param mdl new model matrix
  136. */
  137. void updateFrame(matrix_t proj, matrix_t mdl);
  138. /*!
  139. * \brief Updates view volume for this frame.
  140. *
  141. * Model & Projection Matrices must be set.
  142. */
  143. void updateFrame();
  144. /*!
  145. * \brief Set this class' model matrix
  146. * \param mdl new model matrix
  147. */
  148. void setModel(matrix_t mdl);
  149. /*!
  150. * \brief Set this class' projection matrix
  151. * \param proj new projection matrix
  152. */
  153. void setProjection(matrix_t proj);
  154. private:
  155. /*!
  156. * \brief Computes clipping matrix.
  157. *
  158. * Model & Projection matrices must be set!
  159. */
  160. void updateClip();
  161. /*!
  162. * \brief Computes planes of frustum.
  163. *
  164. * Model, Projection & Clip matrices must be set!
  165. */
  166. void updateFrustum();
  167. Matrix mProjection; //!< Projection matrix
  168. Matrix mModel; //!< Model matrix
  169. Matrix mClip; //!< Clipping matrix
  170. vec_t mFrustum[6][4]; //!< View volume
  171. };
  172. #endif