| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #ifndef CAMERA_H
- #define CAMERA_H
- #include <boost/array.hpp>
- #include <deque>
- #include "Util/Vec.h"
- #include "Collision/Collision.h"
- #include "SceneNode.h"
- #include "Util/Accessors.h"
- #include "VisibilityInfo.h"
- class RenderableNode;
- class SpotLight;
- class PointLight;
- /// Camera SceneNode
- class Camera: public SceneNode, public VisibilityInfo
- {
- public:
- enum CameraType
- {
- CT_PERSPECTIVE,
- CT_ORTHOGRAPHIC,
- CT_NUM
- };
- enum FrustrumPlanes
- {
- FP_LEFT = 0,
- FP_RIGHT,
- FP_NEAR,
- FP_TOP,
- FP_BOTTOM,
- FP_FAR,
- FP_NUM
- };
- Camera(CameraType camType, bool inheritParentTrfFlag,
- SceneNode* parent);
- /// @name Accessors
- /// @{
- GETTER_R(CameraType, type, getType)
- float getZNear() const {return zNear;}
- void setZNear(float znear);
- float getZFar() const {return zFar;}
- void setZFar(float zfar);
- const Mat4& getProjectionMatrix() const {return projectionMat;}
- const Mat4& getViewMatrix() const {return viewMat;}
- /// See the declaration of invProjectionMat for info
- const Mat4& getInvProjectionMatrix() const {return invProjectionMat;}
- const Col::Plane& getWSpaceFrustumPlane(FrustrumPlanes id) const;
- /// @}
- void lookAtPoint(const Vec3& point);
- /// This does:
- /// - Update view matrix
- /// - Update frustum planes
- void moveUpdate();
- /// Do nothing
- void frameUpdate(float /*prevUpdateTime*/, float /*crntTime*/) {}
- /// Do nothing
- void init(const char*) {}
- /// @name Frustum checks
- /// @{
- /// Check if the given camera is inside the frustum clipping planes.
- /// This is used mainly to test if the projected lights are visible
- bool insideFrustum(const Col::CollisionShape& vol) const;
- /// Check if another camera is inside our view (used for projected
- /// lights)
- bool insideFrustum(const Camera& cam) const;
- /// @}
- protected:
- CameraType type;
- float zNear, zFar;
- /// @name The frustum planes in local and world space
- /// @{
- boost::array<Col::Plane, FP_NUM> lspaceFrustumPlanes;
- boost::array<Col::Plane, FP_NUM> wspaceFrustumPlanes;
- /// @}
- /// @name Matrices
- /// @{
- Mat4 projectionMat;
- Mat4 viewMat;
- /// Used in deferred shading for the calculation of view vector (see
- /// CalcViewVector). The reason we store this matrix here is that we
- /// don't want it to be re-calculated all the time but only when the
- /// projection params (fovX, fovY, zNear, zFar) change. Fortunately
- /// the projection params change rarely. Note that the Camera as we all
- /// know re-calculates the matrices only when the parameters change!!
- Mat4 invProjectionMat;
- /// @}
- /// Calculate projectionMat and invProjectionMat
- virtual void calcProjectionMatrix() = 0;
- virtual void calcLSpaceFrustumPlanes() = 0;
- void updateViewMatrix();
- void updateWSpaceFrustumPlanes();
- /// Get the edge points of the camera
- virtual void getExtremePoints(Vec3* pointsArr,
- uint& pointsNum) const = 0;
- };
- inline Camera::Camera(CameraType camType, bool inheritParentTrfFlag,
- SceneNode* parent)
- : SceneNode(SNT_CAMERA, inheritParentTrfFlag, parent),
- type(camType)
- {
- name = "Camera:" + name;
- }
- inline const Col::Plane& Camera::getWSpaceFrustumPlane(FrustrumPlanes id) const
- {
- return wspaceFrustumPlanes[id];
- }
- inline void Camera::setZNear(float znear_)
- {
- zNear = znear_;
- calcProjectionMatrix();
- calcLSpaceFrustumPlanes();
- }
- inline void Camera::setZFar(float zfar_)
- {
- zFar = zfar_;
- calcProjectionMatrix();
- calcLSpaceFrustumPlanes();
- }
- #endif
|