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

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