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

Revision 2911, 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{
42public:
43       
44        Camera();
45
46        Camera(int width, int height, float fieldOfView = 90.f);
47
48
49        void SetPosition(const Vector3 &pos);
50
51        inline Vector3 GetPosition() const { return mPosition; }
52       
53        Vector3 GetDirection() const;
54        Vector3 GetUpVector() const;
55        Vector3 GetRightVector() const;
56
57        Vector3 GetBaseDirection() const;
58        Vector3 GetBaseUpVector() const;
59        Vector3 GetBaseRightVector() const;
60
61        inline float GetFov() const { return mFovy; }
62        inline float GetAspect() const { return (float) mWidth / mHeight; }
63        inline int GetWidth() const { return mWidth; }
64        inline int GetHeight() const { return mHeight; }
65
66        /** Sets up viewing in gl
67        */
68        void SetupCameraView();
69        /** Returns the current projection matrix.
70        */
71        void GetProjectionMatrix(Matrix4x4 &mat);
72        /** Returns the current model view matrix.
73        */
74        void GetModelViewMatrix(Matrix4x4 &mat);
75        /** Calculates a frustum from the projection and the modelview matrix.
76        */
77        void CalcFrustum(Frustum &frustum);
78        /** Computes the extremal points of this frustum.
79        */
80        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
81                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const;
82        /** Computes the extremal points of the base frustum.
83        */
84        void ComputeBasePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
85                                                   Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const;
86        /** Returns the near plane.
87        */
88        inline float GetNear() const { return mNear; }
89        /** Returns the far plane.
90        */
91        inline float GetFar() const { return mFar; }
92        /** Sets the near plane
93        */
94        void SetNear(float nearDist);
95        /** Sets the far plane.
96        */
97        void SetFar(float farDist);
98       
99        void SetOrtho(bool ortho);
100
101        void Yaw(float angle);
102        void Pitch(float angle);
103       
104        float GetPitch() const { return mPitch; }
105        float GetYaw() const { return mYaw; }
106        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
107        /** Sets the camera direction.
108        */
109        void SetDirection(const Vector3 &direction);
110
111        /** Calculates the intersection of the frustum with the box,
112                returns resultin polyhedron as array of polygons.
113        */
114        Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
115
116
117protected:
118
119        void Precompute(const Vector3 &direction);
120
121        void CalculateFromPitchAndYaw();
122
123        void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
124                                                           Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr,
125                                                           const Vector3 &view, const Vector3 &right, const Vector3 &up,
126                                                           const Vector3 &pos) const;
127
128        ////////////////
129        //-- members
130
131        float mFovy;
132        int mWidth;
133        int mHeight;
134
135        float mNear;
136
137        float mFar;
138
139        bool mIsOrtho;
140
141        Matrix4x4 mBaseOrientation;
142        Matrix4x4 mViewOrientation;
143
144        float mPitch;
145        float mYaw;
146
147        Vector3 mPosition;
148};
149
150}
151#endif
Note: See TracBrowser for help on using the repository browser.