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

Revision 3147, 5.1 KB checked in by mattausch, 16 years ago (diff)

updated shader loading

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
[3062]15
[2911]16/** Class representing a frustum.
17*/
18class Frustum
[2753]19{
[2911]20        friend class Camera;
21
[2753]22public:
[2911]23
[3147]24        enum {LEFT_PLANE, RIGHT_PLANE, BOTTOM_PLANE, TOP_PLANE, NEAR_PLANE, FAR_PLANE};
25
[2911]26        Frustum() {};
27
28        Frustum(const Matrix4x4 &trafo);
29
30        /** Resizes the current frustum so that it fully encloses the given polyhedron
[2755]31        */
[2911]32        void EnclosePolyhedron(const Polyhedron &polyhedron);
[2753]33
[2911]34        void ExtractTransformation(Matrix4x4 &m) const;
35
36
37        /// the 6 clip planes
38        Plane3 mClipPlanes[6];
39};
40
41
[3061]42/** Classs representing a camera.
43*/
[2911]44class Camera
45{
46public:
[3061]47        /** Default constructor.
48        */
[2753]49        Camera();
[2932]50        /** Sets the current camera position.
51        */
[2753]52        void SetPosition(const Vector3 &pos);
[3061]53        /** See set.
54        */
[2753]55        inline Vector3 GetPosition() const { return mPosition; }
[3061]56        /** Returns view direction.
57        */
[2796]58        Vector3 GetDirection() const;
[3061]59        /** Returns up vector.
60        */
[2796]61        Vector3 GetUpVector() const;
[3061]62        /** Returns right vector.
63        */
[2796]64        Vector3 GetRightVector() const;
[2753]65
[2911]66        Vector3 GetBaseDirection() const;
67        Vector3 GetBaseUpVector() const;
68        Vector3 GetBaseRightVector() const;
[3061]69        /** Sets up viewing matrices in for opengl rendering
70        */
[2756]71        void SetupCameraView();
[2826]72        /** Returns the current projection matrix.
73        */
[3063]74        void GetProjectionMatrix(Matrix4x4 &mat) const;
[2826]75        /** Returns the current model view matrix.
76        */
[2986]77        void GetModelViewMatrix(Matrix4x4 &mat) const;
[3045]78        /** Returns the view orientation (the model view matrix without the translation)
79        */
[2986]80        void GetViewOrientationMatrix(Matrix4x4 &mat) const;
[2806]81        /** Returns the near plane.
82        */
[2764]83        inline float GetNear() const { return mNear; }
[2806]84        /** Returns the far plane.
85        */
86        inline float GetFar() const { return mFar; }
87        /** Sets the near plane
88        */
[2764]89        void SetNear(float nearDist);
[2806]90        /** Sets the far plane.
91        */
92        void SetFar(float farDist);
[3061]93        /** Set yaw (rotation around vertical axis.
94        */
[2796]95        void Yaw(float angle);
[3061]96        /** Set pitch.
97        */
[2796]98        void Pitch(float angle);
[3061]99        /** Returns pitch.
100        */
[2806]101        float GetPitch() const { return mPitch; }
[3061]102        /** Returns yaw.
103        */
[2806]104        float GetYaw() const { return mYaw; }
[3061]105        /** Resets pitch and yaw.
106        */
[2838]107        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
[3061]108        /** Sets the view direction.
[2829]109        */
110        void SetDirection(const Vector3 &direction);
[3061]111        /** Sets up projection matrix in OpenGl.
112        */
113        void SetupProjection();
114        /** Sets up view + projection matrix in OpenGl.
115        */
116        void SetupViewProjection();
[3062]117        /** Calculates a frustum from the projection and the modelview matrix.
118        */
119        void CalcFrustum(Frustum &frustum);
[2796]120
[2753]121protected:
122
[3063]123        virtual void UpdateProjectionMatrix() = 0;
124
[2796]125        void Precompute(const Vector3 &direction);
[2753]126
[2796]127        void CalculateFromPitchAndYaw();
[2753]128
[2780]129
[2796]130        ////////////////
131        //-- members
132
[2764]133        float mNear;
[2796]134        float mFar;
[3061]135       
[2796]136        Matrix4x4 mBaseOrientation;
137        Matrix4x4 mViewOrientation;
138
[3063]139        Matrix4x4 mProjection;
140
[2796]141        float mPitch;
142        float mYaw;
143
144        Vector3 mPosition;
[3062]145};
[3061]146
[3062]147
148/** Classs representing a perspective camera.
149*/
150class PerspectiveCamera: public Camera
151{
152        friend class ShadowMap;
153
154public:
155        /** Default constructor.
156        */
157        PerspectiveCamera();
158        /** Camera taking the image width and height and the field of view.
159        */
160        PerspectiveCamera(float aspect, float fieldOfView = 90.f);
161        /** Returns the field of view.
162        */
163        inline float GetFov() const { return mFOVy; }
164        /** Returns the aspect ratio.
165        */
166        inline float GetAspect() const { return mAspect; }
167        /** Computes the extremal points of this frustum.
168                If farthestVisibleDistance is nearer than the far plane,
169                it is used to define the far plane instead.
170        */
171        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
172                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr,
173                                           float farthestVisibleDistance = 1e25f) const;
174        /** Returns frustum as polyhedron.
175        */
176        Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const;
177
178
179protected:
[3063]180        /** Calculates the current projection matrix.
181        */
182        virtual void UpdateProjectionMatrix();
[3062]183
184        void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
185                                                           Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr,
186                                                           const Vector3 &view, const Vector3 &right, const Vector3 &up,
187                                                           const Vector3 &pos,
188                                                           float farthestVisibleDistance = 1e25f) const;
189
190        ////////////////
191        //-- members
192
193        float mFOVy;
[3061]194        float mAspect;
[2753]195};
196
[3102]197/** Classs representing an orthographics camera.
198*/
199class OrthoCamera: public Camera
200{
201        friend class ShadowMap;
[3062]202
[3102]203public:
204        /** Default constructor.
205        */
206        OrthoCamera();
207        /** Camera taking the frustum left, right, bottom, top.
208        */
209        OrthoCamera(float l, float r, float b, float t);
210
211        /** Camera taking the frustum left, right, bottom, top, near, far.
212        */
213        OrthoCamera(float l, float r, float b, float t, float n, float f);
214
215
216protected:
217        /** Calculates the current projection matrix.
218        */
219        virtual void UpdateProjectionMatrix();
220
221
222        //////////
223        //-- members
224
225        float mLeft;
226        float mRight;
227        float mBottom;
228        float mTop;
229};
[2753]230}
231#endif
Note: See TracBrowser for help on using the repository browser.