From f707e91599efa8f77cdb0769f72827756145da26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 00:22:52 +0100 Subject: [PATCH] Better parameter names in Matrix transformation methods. Mainly it is now explicitly stated in parameter name that rotation axis must be normalized. --- src/Math/Matrix3.h | 16 +++++------ src/Math/Matrix4.h | 50 +++++++++++++++++------------------ src/Math/Test/Matrix4Test.cpp | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 0fdf309bc..9d0ec0223 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -36,37 +36,37 @@ template class Matrix3: public Matrix<3, T> { public: /** * @brief 2D translation matrix - * @param vec Translation vector + * @param vector Translation vector * * @see translation(), Matrix4::translation(const Vector3&), * Vector2::xAxis(), Vector2::yAxis() */ - inline constexpr static Matrix3 translation(const Vector2& vec) { + inline constexpr static Matrix3 translation(const Vector2& vector) { return Matrix3( /* Column-major! */ T(1), T(0), T(0), T(0), T(1), T(0), - vec.x(), vec.y(), T(1) + vector.x(), vector.y(), T(1) ); } /** * @brief 2D scaling matrix - * @param vec Scaling vector + * @param vector Scaling vector * * @see rotationScaling() const, Matrix4::scaling(const Vector3&), * Vector2::xScale(), Vector2::yScale() */ - inline constexpr static Matrix3 scaling(const Vector2& vec) { + inline constexpr static Matrix3 scaling(const Vector2& vector) { return Matrix3( /* Column-major! */ - vec.x(), T(0), T(0), - T(0), vec.y(), T(0), + vector.x(), T(0), T(0), + T(0), vector.y(), T(0), T(0), T(0), T(1) ); } /** * @brief 2D rotation matrix - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise, in radians) * * @see rotation() const, Matrix4::rotation(T, const Vector3&), deg(), * rad() diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 0354eb991..0e4a94cee 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -38,40 +38,40 @@ template class Matrix4: public Matrix<4, T> { public: /** * @brief 3D translation - * @param vec Translation vector + * @param vector Translation vector * * @see translation(), Matrix3::translation(const Vector2&), * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() */ - inline constexpr static Matrix4 translation(const Vector3& vec) { + inline constexpr static Matrix4 translation(const Vector3& vector) { return Matrix4( /* Column-major! */ T(1), T(0), T(0), T(0), T(0), T(1), T(0), T(0), T(0), T(0), T(1), T(0), - vec.x(), vec.y(), vec.z(), T(1) + vector.x(), vector.y(), vector.z(), T(1) ); } /** * @brief 3D scaling - * @param vec Scaling vector + * @param vector Scaling vector * * @see rotationScaling() const, Matrix3::scaling(const Vector2&), * Vector3::xScale(), Vector3::yScale(), Vector3::zScale() */ - inline constexpr static Matrix4 scaling(const Vector3& vec) { + inline constexpr static Matrix4 scaling(const Vector3& vector) { return Matrix4( /* Column-major! */ - vec.x(), T(0), T(0), T(0), - T(0), vec.y(), T(0), T(0), - T(0), T(0), vec.z(), T(0), + vector.x(), T(0), T(0), T(0), + T(0), vector.y(), T(0), T(0), + T(0), T(0), vector.z(), T(0), T(0), T(0), T(0), T(1) ); } /** * @brief 3D rotation around arbitrary axis - * @param angle Rotation angle (counterclockwise, in radians) - * @param vec Normalized rotation axis + * @param angle Rotation angle (counterclockwise, in radians) + * @param normalizedAxis Normalized rotation axis * * If possible, use faster alternatives like xRotation(), yRotation() * or zRotation(). @@ -80,32 +80,32 @@ template class Matrix4: public Matrix<4, T> { * @attention Assertion fails on non-normalized rotation vector and * identity matrix is returned. */ - static Matrix4 rotation(T angle, const Vector3& vec) { - CORRADE_ASSERT(MathTypeTraits::equals(vec.dot(), T(1)), - "Math::Matrix4::rotation(): vector must be normalized", {}); + static Matrix4 rotation(T angle, const Vector3& normalizedAxis) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + "Math::Matrix4::rotation(): axis must be normalized", {}); T sine = std::sin(angle); T cosine = std::cos(angle); T oneMinusCosine = T(1) - cosine; - T xx = vec.x()*vec.x(); - T xy = vec.x()*vec.y(); - T xz = vec.x()*vec.z(); - T yy = vec.y()*vec.y(); - T yz = vec.y()*vec.z(); - T zz = vec.z()*vec.z(); + T xx = normalizedAxis.x()*normalizedAxis.x(); + T xy = normalizedAxis.x()*normalizedAxis.y(); + T xz = normalizedAxis.x()*normalizedAxis.z(); + T yy = normalizedAxis.y()*normalizedAxis.y(); + T yz = normalizedAxis.y()*normalizedAxis.z(); + T zz = normalizedAxis.z()*normalizedAxis.z(); return Matrix4( /* Column-major! */ cosine + xx*oneMinusCosine, - xy*oneMinusCosine + vec.z()*sine, - xz*oneMinusCosine - vec.y()*sine, + xy*oneMinusCosine + normalizedAxis.z()*sine, + xz*oneMinusCosine - normalizedAxis.y()*sine, T(0), - xy*oneMinusCosine - vec.z()*sine, + xy*oneMinusCosine - normalizedAxis.z()*sine, cosine + yy*oneMinusCosine, - yz*oneMinusCosine + vec.x()*sine, + yz*oneMinusCosine + normalizedAxis.x()*sine, T(0), - xz*oneMinusCosine + vec.y()*sine, - yz*oneMinusCosine - vec.x()*sine, + xz*oneMinusCosine + normalizedAxis.y()*sine, + yz*oneMinusCosine - normalizedAxis.x()*sine, cosine + zz*oneMinusCosine, T(0), T(0), T(0), T(0), T(1) diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index fbcc08e4d..b65142c53 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -97,7 +97,7 @@ void Matrix4Test::rotation() { Error::setOutput(&o); CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); - CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): vector must be normalized\n"); + CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): axis must be normalized\n"); Matrix4 matrix( 0.35612214f, -0.80181062f, 0.47987163f, 0.0f,