From afefed080b0011f92fd7d7221df8f77f73a1b672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Thu, 12 Sep 2013 13:31:44 +0000 Subject: [PATCH] Camera : Added useage tweak. --- src/camera.cpp | 21 +++++++++------------ src/camera.h | 2 ++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index 9b045ebd..111a1d4c 100644 --- a/src/camera.cpp +++ b/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) diff --git a/src/camera.h b/src/camera.h index 91a4ad24..493ebd34 100644 --- a/src/camera.h +++ b/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);