Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/Camera.h
Show All 17 Lines | |||||
/* | /* | ||||
* CCamera holds a view and a projection matrix. It also has a frustum | * CCamera holds a view and a projection matrix. It also has a frustum | ||||
* which can be used to cull objects for rendering. | * which can be used to cull objects for rendering. | ||||
*/ | */ | ||||
#ifndef INCLUDED_CAMERA | #ifndef INCLUDED_CAMERA | ||||
#define INCLUDED_CAMERA | #define INCLUDED_CAMERA | ||||
#include "Frustum.h" | #include "graphics/Frustum.h" | ||||
#include "maths/BoundingBoxAligned.h" | #include "maths/BoundingBoxAligned.h" | ||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
// view port | // view port | ||||
struct SViewPort | struct SViewPort | ||||
{ | { | ||||
int m_X; | int m_X; | ||||
int m_Y; | int m_Y; | ||||
int m_Width; | int m_Width; | ||||
int m_Height; | int m_Height; | ||||
}; | }; | ||||
class CCamera | class CCamera | ||||
{ | { | ||||
public: | public: | ||||
CCamera(); | CCamera(); | ||||
~CCamera(); | ~CCamera(); | ||||
// Methods for projection | |||||
void SetProjection(float nearp, float farp, float fov); | |||||
void SetProjection(const CMatrix3D& matrix) { m_ProjMat = matrix; } | |||||
void SetProjectionTile(int tiles, int tile_x, int tile_y); | |||||
CMatrix3D& GetProjection() { return m_ProjMat; } | CMatrix3D& GetProjection() { return m_ProjMat; } | ||||
const CMatrix3D& GetProjection() const { return m_ProjMat; } | const CMatrix3D& GetProjection() const { return m_ProjMat; } | ||||
CMatrix3D GetViewProjection() const { return m_ProjMat * m_Orientation.GetInverse(); } | |||||
void SetProjection(const CMatrix3D& matrix) { m_ProjMat = matrix; } | |||||
void SetPerspectiveProjection(float nearp, float farp, float fov); | |||||
void SetPerspectiveProjectionTile(int tiles, int tile_x, int tile_y); | |||||
CMatrix3D& GetOrientation() { return m_Orientation; } | CMatrix3D& GetOrientation() { return m_Orientation; } | ||||
const CMatrix3D& GetOrientation() const { return m_Orientation; } | const CMatrix3D& GetOrientation() const { return m_Orientation; } | ||||
CMatrix3D GetViewProjection() const { return m_ProjMat * m_Orientation.GetInverse(); } | |||||
// Updates the frustum planes. Should be called | // Updates the frustum planes. Should be called | ||||
// everytime the view or projection matrices are | // everytime the view or projection matrices are | ||||
// altered. | // altered. | ||||
void UpdateFrustum(const CBoundingBoxAligned& scissor = CBoundingBoxAligned(CVector3D(-1.0f, -1.0f, -1.0f), CVector3D(1.0f, 1.0f, 1.0f))); | void UpdateFrustum(const CBoundingBoxAligned& scissor = CBoundingBoxAligned(CVector3D(-1.0f, -1.0f, -1.0f), CVector3D(1.0f, 1.0f, 1.0f))); | ||||
void ClipFrustum(const CPlane& clipPlane); | void ClipFrustum(const CPlane& clipPlane); | ||||
const CFrustum& GetFrustum() const { return m_ViewFrustum; } | const CFrustum& GetFrustum() const { return m_ViewFrustum; } | ||||
void SetViewPort(const SViewPort& viewport); | void SetViewPort(const SViewPort& viewport); | ||||
Show All 40 Lines | public: | ||||
*/ | */ | ||||
void Render(int intermediates = 0) const; | void Render(int intermediates = 0) const; | ||||
public: | public: | ||||
// This is the orientation matrix. The inverse of this | // This is the orientation matrix. The inverse of this | ||||
// is the view matrix | // is the view matrix | ||||
CMatrix3D m_Orientation; | CMatrix3D m_Orientation; | ||||
// Should not be tweaked externally if possible | private: | ||||
CMatrix3D m_ProjMat; | CMatrix3D m_ProjMat; | ||||
private: | |||||
float m_NearPlane; | float m_NearPlane; | ||||
float m_FarPlane; | float m_FarPlane; | ||||
float m_FOV; | float m_FOV; | ||||
SViewPort m_ViewPort; | SViewPort m_ViewPort; | ||||
CFrustum m_ViewFrustum; | CFrustum m_ViewFrustum; | ||||
}; | }; | ||||
#endif // INCLUDED_CAMERA | #endif // INCLUDED_CAMERA |
Wildfire Games · Phabricator