Changeset 1350


Ignore:
Timestamp:
May 8, 2012, 10:04:00 PM (11 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1349 r1350  
    7070    //Ticker::Ref(m_particlesystem);
    7171
    72     m_camera = new Camera(vec3(0, 300, 300),
     72    /* Create a camera that matches the settings of XNA Orbital */
     73    m_camera = new Camera(vec3(0, 50, 0),
    7374                          vec3(0, 0, 0),
    74                           vec3(0, 1, 0));
     75                          vec3(0, 0, -1));
     76    m_camera->SetOrtho(1280.f / 3, 960.f / 3, -1000.f, 1000.f);
    7577    Ticker::Ref(m_camera);
    7678
  • trunk/src/camera.cpp

    r1348 r1350  
    3232    m_drawgroup = DRAWGROUP_CAMERA;
    3333
     34    /* Create a default perspective */
     35    SetPerspective(45.f, 800.f, 600.f, -1000.f, 1000.f);
    3436    SetPosition(position);
    3537}
     
    4244{
    4345    m_position = pos;
     46}
     47
     48void Camera::SetOrtho(float width, float height, float near, float far)
     49{
     50    m_proj_matrix = mat4::ortho(width, height, near, far);
     51}
     52
     53void Camera::SetPerspective(float fov, float width, float height,
     54                            float near, float far)
     55{
     56    m_proj_matrix = mat4::perspective(fov, width, height, near, far);
    4457}
    4558
     
    8295
    8396    m_view_matrix = mat4::lookat(m_position, m_target, m_up);
    84     m_proj_matrix = mat4::perspective(45.0f, 640.0f, 480.0f, 1.f, 10000.0f);
    85     //m_proj_matrix = mat4::ortho(-160, 160, -120, 120, .1f, 2000.0f);
    8697}
    8798
  • trunk/src/camera.h

    r1310 r1350  
    3131
    3232    void SetPosition(vec3 const &pos);
     33    void SetOrtho(float width, float height, float near, float far);
     34    void SetPerspective(float fov, float width, float height,
     35                        float near, float far);
    3336
    3437    mat4 const &GetViewMatrix();
  • trunk/src/lol/math/vector.h

    r1349 r1350  
    18151815    /* Helpers for projection matrices */
    18161816    static Mat4<T> ortho(T left, T right, T bottom, T top, T near, T far);
     1817    static Mat4<T> ortho(T width, T height, T near, T far);
    18171818    static Mat4<T> frustum(T left, T right, T bottom, T top, T near, T far);
    18181819    static Mat4<T> perspective(T fov_y, T width, T height, T near, T far);
  • trunk/src/math/vector.cpp

    r1349 r1350  
    659659}
    660660
     661template<> mat4 mat4::ortho(float width, float height,
     662                            float near, float far)
     663{
     664    return mat4::ortho(-0.5f * width, 0.5f * width,
     665                       -0.5f * height, 0.5f * height, near, far);
     666}
     667
    661668template<> mat4 mat4::frustum(float left, float right, float bottom,
    662669                              float top, float near, float far)
Note: See TracChangeset for help on using the changeset viewer.