Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ViewVolume.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "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 Deconstructs an object of ViewVolume
  65. */
  66. ~ViewVolume();
  67. /*!
  68. * \brief Check if bounding volume is in view volume
  69. * \param bvol bounding volume to check
  70. * \returns true if frustum contains the given bounding volume
  71. */
  72. bool isBoundingVolumeInFrustum(BoundingVolume bvol);
  73. /*!
  74. * \brief Check if bounding sphere is in view volume
  75. * \param bvol bounding sphere to check
  76. * \returns true if frustum contains the given bounding volume
  77. */
  78. bool isBoundingSphereInFrustum(BoundingSphere bvol);
  79. /*!
  80. * \brief Check if bounding box is in view volume
  81. * \param bvol bounding box to check
  82. * \returns true if frustum contains the given bounding volume
  83. */
  84. bool isBoundingBoxInFrustum(BoundingBox bvol);
  85. /*!
  86. * \brief Check if point is in view volume
  87. * \param x X coordinate of point
  88. * \param y Y coordinate of point
  89. * \param z Z coordinate of point
  90. * \returns true if point in view volume
  91. */
  92. bool isPointInFrustum(vec_t x, vec_t y, vec_t z);
  93. /*!
  94. * \brief Check if bounding sphere is in view volume
  95. * \param x X coordinate of a valid abstract sphere
  96. * \param y Y coordinate of a valid abstract sphere
  97. * \param z Z coordinate of a valid abstract sphere
  98. * \param radius radius of a valid abstract sphere
  99. * \returns true if abstract sphere in view volume
  100. */
  101. bool isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius);
  102. /*!
  103. * \brief Check if bounding box is in view volume
  104. * \param min minimum point of valid abstract bounding box
  105. * \param max maximum point of valid abstract bounding box
  106. * \returns true if abstract bounding box in view volume
  107. */
  108. bool isBboxInFrustum(vec3_t min, vec3_t max);
  109. /*!
  110. * \brief Distance to Bounding sphere
  111. * \param x X coordinate of a valid abstract sphere
  112. * \param y Y coordinate of a valid abstract sphere
  113. * \param z Z coordinate of a valid abstract sphere
  114. * \param radius radius of a valid abstract sphere
  115. * \returns distance to abstract sphere bounding volume
  116. */
  117. vec_t getDistToSphereFromNear(vec_t x, vec_t y, vec_t z, vec_t radius);
  118. /*!
  119. * \brief Distance to Bounding box
  120. * \param min minimum point of a valid abstract bounding box
  121. * \param max maximum point of a valid abstract bounding box
  122. * \returns distance to abstract box bounding volume
  123. */
  124. vec_t getDistToBboxFromNear(vec3_t min, vec3_t max);
  125. /*!
  126. * \brief Get a copy of the view volume
  127. * \param frustum where frustum will be stored
  128. */
  129. void getFrustum(vec_t frustum[6][4]);
  130. /*!
  131. * \brief Get a copy of a given plane in view volume
  132. * \param p side
  133. * \param plane wher plane will be stored
  134. */
  135. void getPlane(ViewVolumeSide p, vec4_t plane);
  136. /*!
  137. * \brief Updates view volume for this frame.
  138. * \param proj new projection matrix
  139. * \param mdl new model matrix
  140. */
  141. void updateFrame(matrix_t proj, matrix_t mdl);
  142. /*!
  143. * \brief Updates view volume for this frame.
  144. *
  145. * Model & Projection Matrices must be set.
  146. */
  147. void updateFrame();
  148. /*!
  149. * \brief Set this class' model matrix
  150. * \param mdl new model matrix
  151. */
  152. void setModel(matrix_t mdl);
  153. /*!
  154. * \brief Set this class' projection matrix
  155. * \param proj new projection matrix
  156. */
  157. void setProjection(matrix_t proj);
  158. private:
  159. /*!
  160. * \brief Computes clipping matrix.
  161. *
  162. * Model & Projection matrices must be set!
  163. */
  164. void updateClip();
  165. /*!
  166. * \brief Computes planes of frustum.
  167. *
  168. * Model, Projection & Clip matrices must be set!
  169. */
  170. void updateFrustum();
  171. Matrix mProjection; //!< Projection matrix
  172. Matrix mModel; //!< Model matrix
  173. Matrix mClip; //!< Clipping matrix
  174. vec_t mFrustum[6][4]; //!< View volume
  175. };
  176. #endif