Changeset 2899


Ignore:
Timestamp:
Sep 12, 2013, 3:31:44 PM (6 years ago)
Author:
touky
Message:

Camera : Added useage tweak.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/camera.cpp

    r2897 r2899  
    7575{
    7676    m_view_matrix = mat4::lookat(pos,
    77                                  pos + rot.transform(vec3(0.f, 0.f, -1.f)),
     77                                 pos + rot.transform(vec3(0.f, 0.f, -max(m_target_distance, 1.f))),
    7878                                 rot.transform(vec3(0.f, 1.f, 0.f)));
    7979    m_position = pos;
    80     m_target_distance = .0f;
    8180}
    8281
     
    157156}
    158157
     158void Camera::UseTarget(bool use_target)
     159{
     160    m_target_distance = ((use_target)?(max(m_target_distance, 1.f)):(.0f));
     161}
    159162
    160163//-----------------------------------------------------------------------------
     
    164167{
    165168    if (m_target_distance > .0f)
    166     {
    167         vec4 up = m_view_matrix * vec4(0.f, 1.f, 0.f, 0.f);
    168         vec4 target = m_view_matrix * vec4(0.f, 0.f, -m_target_distance, 0.f);
    169         SetView(m_position, m_position + target.xyz, up.xyz);
    170     }
     169        SetView(m_position, m_position + GetTarget(), GetUp());
    171170    else
    172         m_view_matrix = m_view_matrix * mat4::translate(pos - m_position);
     171        SetView(GetView() * mat4::translate(pos - m_position));
    173172    m_position = pos;
    174173}
     
    176175void Camera::SetTarget(vec3 target)
    177176{
    178     vec4 up = inverse(m_view_matrix) * vec4(0.f, 1.f, 0.f, 0.f);
    179     SetView(m_position, target, up.xyz);
     177    SetView(m_position, target, GetUp());
    180178}
    181179
    182180void Camera::SetUp(vec3 up)
    183181{
    184     vec4 target = inverse(m_view_matrix) * vec4(0.f, 0.f, -max(m_target_distance, 1.f), 0.f);
    185     SetView(m_position, m_position + target.xyz, up);
     182    SetView(m_position, GetTarget(), up);
    186183}
    187184
  • trunk/src/camera.h

    r2894 r2899  
    5454    void SetDrawInfos(float near, float far);
    5555    void UseShift(bool should_shift);
     56    void UseTarget(bool use_target);
    5657
    5758    float GetFov()          { return m_fov; }
     
    6162    float GetFar()          { return m_far; }
    6263    bool  IsShifted()       { return m_is_shifted; }
     64    bool  IsTargeting()     { return (m_target_distance != .0f); }
    6365
    6466    //camera manipulation Functions
Note: See TracChangeset for help on using the changeset viewer.