2015-04-19 20:39:16 +00:00
|
|
|
#ifndef CPROJECTION_HPP
|
|
|
|
#define CPROJECTION_HPP
|
|
|
|
|
|
|
|
#include "Global.hpp"
|
2015-05-06 07:05:06 +00:00
|
|
|
#include "CMatrix4f.hpp"
|
2015-08-20 02:51:47 +00:00
|
|
|
#include <stdio.h>
|
2015-04-19 20:39:16 +00:00
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES 1
|
|
|
|
#include <math.h>
|
2015-10-08 00:21:38 +00:00
|
|
|
namespace Zeus
|
|
|
|
{
|
2015-11-21 01:14:10 +00:00
|
|
|
enum class EProjType
|
2015-04-19 20:39:16 +00:00
|
|
|
{
|
2015-11-21 01:14:10 +00:00
|
|
|
None = 0,
|
|
|
|
Orthographic = 1,
|
|
|
|
Perspective = 2
|
2015-04-19 20:39:16 +00:00
|
|
|
};
|
|
|
|
struct SProjOrtho
|
|
|
|
{
|
|
|
|
float m_top, m_bottom, m_left, m_right, m_near, m_far;
|
|
|
|
SProjOrtho(float p_top=1.0f, float p_bottom=-1.0f, float p_left=-1.0f, float p_right=1.0f,
|
|
|
|
float p_near=1.0f, float p_far=-1.0f) :
|
|
|
|
m_top(p_top), m_bottom(p_bottom), m_left(p_left), m_right(p_right), m_near(p_near), m_far(p_far) {}
|
|
|
|
};
|
|
|
|
struct SProjPersp
|
|
|
|
{
|
|
|
|
float m_fov, m_aspect, m_near, m_far;
|
|
|
|
SProjPersp(float p_fov=55.0f * M_PI / 180.0f, float p_aspect=1.0f, float p_near=0.1f, float p_far=4096.f) :
|
|
|
|
m_fov(p_fov), m_aspect(p_aspect), m_near(p_near), m_far(p_far) {}
|
|
|
|
};
|
|
|
|
extern const SProjOrtho kOrthoIdentity;
|
|
|
|
|
2015-10-25 19:31:41 +00:00
|
|
|
class alignas(16) CProjection
|
2015-04-19 20:39:16 +00:00
|
|
|
{
|
|
|
|
void _updateCachedMatrix();
|
|
|
|
public:
|
|
|
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
|
|
|
|
|
|
|
CProjection()
|
|
|
|
{
|
2015-11-21 01:14:10 +00:00
|
|
|
m_projType = EProjType::Orthographic;
|
2015-04-19 20:39:16 +00:00
|
|
|
m_ortho = SProjOrtho();
|
2015-05-06 07:05:06 +00:00
|
|
|
m_mtx = CMatrix4f::skIdentityMatrix4f;
|
2015-04-19 20:39:16 +00:00
|
|
|
}
|
|
|
|
CProjection(const CProjection& other) {*this = other;}
|
|
|
|
CProjection(const SProjOrtho& ortho) {setOrtho(ortho);}
|
|
|
|
CProjection(const SProjPersp& persp) {setPersp(persp);}
|
|
|
|
|
|
|
|
inline CProjection& operator=(const CProjection& other)
|
|
|
|
{
|
|
|
|
if (this != &other)
|
|
|
|
{
|
|
|
|
m_projType = other.m_projType;
|
|
|
|
m_ortho = other.m_ortho;
|
2015-04-19 23:15:32 +00:00
|
|
|
m_mtx = other.m_mtx;
|
2015-04-19 20:39:16 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setOrtho(const SProjOrtho& ortho)
|
2015-11-21 01:14:10 +00:00
|
|
|
{m_projType = EProjType::Orthographic; m_ortho = ortho; _updateCachedMatrix();}
|
2015-04-19 20:39:16 +00:00
|
|
|
inline void setPersp(const SProjPersp& persp)
|
2015-11-21 01:14:10 +00:00
|
|
|
{m_projType = EProjType::Perspective; m_persp = persp; _updateCachedMatrix();}
|
2015-04-19 20:39:16 +00:00
|
|
|
|
|
|
|
inline EProjType getType() const {return m_projType;}
|
|
|
|
inline const SProjOrtho& getOrtho() const
|
|
|
|
{
|
2015-11-21 01:14:10 +00:00
|
|
|
if (m_projType != EProjType::Orthographic)
|
2015-08-20 02:51:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "attempted to access orthographic structure of non-ortho projection");
|
|
|
|
abort();
|
|
|
|
}
|
2015-04-19 20:39:16 +00:00
|
|
|
return m_ortho;
|
|
|
|
}
|
|
|
|
inline const SProjPersp& getPersp() const
|
|
|
|
{
|
2015-11-21 01:14:10 +00:00
|
|
|
if (m_projType != EProjType::Perspective)
|
2015-08-20 02:51:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "attempted to access perspective structure of non-persp projection");
|
|
|
|
abort();
|
|
|
|
}
|
2015-04-19 20:39:16 +00:00
|
|
|
return m_persp;
|
|
|
|
}
|
|
|
|
|
2015-05-06 07:05:06 +00:00
|
|
|
inline const CMatrix4f& getCachedMatrix() const {return m_mtx;}
|
2015-04-19 20:39:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/* Projection type */
|
|
|
|
enum EProjType m_projType;
|
|
|
|
|
|
|
|
/* Projection intermediate */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
SProjOrtho m_ortho;
|
|
|
|
};
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
SProjPersp m_persp;
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
SProjOrtho m_ortho;
|
|
|
|
SProjPersp m_persp;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Cached projection matrix */
|
2015-05-06 07:05:06 +00:00
|
|
|
CMatrix4f m_mtx;
|
2015-04-19 20:39:16 +00:00
|
|
|
|
|
|
|
};
|
2015-10-08 00:21:38 +00:00
|
|
|
}
|
2015-04-19 20:39:16 +00:00
|
|
|
|
|
|
|
#endif // CMATRIX3F_HPP
|