123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- /*!
- * \file include/ViewVolume.h
- * \brief Viewing Volume for culling use
- *
- * \author Mongoose
- */
-
- #ifndef _VIEWVOLUME_H_
- #define _VIEWVOLUME_H_
-
- #include "Matrix.h"
-
- /*!
- * \brief Defines a 3D sphere.
- */
- class BoundingSphere {
- public:
- vec3_t mCenter; //!< Center of bounding sphere
- vec_t mRadius; //!< Raduis of bounding sphere
- };
-
- /*!
- * \brief Defines a 3D rectangle.
- */
- class BoundingBox {
- public:
- vec3_t mMin; //!< Bounding box MIN point
- vec3_t mMax; //!< Bounding box MAX point
- };
-
- /*!
- * \brief Defines a 3D sphere and/or rectangle.
- */
- class BoundingVolume {
- public:
- BoundingSphere mSphere; //!< Bounding sphere of this volume
- BoundingBox mBox; //!< Bounding box of this volume
- };
-
- /*!
- * \brief Viewing Volume for culling use
- */
- class ViewVolume {
- public:
-
- /*!
- * \brief Sides of the view volume
- */
- enum ViewVolumeSide {
- rightSide = 0, //!< Right
- leftSide = 1, //!< Left
- bottomSide = 2, //!< Bottom
- topSide = 3, //!< Top
- farSide = 4, //!< Back
- nearSide = 5 //!< Front
- };
-
- /*!
- * \brief Planes of the view volume
- */
- enum ViewVolumePlane {
- planeA = 0, //!< X value of normal
- planeB = 1, //!< Y value of normal
- planeC = 2, //!< Z value of normal
- planeD = 3 //!< Distance to origin
- };
-
- /*!
- * \brief Constructs an object of ViewVolume
- */
- ViewVolume();
-
- /*!
- * \brief Deconstructs an object of ViewVolume
- */
- ~ViewVolume();
-
- /*!
- * \brief Check if bounding volume is in view volume
- * \param bvol bounding volume to check
- * \returns true if frustum contains the given bounding volume
- */
- bool isBoundingVolumeInFrustum(BoundingVolume bvol);
-
- /*!
- * \brief Check if bounding sphere is in view volume
- * \param bvol bounding sphere to check
- * \returns true if frustum contains the given bounding volume
- */
- bool isBoundingSphereInFrustum(BoundingSphere bvol);
-
- /*!
- * \brief Check if bounding box is in view volume
- * \param bvol bounding box to check
- * \returns true if frustum contains the given bounding volume
- */
- bool isBoundingBoxInFrustum(BoundingBox bvol);
-
- /*!
- * \brief Check if point is in view volume
- * \param x X coordinate of point
- * \param y Y coordinate of point
- * \param z Z coordinate of point
- * \returns true if point in view volume
- */
- bool isPointInFrustum(vec_t x, vec_t y, vec_t z);
-
- /*!
- * \brief Check if bounding sphere is in view volume
- * \param x X coordinate of a valid abstract sphere
- * \param y Y coordinate of a valid abstract sphere
- * \param z Z coordinate of a valid abstract sphere
- * \param radius radius of a valid abstract sphere
- * \returns true if abstract sphere in view volume
- */
- bool isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius);
-
- /*!
- * \brief Check if bounding box is in view volume
- * \param min minimum point of valid abstract bounding box
- * \param max maximum point of valid abstract bounding box
- * \returns true if abstract bounding box in view volume
- */
- bool isBboxInFrustum(vec3_t min, vec3_t max);
-
- /*!
- * \brief Distance to Bounding sphere
- * \param x X coordinate of a valid abstract sphere
- * \param y Y coordinate of a valid abstract sphere
- * \param z Z coordinate of a valid abstract sphere
- * \param radius radius of a valid abstract sphere
- * \returns distance to abstract sphere bounding volume
- */
- vec_t getDistToSphereFromNear(vec_t x, vec_t y, vec_t z, vec_t radius);
-
- /*!
- * \brief Distance to Bounding box
- * \param min minimum point of a valid abstract bounding box
- * \param max maximum point of a valid abstract bounding box
- * \returns distance to abstract box bounding volume
- */
- vec_t getDistToBboxFromNear(vec3_t min, vec3_t max);
-
- /*!
- * \brief Get a copy of the view volume
- * \param frustum where frustum will be stored
- */
- void getFrustum(vec_t frustum[6][4]);
-
- /*!
- * \brief Get a copy of a given plane in view volume
- * \param p side
- * \param plane wher plane will be stored
- */
- void getPlane(ViewVolumeSide p, vec4_t plane);
-
- /*!
- * \brief Updates view volume for this frame.
- * \param proj new projection matrix
- * \param mdl new model matrix
- */
- void updateFrame(matrix_t proj, matrix_t mdl);
-
- /*!
- * \brief Updates view volume for this frame.
- *
- * Model & Projection Matrices must be set.
- */
- void updateFrame();
-
- /*!
- * \brief Set this class' model matrix
- * \param mdl new model matrix
- */
- void setModel(matrix_t mdl);
-
- /*!
- * \brief Set this class' projection matrix
- * \param proj new projection matrix
- */
- void setProjection(matrix_t proj);
-
- private:
-
- /*!
- * \brief Computes clipping matrix.
- *
- * Model & Projection matrices must be set!
- */
- void updateClip();
-
- /*!
- * \brief Computes planes of frustum.
- *
- * Model, Projection & Clip matrices must be set!
- */
- void updateFrustum();
-
- Matrix mProjection; //!< Projection matrix
- Matrix mModel; //!< Model matrix
- Matrix mClip; //!< Clipping matrix
- vec_t mFrustum[6][4]; //!< View volume
- };
-
- #endif
|