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 void GetSize(int &width, int &height) const { width = mWidth; height = mHeight; }
|
---|
41 | inline float GetAspect() const { return (float) mWidth / mHeight; }
|
---|
42 |
|
---|
43 | /** Sets up viewing in gl
|
---|
44 | */
|
---|
45 | void SetupCameraView();
|
---|
46 | void GetProjectionMatrix(Matrix4x4 &mat);
|
---|
47 | void GetModelViewMatrix(Matrix4x4 &mat);
|
---|
48 |
|
---|
49 | void CalcFrustum(Frustum &frustum);
|
---|
50 | /** Computes the extremal points of this frustum.
|
---|
51 | */
|
---|
52 | void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
|
---|
53 | Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr);
|
---|
54 |
|
---|
55 | /** Returns the near plane.
|
---|
56 | */
|
---|
57 | inline float GetNear() const { return mNear; }
|
---|
58 | /** Returns the far plane.
|
---|
59 | */
|
---|
60 | inline float GetFar() const { return mFar; }
|
---|
61 | /** Sets the near plane
|
---|
62 | */
|
---|
63 | void SetNear(float nearDist);
|
---|
64 | /** Sets the far plane.
|
---|
65 | */
|
---|
66 | void SetFar(float farDist);
|
---|
67 |
|
---|
68 | void SetOrtho(bool ortho);
|
---|
69 |
|
---|
70 | void Yaw(float angle);
|
---|
71 | void Pitch(float angle);
|
---|
72 |
|
---|
73 | float GetPitch() const { return mPitch; }
|
---|
74 | float GetYaw() const { return mYaw; }
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | protected:
|
---|
79 |
|
---|
80 | void Precompute(const Vector3 &direction);
|
---|
81 |
|
---|
82 | void CalculateFromPitchAndYaw();
|
---|
83 |
|
---|
84 |
|
---|
85 | ////////////////
|
---|
86 | //-- members
|
---|
87 |
|
---|
88 | float mFovy;
|
---|
89 | int mWidth;
|
---|
90 | int mHeight;
|
---|
91 |
|
---|
92 | float mNear;
|
---|
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;
|
---|
105 | };
|
---|
106 |
|
---|
107 | }
|
---|
108 | #endif
|
---|