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

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
[2911]15/** Class representing a frustum.
16*/
17class Frustum
[2753]18{
[2911]19        friend class Camera;
20
[2753]21public:
[2911]22
23        Frustum() {};
24
25        Frustum(const Matrix4x4 &trafo);
26
[2936]27        enum { LEFT_PLANE, RIGHT_PLANE, BOTTOM_PLANE, TOP_PLANE, NEAR_PLANE, FAR_PLANE};
28
[2911]29        /** Resizes the current frustum so that it fully encloses the given polyhedron
[2755]30        */
[2911]31        void EnclosePolyhedron(const Polyhedron &polyhedron);
[2753]32
[2911]33        void ExtractTransformation(Matrix4x4 &m) const;
34
35
36        /// the 6 clip planes
37        Plane3 mClipPlanes[6];
38};
39
40
41class Camera
42{
[2932]43        friend class ShadowMap;
[2911]44public:
[2755]45       
[2753]46        Camera();
47
48        Camera(int width, int height, float fieldOfView = 90.f);
49
[2932]50        /** Sets the current camera position.
51        */
[2753]52        void SetPosition(const Vector3 &pos);
53
54        inline Vector3 GetPosition() const { return mPosition; }
[2911]55       
[2796]56        Vector3 GetDirection() const;
57        Vector3 GetUpVector() const;
58        Vector3 GetRightVector() const;
[2753]59
[2911]60        Vector3 GetBaseDirection() const;
61        Vector3 GetBaseUpVector() const;
62        Vector3 GetBaseRightVector() const;
63
[2753]64        inline float GetFov() const { return mFovy; }
[2755]65        inline float GetAspect() const { return (float) mWidth / mHeight; }
[2826]66        inline int GetWidth() const { return mWidth; }
67        inline int GetHeight() const { return mHeight; }
[2753]68
[2796]69        /** Sets up viewing in gl
70        */
[2756]71        void SetupCameraView();
[2826]72        /** Returns the current projection matrix.
73        */
[2986]74        void GetProjectionMatrix(Matrix4x4 &mat) const;
[2826]75        /** Returns the current model view matrix.
76        */
[2986]77        void GetModelViewMatrix(Matrix4x4 &mat) const;
78
79        void GetViewOrientationMatrix(Matrix4x4 &mat) const;
[2911]80        /** Calculates a frustum from the projection and the modelview matrix.
81        */
[2755]82        void CalcFrustum(Frustum &frustum);
[2806]83        /** Computes the extremal points of this frustum.
[2947]84                If farthestVisibleDistance is nearer than the far plane,
85                it is used to define the far plane instead.
[2806]86        */
[2762]87        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
[2947]88                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr,
89                                           float farthestVisibleDistance = 1e25f) const;
[2806]90        /** Returns the near plane.
91        */
[2764]92        inline float GetNear() const { return mNear; }
[2806]93        /** Returns the far plane.
94        */
95        inline float GetFar() const { return mFar; }
96        /** Sets the near plane
97        */
[2764]98        void SetNear(float nearDist);
[2806]99        /** Sets the far plane.
100        */
101        void SetFar(float farDist);
[2796]102       
103        void SetOrtho(bool ortho);
104
105        void Yaw(float angle);
106        void Pitch(float angle);
107       
[2806]108        float GetPitch() const { return mPitch; }
109        float GetYaw() const { return mYaw; }
[2838]110        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
[2829]111        /** Sets the camera direction.
112        */
113        void SetDirection(const Vector3 &direction);
[2947]114        /** Returns frustum as polyhedron.
[2931]115        */
[2947]116        Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const;
[2796]117
[2753]118protected:
119
[2796]120        void Precompute(const Vector3 &direction);
[2753]121
[2796]122        void CalculateFromPitchAndYaw();
[2753]123
[2911]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,
[2947]127                                                           const Vector3 &pos,
128                                                           float farthestVisibleDistance = 1e25f) const;
[2780]129
[2796]130        ////////////////
131        //-- members
132
[2753]133        float mFovy;
134        int mWidth;
135        int mHeight;
[2764]136
137        float mNear;
[2796]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;
[2753]150};
151
152}
153#endif
Note: See TracBrowser for help on using the repository browser.