Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-24 18:59:44 +0000
committerStijn Buys <ingar@osirion.org>2008-07-24 18:59:44 +0000
commitabe6c3dc6e6f9df40345d6aaf19f12fdfa3f3024 (patch)
tree8ec3b4987bb7362217e6c7b8ee2d27fcb7e95edc /src/render/camera.cc
parente24766e5d3f9da4a7a566fe7035727787f9d822b (diff)
delta protection for camera rotations
Diffstat (limited to 'src/render/camera.cc')
-rw-r--r--src/render/camera.cc29
1 files changed, 19 insertions, 10 deletions
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) {