[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 |
|
---|
| 12 |
|
---|
| 13 | class Camera
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
[2755] | 16 |
|
---|
| 17 | /** Small struct representing a frustum.
|
---|
| 18 | */
|
---|
| 19 | struct Frustum
|
---|
| 20 | {
|
---|
| 21 | /// the 6 clip planes
|
---|
| 22 | Plane3 mClipPlanes[6];
|
---|
[2753] | 23 |
|
---|
[2755] | 24 | void CalcNPVertexIndices(int *indices);
|
---|
| 25 | };
|
---|
| 26 |
|
---|
[2753] | 27 | Camera();
|
---|
| 28 |
|
---|
| 29 | Camera(int width, int height, float fieldOfView = 90.f);
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | void SetPosition(const Vector3 &pos);
|
---|
| 33 |
|
---|
| 34 | inline Vector3 GetPosition() const { return mPosition; }
|
---|
[2796] | 35 | Vector3 GetDirection() const;
|
---|
| 36 | Vector3 GetUpVector() const;
|
---|
| 37 | Vector3 GetRightVector() const;
|
---|
[2753] | 38 |
|
---|
| 39 | inline float GetFov() const { return mFovy; }
|
---|
| 40 | inline void GetSize(int &width, int &height) const { width = mWidth; height = mHeight; }
|
---|
[2755] | 41 | inline float GetAspect() const { return (float) mWidth / mHeight; }
|
---|
[2753] | 42 |
|
---|
[2796] | 43 | /** Sets up viewing in gl
|
---|
| 44 | */
|
---|
[2756] | 45 | void SetupCameraView();
|
---|
[2755] | 46 | void GetProjectionMatrix(Matrix4x4 &mat);
|
---|
| 47 | void GetModelViewMatrix(Matrix4x4 &mat);
|
---|
| 48 |
|
---|
| 49 | void CalcFrustum(Frustum &frustum);
|
---|
[2806] | 50 | /** Computes the extremal points of this frustum.
|
---|
| 51 | */
|
---|
[2762] | 52 | void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
|
---|
| 53 | Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr);
|
---|
[2764] | 54 |
|
---|
[2806] | 55 | /** Returns the near plane.
|
---|
| 56 | */
|
---|
[2764] | 57 | inline float GetNear() const { return mNear; }
|
---|
[2806] | 58 | /** Returns the far plane.
|
---|
| 59 | */
|
---|
| 60 | inline float GetFar() const { return mFar; }
|
---|
| 61 | /** Sets the near plane
|
---|
| 62 | */
|
---|
[2764] | 63 | void SetNear(float nearDist);
|
---|
[2806] | 64 | /** Sets the far plane.
|
---|
| 65 | */
|
---|
| 66 | void SetFar(float farDist);
|
---|
[2796] | 67 |
|
---|
| 68 | void SetOrtho(bool ortho);
|
---|
| 69 |
|
---|
| 70 | void Yaw(float angle);
|
---|
| 71 | void Pitch(float angle);
|
---|
| 72 |
|
---|
[2806] | 73 | float GetPitch() const { return mPitch; }
|
---|
| 74 | float GetYaw() const { return mYaw; }
|
---|
[2796] | 75 |
|
---|
| 76 |
|
---|
[2806] | 77 |
|
---|
[2753] | 78 | protected:
|
---|
| 79 |
|
---|
[2796] | 80 | void Precompute(const Vector3 &direction);
|
---|
[2753] | 81 |
|
---|
[2796] | 82 | void CalculateFromPitchAndYaw();
|
---|
[2753] | 83 |
|
---|
[2780] | 84 |
|
---|
[2796] | 85 | ////////////////
|
---|
| 86 | //-- members
|
---|
| 87 |
|
---|
[2753] | 88 | float mFovy;
|
---|
| 89 | int mWidth;
|
---|
| 90 | int mHeight;
|
---|
[2764] | 91 |
|
---|
| 92 | float mNear;
|
---|
[2796] | 93 |
|
---|
| 94 | float mFar;
|
---|
| 95 |
|
---|
| 96 | bool mIsOrtho;
|
---|
| 97 |
|
---|
| 98 | Matrix4x4 mBaseOrientation;
|
---|
| 99 | Matrix4x4 mViewOrientation;
|
---|
| 100 |
|
---|
| 101 | float mPitch;
|
---|
| 102 | float mYaw;
|
---|
| 103 |
|
---|
| 104 | Vector3 mPosition;
|
---|
[2753] | 105 | };
|
---|
| 106 |
|
---|
| 107 | }
|
---|
| 108 | #endif
|
---|