diff options
author | Stijn Buys <ingar@osirion.org> | 2008-10-12 11:14:22 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-10-12 11:14:22 +0000 |
commit | 18383a5fc596bf9546f14d7393ee66c57720b116 (patch) | |
tree | 5382c3b380a72149eabbc4f75a2c5744b895e48a /src/math/axis.cc | |
parent | 0d831968949b1119db48530a86c2d1651c6cbfc6 (diff) |
libmath API cleanup
Diffstat (limited to 'src/math/axis.cc')
-rw-r--r-- | src/math/axis.cc | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/math/axis.cc b/src/math/axis.cc index e6442eb..3c11de1 100644 --- a/src/math/axis.cc +++ b/src/math/axis.cc @@ -16,7 +16,8 @@ Axis::Axis() clear(); } -Axis::Axis(const Axis & other) { +Axis::Axis(const Axis & other) +{ assign(other); } @@ -27,22 +28,25 @@ void Axis::clear() axis_vector[2] = Vector3f(0.0f, 0.0f, 1.0f); } -void Axis::assign(const Axis & other) { +void Axis::assign(const Axis & other) +{ for (size_t i=0; i < 3; i++) { axis_vector[i].assign(other.axis_vector[i]); } } -Axis & Axis::operator=(const Axis & other) { +Axis & Axis::operator=(const Axis & other) +{ assign(other); return *this; } // change heading, rotate around Z-axis (positive is left) -void Axis::change_direction(const float angle) { +void Axis::change_direction(const float angle) +{ float cosa = cosf(angle * M_PI / 180.0f); float sina = sinf(angle * M_PI / 180.0f); - + Vector3f forward = axis_vector[0] * cosa + axis_vector[1] * sina; Vector3f left = axis_vector[1] *cosa - axis_vector[0] * sina; @@ -51,25 +55,27 @@ void Axis::change_direction(const float angle) { } // change pitch, rotate around negative Y-axis (positive is up) -void Axis::change_pitch(const float angle) { +void Axis::change_pitch(const float angle) +{ float cosa = cosf(angle * M_PI / 180.0f); float sina = sinf(angle * M_PI / 180.0f); - + Vector3f forward = axis_vector[0] * cosa + axis_vector[2] * sina; Vector3f up = axis_vector[2] * cosa - axis_vector[0] * sina; - + axis_vector[0].assign(forward); axis_vector[2].assign(up); } // change roll, rotate around forward vector (positive is left) -void Axis::change_roll(const float angle) { +void Axis::change_roll(const float angle) +{ float cosa = cosf(angle * M_PI / 180.0f); float sina = sinf(angle * M_PI / 180.0f); - + Vector3f forward = axis_vector[2] * cosa + axis_vector[1] * sina; Vector3f up = axis_vector[1] * cosa - axis_vector[2] * sina; - + axis_vector[2].assign(forward); axis_vector[1].assign(up); } @@ -82,11 +88,11 @@ 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) + + axis_vector[i] = + axis_vector[i]*cosa + + normal * dotproduct(normal, axis_vector[i]) * (1 - cosa) + crossproduct(axis_vector[i], normal)*sina; } } @@ -94,7 +100,7 @@ void Axis::rotate(Vector3f const &normal, float angle) Axis Axis::transpose() const { Axis t; - + for (size_t i = 0; i < 3; i++) for (size_t j = 0; j < 3; j++) t.axis_vector[i][j] = axis_vector[j][i]; |