diff --git a/src/Magnum.h b/src/Magnum.h index fe6466cec..ba3f95487 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -41,6 +41,10 @@ typedef Math::Matrix3 Matrix3; /** @brief 4x4 floating-point matrix */ typedef Math::Matrix4 Matrix4; +/* Copying angle converters from Math namespace */ +using Math::deg; +using Math::rad; + } #endif diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 0e4886618..70eee796b 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -60,7 +60,7 @@ void Matrix4Test::rotation() { 0.0f, 0.0f, 0.0f, 1.0f }; - QVERIFY(Matrix4::rotation(-74*PI/180.0f, -1.0f, 2.0f, 2.0f) == Matrix4(matrix)); + QVERIFY(Matrix4::rotation(deg(-74.0f), -1.0f, 2.0f, 2.0f) == Matrix4(matrix)); } void Matrix4Test::debug() { diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index fb6e4b4dd..5cdb4131e 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -124,7 +124,7 @@ void VectorTest::angle() { float a[] = { 2.0f, 3.0f, 4.0f }; float b[] = { 1.0f, -2.0f, 3.0f }; - QCOMPARE(Vector3::angle(a, b), 1.16251f); + QCOMPARE(Vector3::angle(a, b), rad(1.16251f)); } void VectorTest::negative() { diff --git a/src/Math/constants.h b/src/Math/constants.h index f43e1be91..2d1528776 100644 --- a/src/Math/constants.h +++ b/src/Math/constants.h @@ -27,6 +27,21 @@ namespace Magnum { namespace Math { /** @brief Maximal tolerance when comparing floats */ #define EPSILON 1.0e-6 +/** + * @brief Angle in degrees + * + * Function to make angle entering less error-prone. Converts the value to + * radians at compile time. For example @c deg(180.0f) is converted to @c 3.14f. + */ +template inline constexpr T deg(T value) { return value*PI/180; } + +/** + * @brief Angle in radians + * + * See also deg(). + */ +template inline constexpr T rad(T value) { return value; } + }} #endif diff --git a/src/Test/CameraTest.cpp b/src/Test/CameraTest.cpp index fdfa80882..b86c1f6cf 100644 --- a/src/Test/CameraTest.cpp +++ b/src/Test/CameraTest.cpp @@ -40,7 +40,7 @@ void CameraTest::orthographic() { void CameraTest::perspective() { Camera camera; - camera.setPerspective(27*PI/180, 32.0f, 100); + camera.setPerspective(deg(27.0f), 32.0f, 100); GLfloat a[] = { 4.1652994f, 0, 0, 0,