diff --git a/src/Magnum.h b/src/Magnum.h index c7a15bf31..6a2d174df 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -53,18 +53,20 @@ namespace Corrade { } namespace Magnum { - namespace Math { - template class Vector2; - template class Vector3; - template class Vector4; - template class Point2D; - template class Point3D; - template class Matrix3; - template class Matrix4; - - template constexpr T deg(T value); - template constexpr T rad(T value); - } + +namespace Math { + template class Vector2; + template class Vector3; + template class Vector4; + template class Point2D; + template class Point3D; + template class Matrix3; + template class Matrix4; + + template constexpr T deg(T value); + template constexpr T rad(T value); + template struct Constants; +} /* Bring debugging facility from Corrade::Utility namespace */ using Corrade::Utility::Debug; @@ -92,6 +94,10 @@ typedef Math::Matrix3 Matrix3; /** @brief 4x4 floating-point matrix */ typedef Math::Matrix4 Matrix4; +/** @brief Floating-point constants */ +/* Using float instead of GLfloat to not break KDevelop autocompletion */ +typedef Math::Constants Constants; + /* Copying angle converters from Math namespace */ using Math::deg; using Math::rad; diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 0c9a8882e..422bd12bb 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -30,7 +30,7 @@ namespace Magnum { namespace Physics { template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); - float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Math::Constants::sqrt3())).length(); + float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 91caac41d..94b971b3e 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -31,11 +31,11 @@ namespace { template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { - return Vector2(1/Math::Constants::sqrt2()); + return Vector2(1/Constants::sqrt2()); } template<> inline Vector3 unitVector<3>() { - return Vector3(1/Math::Constants::sqrt3()); + return Vector3(1/Constants::sqrt3()); } } diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 1d11fabc4..698778a90 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -38,8 +38,8 @@ void CapsuleTest::applyTransformation() { CORRADE_COMPARE(capsule.radius(), 7.0f); /* Apply average scaling to radius */ - capsule.applyTransformation(Matrix4::scaling({Math::Constants::sqrt3(), -Math::Constants::sqrt2(), 2.0f})); - CORRADE_COMPARE(capsule.transformedRadius(), Math::Constants::sqrt3()*7.0f); + capsule.applyTransformation(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); + CORRADE_COMPARE(capsule.transformedRadius(), Constants::sqrt3()*7.0f); } void CapsuleTest::collisionPoint() { diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index 75170f84c..294032de7 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -31,16 +31,16 @@ PlaneTest::PlaneTest() { } void PlaneTest::applyTransformation() { - Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Math::Constants::sqrt2(), -Math::Constants::sqrt2(), 0}); + Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0}); plane.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::xAxis())); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.0f, -3.0f, 2.0f)); - CORRADE_COMPARE(plane.transformedNormal(), Vector3(Math::Constants::sqrt2(), 0, -Math::Constants::sqrt2())); + CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), 0, -Constants::sqrt2())); /* The normal should stay normalized */ plane.applyTransformation(Matrix4::scaling({1.5f, 2.0f, 3.0f})); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.5f, 4.0f, 9.0f)); - CORRADE_COMPARE(plane.transformedNormal(), Vector3(Math::Constants::sqrt2(), -Math::Constants::sqrt2(), 0)); + CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), -Constants::sqrt2(), 0)); } void PlaneTest::collisionLine() { diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index 473be576c..f845b942e 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -45,8 +45,8 @@ void SphereTest::applyTransformation() { CORRADE_COMPARE(sphere.transformedRadius(), 14.0f); /* Apply average scaling to radius */ - sphere.applyTransformation(Matrix4::scaling({Math::Constants::sqrt3(), -Math::Constants::sqrt2(), 2.0f})); - CORRADE_COMPARE(sphere.transformedRadius(), Math::Constants::sqrt3()*7.0f); + sphere.applyTransformation(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); + CORRADE_COMPARE(sphere.transformedRadius(), Constants::sqrt3()*7.0f); } void SphereTest::collisionPoint() { diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 266be7617..c7d6568c7 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -27,13 +27,13 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std GLfloat height = 2.0f+length; GLfloat hemisphereTextureCoordsVIncrement = 1.0f/(hemisphereRings*height); - GLfloat hemisphereRingAngleIncrement = Math::Constants::pi()/(2*hemisphereRings); + GLfloat hemisphereRingAngleIncrement = Constants::pi()/(2*hemisphereRings); /* Bottom cap vertex */ capVertex(-height/2, -1.0f, 0.0f); /* Rings of bottom hemisphere */ - hemisphereVertexRings(hemisphereRings-1, -length/2, -Math::Constants::pi()/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); + hemisphereVertexRings(hemisphereRings-1, -length/2, -Constants::pi()/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); /* Rings of cylinder */ cylinderVertexRings(cylinderRings+1, -length/2, length/cylinderRings, 1.0f/height, length/(cylinderRings*height)); @@ -61,7 +61,7 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { } void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { - GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; + GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; GLfloat x, y, z; for(uint32_t i = 0; i != count; ++i) { GLfloat ringAngle = startRingAngle + i*ringAngleIncrement; @@ -87,7 +87,7 @@ void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat sta } void Capsule::cylinderVertexRings(uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { - GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; + GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; for(uint32_t i = 0; i != count; ++i) { for(uint32_t j = 0; j != segments; ++j) { GLfloat segmentAngle = j*segmentAngleIncrement; diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index ebe23b35c..0d8460107 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -49,7 +49,7 @@ Cylinder::Cylinder(uint32_t rings, uint32_t segments, GLfloat length, Flags flag } void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { - GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; + GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; for(uint32_t i = 0; i != segments; ++i) { GLfloat segmentAngle = i*segmentAngleIncrement; diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index e82814264..920ac2dd3 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -27,13 +27,13 @@ UVSphere::UVSphere(uint32_t rings, uint32_t segments, TextureCoords textureCoord CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", ); GLfloat textureCoordsVIncrement = 1.0f/rings; - GLfloat ringAngleIncrement = Math::Constants::pi()/rings; + GLfloat ringAngleIncrement = Constants::pi()/rings; /* Bottom cap vertex */ capVertex(-1.0f, -1.0f, 0.0f); /* Vertex rings */ - hemisphereVertexRings(rings-1, 0.0f, -Math::Constants::pi()/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); + hemisphereVertexRings(rings-1, 0.0f, -Constants::pi()/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); /* Top cap vertex */ capVertex(1.0f, 1.0f, 1.0f);