source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h @ 2932

Revision 2932, 3.4 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[2753]1#ifndef __CAMERA_H
2#define __CAMERA_H
3
4#include "Vector3.h"
5#include "AxisAlignedBox3.h"
[2755]6#include "Plane3.h"
[2753]7
8
[2776]9namespace CHCDemoEngine
[2755]10{
[2753]11
[2911]12class Matrix4x4;
13class Polyhedron;
[2753]14
[2911]15/** Class representing a frustum.
16*/
17class Frustum
[2753]18{
[2911]19        friend class Camera;
20
[2753]21public:
[2911]22
23        Frustum() {};
24
25        Frustum(const Matrix4x4 &trafo);
26
27        enum { RIGHT_PLANE, LEFT_PLANE, BOTTOM_PLANE, TOP_PLANE, FAR_PLANE, NEAR_PLANE};
28        /** Resizes the current frustum so that it fully encloses the given polyhedron
[2755]29        */
[2911]30        void EnclosePolyhedron(const Polyhedron &polyhedron);
[2753]31
[2911]32        void ExtractTransformation(Matrix4x4 &m) const;
33
34
35        /// the 6 clip planes
36        Plane3 mClipPlanes[6];
37};
38
39
40class Camera
41{
[2932]42        friend class ShadowMap;
[2911]43public:
[2755]44       
[2753]45        Camera();
46
47        Camera(int width, int height, float fieldOfView = 90.f);
48
[2932]49        /** Sets the current camera position.
50        */
[2753]51        void SetPosition(const Vector3 &pos);
52
53        inline Vector3 GetPosition() const { return mPosition; }
[2911]54       
[2796]55        Vector3 GetDirection() const;
56        Vector3 GetUpVector() const;
57        Vector3 GetRightVector() const;
[2753]58
[2911]59        Vector3 GetBaseDirection() const;
60        Vector3 GetBaseUpVector() const;
61        Vector3 GetBaseRightVector() const;
62
[2753]63        inline float GetFov() const { return mFovy; }
[2755]64        inline float GetAspect() const { return (float) mWidth / mHeight; }
[2826]65        inline int GetWidth() const { return mWidth; }
66        inline int GetHeight() const { return mHeight; }
[2753]67
[2796]68        /** Sets up viewing in gl
69        */
[2756]70        void SetupCameraView();
[2826]71        /** Returns the current projection matrix.
72        */
[2755]73        void GetProjectionMatrix(Matrix4x4 &mat);
[2826]74        /** Returns the current model view matrix.
75        */
[2755]76        void GetModelViewMatrix(Matrix4x4 &mat);
[2911]77        /** Calculates a frustum from the projection and the modelview matrix.
78        */
[2755]79        void CalcFrustum(Frustum &frustum);
[2806]80        /** Computes the extremal points of this frustum.
81        */
[2762]82        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
[2911]83                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const;
84        /** Computes the extremal points of the base frustum.
85        */
86        void ComputeBasePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
87                                                   Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const;
[2806]88        /** Returns the near plane.
89        */
[2764]90        inline float GetNear() const { return mNear; }
[2806]91        /** Returns the far plane.
92        */
93        inline float GetFar() const { return mFar; }
94        /** Sets the near plane
95        */
[2764]96        void SetNear(float nearDist);
[2806]97        /** Sets the far plane.
98        */
99        void SetFar(float farDist);
[2796]100       
101        void SetOrtho(bool ortho);
102
103        void Yaw(float angle);
104        void Pitch(float angle);
105       
[2806]106        float GetPitch() const { return mPitch; }
107        float GetYaw() const { return mYaw; }
[2838]108        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
[2829]109        /** Sets the camera direction.
110        */
111        void SetDirection(const Vector3 &direction);
[2931]112        /** Returns frustum as polyhedron.
113        */
114        Polyhedron *Camera::ComputeFrustum() const;
[2796]115
[2753]116protected:
117
[2796]118        void Precompute(const Vector3 &direction);
[2753]119
[2796]120        void CalculateFromPitchAndYaw();
[2753]121
[2911]122        void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
123                                                           Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr,
124                                                           const Vector3 &view, const Vector3 &right, const Vector3 &up,
125                                                           const Vector3 &pos) const;
[2780]126
[2796]127        ////////////////
128        //-- members
129
[2753]130        float mFovy;
131        int mWidth;
132        int mHeight;
[2764]133
134        float mNear;
[2796]135
136        float mFar;
137
138        bool mIsOrtho;
139
140        Matrix4x4 mBaseOrientation;
141        Matrix4x4 mViewOrientation;
142
143        float mPitch;
144        float mYaw;
145
146        Vector3 mPosition;
[2753]147};
148
149}
150#endif
Note: See TracBrowser for help on using the repository browser.