瀏覽代碼

Camera : Added useage tweak.

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 年之前
父節點
當前提交
afefed080b
共有 2 個檔案被更改,包括 11 行新增12 行删除
  1. +9
    -12
      src/camera.cpp
  2. +2
    -0
      src/camera.h

+ 9
- 12
src/camera.cpp 查看文件

@@ -74,10 +74,9 @@ void Camera::SetView(vec3 pos, vec3 rot)
void Camera::SetView(vec3 pos, quat rot)
{
m_view_matrix = mat4::lookat(pos,
pos + rot.transform(vec3(0.f, 0.f, -1.f)),
pos + rot.transform(vec3(0.f, 0.f, -max(m_target_distance, 1.f))),
rot.transform(vec3(0.f, 1.f, 0.f)));
m_position = pos;
m_target_distance = .0f;
}

mat4 Camera::GetView()
@@ -156,6 +155,10 @@ void Camera::UseShift(bool should_shift)
SetProjection(m_fov, m_near, m_far, m_screen_size, m_screen_ratio);
}

void Camera::UseTarget(bool use_target)
{
m_target_distance = ((use_target)?(max(m_target_distance, 1.f)):(.0f));
}

//-----------------------------------------------------------------------------
//camera manipulation Functions
@@ -163,26 +166,20 @@ void Camera::UseShift(bool should_shift)
void Camera::SetPosition(vec3 pos)
{
if (m_target_distance > .0f)
{
vec4 up = m_view_matrix * vec4(0.f, 1.f, 0.f, 0.f);
vec4 target = m_view_matrix * vec4(0.f, 0.f, -m_target_distance, 0.f);
SetView(m_position, m_position + target.xyz, up.xyz);
}
SetView(m_position, m_position + GetTarget(), GetUp());
else
m_view_matrix = m_view_matrix * mat4::translate(pos - m_position);
SetView(GetView() * mat4::translate(pos - m_position));
m_position = pos;
}

void Camera::SetTarget(vec3 target)
{
vec4 up = inverse(m_view_matrix) * vec4(0.f, 1.f, 0.f, 0.f);
SetView(m_position, target, up.xyz);
SetView(m_position, target, GetUp());
}

void Camera::SetUp(vec3 up)
{
vec4 target = inverse(m_view_matrix) * vec4(0.f, 0.f, -max(m_target_distance, 1.f), 0.f);
SetView(m_position, m_position + target.xyz, up);
SetView(m_position, GetTarget(), up);
}

void Camera::SetRotation(vec3 rot)


+ 2
- 0
src/camera.h 查看文件

@@ -53,6 +53,7 @@ public:
void SetDrawInfos(float far);
void SetDrawInfos(float near, float far);
void UseShift(bool should_shift);
void UseTarget(bool use_target);

float GetFov() { return m_fov; }
float GetScreenSize() { return m_screen_size; }
@@ -60,6 +61,7 @@ public:
float GetNear() { return m_near; }
float GetFar() { return m_far; }
bool IsShifted() { return m_is_shifted; }
bool IsTargeting() { return (m_target_distance != .0f); }

//camera manipulation Functions
void SetPosition(vec3 pos);


Loading…
取消
儲存