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.

ViewVolume.h 4.8KB

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