Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/Camera.h
Show All 21 Lines | |||||
#ifndef INCLUDED_CAMERA | #ifndef INCLUDED_CAMERA | ||||
#define INCLUDED_CAMERA | #define INCLUDED_CAMERA | ||||
#include "graphics/Frustum.h" | #include "graphics/Frustum.h" | ||||
#include "maths/BoundingBoxAligned.h" | #include "maths/BoundingBoxAligned.h" | ||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
#include <array> | |||||
// 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: | ||||
// Represents camera viewport or frustum side in 3D space. | |||||
using Quad = std::array<CVector3D, 4>; | |||||
CCamera(); | CCamera(); | ||||
~CCamera(); | ~CCamera(); | ||||
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(); } | CMatrix3D GetViewProjection() const { return m_ProjMat * m_Orientation.GetInverse(); } | ||||
void SetProjection(const CMatrix3D& matrix) { m_ProjMat = matrix; } | void SetProjection(const CMatrix3D& matrix) { m_ProjMat = matrix; } | ||||
void SetPerspectiveProjection(float nearp, float farp, float fov); | void SetPerspectiveProjection(float nearp, float farp, float fov); | ||||
void SetPerspectiveProjectionTile(int tiles, int tile_x, int tile_y); | 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; } | ||||
// 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); | ||||
const SViewPort& GetViewPort() const { return m_ViewPort; } | const SViewPort& GetViewPort() const { return m_ViewPort; } | ||||
float GetAspectRatio() const; | |||||
float GetNearPlane() const { return m_NearPlane; } | float GetNearPlane() const { return m_NearPlane; } | ||||
float GetFarPlane() const { return m_FarPlane; } | float GetFarPlane() const { return m_FarPlane; } | ||||
float GetFOV() const { return m_FOV; } | float GetFOV() const { return m_FOV; } | ||||
// Returns four points in camera space at given distance from camera | // Returns a quad of view in camera space at given distance from camera. | ||||
void GetCameraPlanePoints(float dist, CVector3D pts[4]) const; | void GetViewQuad(float dist, Quad& quad) const; | ||||
// Build a ray passing through the screen coordinate (px, py) and the camera | // Build a ray passing through the screen coordinate (px, py) and the camera | ||||
///////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////// | ||||
// BuildCameraRay: calculate origin and ray direction of a ray through | // BuildCameraRay: calculate origin and ray direction of a ray through | ||||
// the pixel (px,py) on the screen | // the pixel (px,py) on the screen | ||||
void BuildCameraRay(int px, int py, CVector3D& origin, CVector3D& dir) const; | void BuildCameraRay(int px, int py, CVector3D& origin, CVector3D& dir) const; | ||||
// General helpers that seem to fit here | // General helpers that seem to fit here | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator