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

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