From abe6c3dc6e6f9df40345d6aaf19f12fdfa3f3024 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 24 Jul 2008 18:59:44 +0000 Subject: delta protection for camera rotations --- src/render/camera.cc | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/render/camera.cc b/src/render/camera.cc index c35cb3c..74eb674 100644 --- a/src/render/camera.cc +++ b/src/render/camera.cc @@ -191,26 +191,33 @@ void Camera::frame(float seconds) float angle; // angle in radians math::Vector3f n; // normal of a plane - // camera axis: pitch & direction - n.assign(math::crossproduct(camera_axis.forward(), target_axis.forward())); - if (n.lengthsquared() > MIN_DELTA) { + if (!(n.length() < MIN_DELTA)) { n.normalize(); cosangle = math::dotproduct(camera_axis.forward(), target_axis.forward()); - angle = acos(cosangle); // * 180.0f / M_PI; - camera_axis.rotate(n, -angle * seconds); + angle = acos(cosangle) * seconds; // * 180.0f / M_PI; + if (angle > MIN_DELTA) + camera_axis.rotate(n, -angle); } - // camera axis: roll - n.assign(math::crossproduct(camera_axis.left(), target_axis.left())); - if (n.lengthsquared() > MIN_DELTA) { + if (!(n.length() < MIN_DELTA)) { n.normalize(); cosangle = math::dotproduct(camera_axis.left(), target_axis.left()); - angle = acos(cosangle); // * 180.0f / M_PI; - camera_axis.rotate(n, -angle * seconds); + angle = acos(cosangle) * seconds; // * 180.0f / M_PI; + if (angle > MIN_DELTA) + camera_axis.rotate(n, -angle); } + n.assign(math::crossproduct(camera_axis.up(), target_axis.up())); + if (!(n.length() < MIN_DELTA)) { + n.normalize(); + cosangle = math::dotproduct(camera_axis.up(), target_axis.up()); + angle = acos(cosangle) * seconds; // * 180.0f / M_PI; + if (angle > MIN_DELTA) + camera_axis.rotate(n, -angle); + } + if (core::localcontrol()->model()) { camera_target -= (core::localcontrol()->model()->maxbbox().x + core::localcontrol()->model()->radius() + 0.1f) * 0.5f * camera_axis.forward(); camera_target += (core::localcontrol()->model()->maxbbox().z + core::localcontrol()->model()->radius() + 0.1f) * 0.5f * camera_axis.up(); @@ -231,6 +238,8 @@ void Camera::frame(float seconds) d = degrees180f(pitch_current - pitch_target); pitch_current = degrees360f(pitch_current - d * seconds); camera_axis.change_pitch(pitch_current); + + distance = 1.5f * core::localcontrol()->radius(); } else if (mode() == Cockpit) { -- cgit v1.2.3