[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 |
|
---|
[2755] | 9 | namespace CHCDemo
|
---|
| 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 | //float mClipPlane[6][4];
|
---|
| 23 | Plane3 mClipPlanes[6];
|
---|
[2753] | 24 |
|
---|
[2755] | 25 | void CalcNPVertexIndices(int *indices);
|
---|
| 26 | };
|
---|
| 27 |
|
---|
[2753] | 28 | Camera();
|
---|
| 29 |
|
---|
| 30 | Camera(int width, int height, float fieldOfView = 90.f);
|
---|
| 31 |
|
---|
| 32 | void Precompute();
|
---|
| 33 |
|
---|
| 34 | void LookInBox(const AxisAlignedBox3 &box);
|
---|
| 35 |
|
---|
| 36 | void LookAtBox(const AxisAlignedBox3 &box);
|
---|
| 37 |
|
---|
| 38 | void SetPosition(const Vector3 &pos);
|
---|
| 39 |
|
---|
| 40 | void SetDirection(const Vector3 &dir);
|
---|
| 41 |
|
---|
| 42 | inline Vector3 GetPosition() const { return mPosition; }
|
---|
| 43 | inline Vector3 GetDirection() const { return mDirection; }
|
---|
| 44 | inline Vector3 GetUpVector() const { return mUp; }
|
---|
| 45 | inline Vector3 GetRightVector() const { return mRight; }
|
---|
| 46 |
|
---|
| 47 | inline float GetFov() const { return mFovy; }
|
---|
| 48 | inline void GetSize(int &width, int &height) const { width = mWidth; height = mHeight; }
|
---|
[2755] | 49 | inline float GetAspect() const { return (float) mWidth / mHeight; }
|
---|
[2753] | 50 |
|
---|
[2756] | 51 | void SetupCameraView();
|
---|
[2755] | 52 | void GetProjectionMatrix(Matrix4x4 &mat);
|
---|
| 53 | void GetModelViewMatrix(Matrix4x4 &mat);
|
---|
| 54 |
|
---|
| 55 | void CalcFrustum(Frustum &frustum);
|
---|
| 56 |
|
---|
[2762] | 57 | void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
|
---|
| 58 | Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr);
|
---|
[2755] | 59 |
|
---|
[2762] | 60 |
|
---|
[2753] | 61 | protected:
|
---|
| 62 |
|
---|
| 63 | ////////////////
|
---|
| 64 |
|
---|
| 65 | Vector3 mPosition;
|
---|
| 66 | Vector3 mDirection;
|
---|
| 67 |
|
---|
| 68 | /// up vector takes into account the FOV at a unit distance from the origin
|
---|
| 69 | Vector3 mUp;
|
---|
| 70 | /// right vector takes into account the FOV at a unit distance from the origin
|
---|
| 71 | Vector3 mRight;
|
---|
| 72 |
|
---|
| 73 | float mFovy;
|
---|
| 74 | int mWidth;
|
---|
| 75 | int mHeight;
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | }
|
---|
| 79 | #endif
|
---|