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