From e24766e5d3f9da4a7a566fe7035727787f9d822b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 24 Jul 2008 17:12:32 +0000 Subject: improved Track view --- src/math/axis.cc | 17 +++++++++++++++++ src/math/axis.h | 3 +++ 2 files changed, 20 insertions(+) (limited to 'src/math') diff --git a/src/math/axis.cc b/src/math/axis.cc index 4d752bf..aa35d92 100644 --- a/src/math/axis.cc +++ b/src/math/axis.cc @@ -74,6 +74,23 @@ void Axis::change_roll(const float angle) { axis_vector[1].assign(up); } +// perform a rotation about an arbitrary axis +/* notes: + http://mathworld.wolfram.com/RotationFormula.html +*/ +void Axis::rotate(Vector3f const &normal, float angle) +{ + float cosa = cosf(angle); + float sina = sinf(angle); + + for (size_t i =0; i < 3; i++) { + axis_vector[i] = + axis_vector[i]*cosa + + normal * dotproduct(normal, axis_vector[i]) * (1 - cosa) + + crossproduct(axis_vector[i], normal)*sina; + } +} + /* Axis const Axis::transpose() { diff --git a/src/math/axis.h b/src/math/axis.h index d011675..1422564 100644 --- a/src/math/axis.h +++ b/src/math/axis.h @@ -48,6 +48,9 @@ public: /// change roll, rotate around forward vector (positive is left) void change_roll(const float angle); + /// rotation about an arbitrary axis + void rotate(Vector3f const &normal, float angle); + private: Vector3f axis_vector[3]; }; -- cgit v1.2.3