Browse Source

core: add methods to set the camera's view matrix.

legacy
Sam Hocevar sam 12 years ago
parent
commit
da6062de06
4 changed files with 24 additions and 2 deletions
  1. +13
    -2
      src/camera.cpp
  2. +3
    -0
      src/camera.h
  3. +1
    -0
      src/lol/math/vector.h
  4. +7
    -0
      src/math/vector.cpp

+ 13
- 2
src/camera.cpp View File

@@ -31,6 +31,8 @@ Camera::Camera(vec3 const &position, vec3 const &target, vec3 const &up)
m_gamegroup = GAMEGROUP_BEFORE; m_gamegroup = GAMEGROUP_BEFORE;
m_drawgroup = DRAWGROUP_CAMERA; m_drawgroup = DRAWGROUP_CAMERA;


/* Create a default perspective */
SetPerspective(45.f, 800.f, 600.f, -1000.f, 1000.f);
SetPosition(position); SetPosition(position);
} }


@@ -43,6 +45,17 @@ void Camera::SetPosition(vec3 const &pos)
m_position = pos; m_position = pos;
} }


void Camera::SetOrtho(float width, float height, float near, float far)
{
m_proj_matrix = mat4::ortho(width, height, near, far);
}

void Camera::SetPerspective(float fov, float width, float height,
float near, float far)
{
m_proj_matrix = mat4::perspective(fov, width, height, near, far);
}

mat4 const &Camera::GetViewMatrix() mat4 const &Camera::GetViewMatrix()
{ {
return m_view_matrix; return m_view_matrix;
@@ -81,8 +94,6 @@ void Camera::TickGame(float seconds)
m_target += vec3(rightleft, 0, -updown) * 200.f * seconds; m_target += vec3(rightleft, 0, -updown) * 200.f * seconds;


m_view_matrix = mat4::lookat(m_position, m_target, m_up); m_view_matrix = mat4::lookat(m_position, m_target, m_up);
m_proj_matrix = mat4::perspective(45.0f, 640.0f, 480.0f, 1.f, 10000.0f);
//m_proj_matrix = mat4::ortho(-160, 160, -120, 120, .1f, 2000.0f);
} }


void Camera::TickDraw(float seconds) void Camera::TickDraw(float seconds)


+ 3
- 0
src/camera.h View File

@@ -30,6 +30,9 @@ public:
char const *GetName() { return "<camera>"; } char const *GetName() { return "<camera>"; }


void SetPosition(vec3 const &pos); void SetPosition(vec3 const &pos);
void SetOrtho(float width, float height, float near, float far);
void SetPerspective(float fov, float width, float height,
float near, float far);


mat4 const &GetViewMatrix(); mat4 const &GetViewMatrix();
mat4 const &GetProjMatrix(); mat4 const &GetProjMatrix();


+ 1
- 0
src/lol/math/vector.h View File

@@ -1814,6 +1814,7 @@ template <typename T> struct Mat4


/* Helpers for projection matrices */ /* Helpers for projection matrices */
static Mat4<T> ortho(T left, T right, T bottom, T top, T near, T far); static Mat4<T> ortho(T left, T right, T bottom, T top, T near, T far);
static Mat4<T> ortho(T width, T height, T near, T far);
static Mat4<T> frustum(T left, T right, T bottom, T top, T near, T far); static Mat4<T> frustum(T left, T right, T bottom, T top, T near, T far);
static Mat4<T> perspective(T fov_y, T width, T height, T near, T far); static Mat4<T> perspective(T fov_y, T width, T height, T near, T far);




+ 7
- 0
src/math/vector.cpp View File

@@ -658,6 +658,13 @@ template<> mat4 mat4::ortho(float left, float right, float bottom,
return ret; return ret;
} }


template<> mat4 mat4::ortho(float width, float height,
float near, float far)
{
return mat4::ortho(-0.5f * width, 0.5f * width,
-0.5f * height, 0.5f * height, near, far);
}

template<> mat4 mat4::frustum(float left, float right, float bottom, template<> mat4 mat4::frustum(float left, float right, float bottom,
float top, float near, float far) float top, float near, float far)
{ {


Loading…
Cancel
Save