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

Revision 2932, 3.4 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 { 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
29        */
30        void EnclosePolyhedron(const Polyhedron &polyhedron);
31
32        void ExtractTransformation(Matrix4x4 &m) const;
33
34
35        /// the 6 clip planes
36        Plane3 mClipPlanes[6];
37};
38
39
40class Camera
41{
42        friend class ShadowMap;
43public:
44       
45        Camera();
46
47        Camera(int width, int height, float fieldOfView = 90.f);
48
49        /** Sets the current camera position.
50        */
51        void SetPosition(const Vector3 &pos);
52
53        inline Vector3 GetPosition() const { return mPosition; }
54       
55        Vector3 GetDirection() const;
56        Vector3 GetUpVector() const;
57        Vector3 GetRightVector() const;
58
59        Vector3 GetBaseDirection() const;
60        Vector3 GetBaseUpVector() const;
61        Vector3 GetBaseRightVector() const;
62
63        inline float GetFov() const { return mFovy; }
64        inline float GetAspect() const { return (float) mWidth / mHeight; }
65        inline int GetWidth() const { return mWidth; }
66        inline int GetHeight() const { return mHeight; }
67
68        /** Sets up viewing in gl
69        */
70        void SetupCameraView();
71        /** Returns the current projection matrix.
72        */
73        void GetProjectionMatrix(Matrix4x4 &mat);
74        /** Returns the current model view matrix.
75        */
76        void GetModelViewMatrix(Matrix4x4 &mat);
77        /** Calculates a frustum from the projection and the modelview matrix.
78        */
79        void CalcFrustum(Frustum &frustum);
80        /** Computes the extremal points of this frustum.
81        */
82        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
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;
88        /** Returns the near plane.
89        */
90        inline float GetNear() const { return mNear; }
91        /** Returns the far plane.
92        */
93        inline float GetFar() const { return mFar; }
94        /** Sets the near plane
95        */
96        void SetNear(float nearDist);
97        /** Sets the far plane.
98        */
99        void SetFar(float farDist);
100       
101        void SetOrtho(bool ortho);
102
103        void Yaw(float angle);
104        void Pitch(float angle);
105       
106        float GetPitch() const { return mPitch; }
107        float GetYaw() const { return mYaw; }
108        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
109        /** Sets the camera direction.
110        */
111        void SetDirection(const Vector3 &direction);
112        /** Returns frustum as polyhedron.
113        */
114        Polyhedron *Camera::ComputeFrustum() const;
115
116protected:
117
118        void Precompute(const Vector3 &direction);
119
120        void CalculateFromPitchAndYaw();
121
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;
126
127        ////////////////
128        //-- members
129
130        float mFovy;
131        int mWidth;
132        int mHeight;
133
134        float mNear;
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;
147};
148
149}
150#endif
Note: See TracBrowser for help on using the repository browser.