#ifndef __CAMERA_H #define __CAMERA_H #include "Vector3.h" #include "AxisAlignedBox3.h" #include "Plane3.h" namespace CHCDemoEngine { class Matrix4x4; class Polyhedron; /** Class representing a frustum. */ class Frustum { friend class Camera; public: Frustum() {}; Frustum(const Matrix4x4 &trafo); enum { LEFT_PLANE, RIGHT_PLANE, BOTTOM_PLANE, TOP_PLANE, NEAR_PLANE, FAR_PLANE}; /** Resizes the current frustum so that it fully encloses the given polyhedron */ void EnclosePolyhedron(const Polyhedron &polyhedron); void ExtractTransformation(Matrix4x4 &m) const; /// the 6 clip planes Plane3 mClipPlanes[6]; }; class Camera { friend class ShadowMap; public: Camera(); Camera(int width, int height, float fieldOfView = 90.f); /** Sets the current camera position. */ void SetPosition(const Vector3 &pos); inline Vector3 GetPosition() const { return mPosition; } Vector3 GetDirection() const; Vector3 GetUpVector() const; Vector3 GetRightVector() const; Vector3 GetBaseDirection() const; Vector3 GetBaseUpVector() const; Vector3 GetBaseRightVector() const; inline float GetFov() const { return mFovy; } inline float GetAspect() const { return (float) mWidth / mHeight; } inline int GetWidth() const { return mWidth; } inline int GetHeight() const { return mHeight; } /** Sets up viewing in gl */ void SetupCameraView(); /** Returns the current projection matrix. */ void GetProjectionMatrix(Matrix4x4 &mat) const; /** Returns the current model view matrix. */ void GetModelViewMatrix(Matrix4x4 &mat) const; void GetViewOrientationMatrix(Matrix4x4 &mat) const; /** Calculates a frustum from the projection and the modelview matrix. */ void CalcFrustum(Frustum &frustum); /** Computes the extremal points of this frustum. If farthestVisibleDistance is nearer than the far plane, it is used to define the far plane instead. */ void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, float farthestVisibleDistance = 1e25f) const; /** Returns the near plane. */ inline float GetNear() const { return mNear; } /** Returns the far plane. */ inline float GetFar() const { return mFar; } /** Sets the near plane */ void SetNear(float nearDist); /** Sets the far plane. */ void SetFar(float farDist); void SetOrtho(bool ortho); void Yaw(float angle); void Pitch(float angle); float GetPitch() const { return mPitch; } float GetYaw() const { return mYaw; } void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; } /** Sets the camera direction. */ void SetDirection(const Vector3 &direction); /** Returns frustum as polyhedron. */ Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; protected: void Precompute(const Vector3 &direction); void CalculateFromPitchAndYaw(); void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, const Vector3 &view, const Vector3 &right, const Vector3 &up, const Vector3 &pos, float farthestVisibleDistance = 1e25f) const; //////////////// //-- members float mFovy; int mWidth; int mHeight; float mNear; float mFar; bool mIsOrtho; Matrix4x4 mBaseOrientation; Matrix4x4 mViewOrientation; float mPitch; float mYaw; Vector3 mPosition; }; } #endif