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

Revision 2986, 3.5 KB checked in by mattausch, 16 years ago (diff)

debug version trying to retrieve position from linear eye space depth

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