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

Revision 2911, 3.4 KB checked in by mattausch, 16 years ago (diff)
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
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
[2755]29        */
[2911]30        void EnclosePolyhedron(const Polyhedron &polyhedron);
[2753]31
[2911]32        void ExtractTransformation(Matrix4x4 &m) const;
33
34
35        /// the 6 clip planes
36        Plane3 mClipPlanes[6];
37};
38
39
40class Camera
41{
42public:
[2755]43       
[2753]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; }
[2911]52       
[2796]53        Vector3 GetDirection() const;
54        Vector3 GetUpVector() const;
55        Vector3 GetRightVector() const;
[2753]56
[2911]57        Vector3 GetBaseDirection() const;
58        Vector3 GetBaseUpVector() const;
59        Vector3 GetBaseRightVector() const;
60
[2753]61        inline float GetFov() const { return mFovy; }
[2755]62        inline float GetAspect() const { return (float) mWidth / mHeight; }
[2826]63        inline int GetWidth() const { return mWidth; }
64        inline int GetHeight() const { return mHeight; }
[2753]65
[2796]66        /** Sets up viewing in gl
67        */
[2756]68        void SetupCameraView();
[2826]69        /** Returns the current projection matrix.
70        */
[2755]71        void GetProjectionMatrix(Matrix4x4 &mat);
[2826]72        /** Returns the current model view matrix.
73        */
[2755]74        void GetModelViewMatrix(Matrix4x4 &mat);
[2911]75        /** Calculates a frustum from the projection and the modelview matrix.
76        */
[2755]77        void CalcFrustum(Frustum &frustum);
[2806]78        /** Computes the extremal points of this frustum.
79        */
[2762]80        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
[2911]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;
[2806]86        /** Returns the near plane.
87        */
[2764]88        inline float GetNear() const { return mNear; }
[2806]89        /** Returns the far plane.
90        */
91        inline float GetFar() const { return mFar; }
92        /** Sets the near plane
93        */
[2764]94        void SetNear(float nearDist);
[2806]95        /** Sets the far plane.
96        */
97        void SetFar(float farDist);
[2796]98       
99        void SetOrtho(bool ortho);
100
101        void Yaw(float angle);
102        void Pitch(float angle);
103       
[2806]104        float GetPitch() const { return mPitch; }
105        float GetYaw() const { return mYaw; }
[2838]106        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
[2829]107        /** Sets the camera direction.
108        */
109        void SetDirection(const Vector3 &direction);
[2796]110
[2911]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;
[2796]115
[2806]116
[2753]117protected:
118
[2796]119        void Precompute(const Vector3 &direction);
[2753]120
[2796]121        void CalculateFromPitchAndYaw();
[2753]122
[2911]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;
[2780]127
[2796]128        ////////////////
129        //-- members
130
[2753]131        float mFovy;
132        int mWidth;
133        int mHeight;
[2764]134
135        float mNear;
[2796]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;
[2753]148};
149
150}
151#endif
Note: See TracBrowser for help on using the repository browser.