1 | #ifndef __CAMERA_H
|
---|
2 | #define __CAMERA_H
|
---|
3 |
|
---|
4 | #include "Vector3.h"
|
---|
5 | #include "AxisAlignedBox3.h"
|
---|
6 | #include "Plane3.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace CHCDemoEngine
|
---|
10 | {
|
---|
11 |
|
---|
12 |
|
---|
13 | class Camera
|
---|
14 | {
|
---|
15 | public:
|
---|
16 |
|
---|
17 | /** Small struct representing a frustum.
|
---|
18 | */
|
---|
19 | struct Frustum
|
---|
20 | {
|
---|
21 | /// the 6 clip planes
|
---|
22 | Plane3 mClipPlanes[6];
|
---|
23 |
|
---|
24 | void CalcNPVertexIndices(int *indices);
|
---|
25 | };
|
---|
26 |
|
---|
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; }
|
---|
35 | Vector3 GetDirection() const;
|
---|
36 | Vector3 GetUpVector() const;
|
---|
37 | Vector3 GetRightVector() const;
|
---|
38 |
|
---|
39 | inline float GetFov() const { return mFovy; }
|
---|
40 | inline float GetAspect() const { return (float) mWidth / mHeight; }
|
---|
41 | inline int GetWidth() const { return mWidth; }
|
---|
42 | inline int GetHeight() const { return mHeight; }
|
---|
43 |
|
---|
44 | /** Sets up viewing in gl
|
---|
45 | */
|
---|
46 | void SetupCameraView();
|
---|
47 | /** Returns the current projection matrix.
|
---|
48 | */
|
---|
49 | void GetProjectionMatrix(Matrix4x4 &mat);
|
---|
50 | /** Returns the current model view matrix.
|
---|
51 | */
|
---|
52 | void GetModelViewMatrix(Matrix4x4 &mat);
|
---|
53 |
|
---|
54 | void CalcFrustum(Frustum &frustum);
|
---|
55 | /** Computes the extremal points of this frustum.
|
---|
56 | */
|
---|
57 | void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
|
---|
58 | Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr);
|
---|
59 |
|
---|
60 | /** Returns the near plane.
|
---|
61 | */
|
---|
62 | inline float GetNear() const { return mNear; }
|
---|
63 | /** Returns the far plane.
|
---|
64 | */
|
---|
65 | inline float GetFar() const { return mFar; }
|
---|
66 | /** Sets the near plane
|
---|
67 | */
|
---|
68 | void SetNear(float nearDist);
|
---|
69 | /** Sets the far plane.
|
---|
70 | */
|
---|
71 | void SetFar(float farDist);
|
---|
72 |
|
---|
73 | void SetOrtho(bool ortho);
|
---|
74 |
|
---|
75 | void Yaw(float angle);
|
---|
76 | void Pitch(float angle);
|
---|
77 |
|
---|
78 | float GetPitch() const { return mPitch; }
|
---|
79 | float GetYaw() const { return mYaw; }
|
---|
80 | void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
|
---|
81 | /** Sets the camera direction.
|
---|
82 | */
|
---|
83 | void SetDirection(const Vector3 &direction);
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 | protected:
|
---|
88 |
|
---|
89 | void Precompute(const Vector3 &direction);
|
---|
90 |
|
---|
91 | void CalculateFromPitchAndYaw();
|
---|
92 |
|
---|
93 |
|
---|
94 | ////////////////
|
---|
95 | //-- members
|
---|
96 |
|
---|
97 | float mFovy;
|
---|
98 | int mWidth;
|
---|
99 | int mHeight;
|
---|
100 |
|
---|
101 | float mNear;
|
---|
102 |
|
---|
103 | float mFar;
|
---|
104 |
|
---|
105 | bool mIsOrtho;
|
---|
106 |
|
---|
107 | Matrix4x4 mBaseOrientation;
|
---|
108 | Matrix4x4 mViewOrientation;
|
---|
109 |
|
---|
110 | float mPitch;
|
---|
111 | float mYaw;
|
---|
112 |
|
---|
113 | Vector3 mPosition;
|
---|
114 | };
|
---|
115 |
|
---|
116 | }
|
---|
117 | #endif
|
---|