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 | /** Sets the camera direction.
|
---|
81 | */
|
---|
82 | void SetDirection(const Vector3 &direction);
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 | protected:
|
---|
87 |
|
---|
88 | void Precompute(const Vector3 &direction);
|
---|
89 |
|
---|
90 | void CalculateFromPitchAndYaw();
|
---|
91 |
|
---|
92 |
|
---|
93 | ////////////////
|
---|
94 | //-- members
|
---|
95 |
|
---|
96 | float mFovy;
|
---|
97 | int mWidth;
|
---|
98 | int mHeight;
|
---|
99 |
|
---|
100 | float mNear;
|
---|
101 |
|
---|
102 | float mFar;
|
---|
103 |
|
---|
104 | bool mIsOrtho;
|
---|
105 |
|
---|
106 | Matrix4x4 mBaseOrientation;
|
---|
107 | Matrix4x4 mViewOrientation;
|
---|
108 |
|
---|
109 | float mPitch;
|
---|
110 | float mYaw;
|
---|
111 |
|
---|
112 | Vector3 mPosition;
|
---|
113 | };
|
---|
114 |
|
---|
115 | }
|
---|
116 | #endif
|
---|