Browse Source

Bring Math::Constants<float> to Magnum namespace.

You can now write only

    Constants::sqrt3();

instead of

    Math::Constants<GLfloat>::sqrt3();

For other types you can still use the fully qualified name.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
03721cd95c
  1. 30
      src/Magnum.h
  2. 2
      src/Physics/Capsule.cpp
  3. 4
      src/Physics/Sphere.cpp
  4. 4
      src/Physics/Test/CapsuleTest.cpp
  5. 6
      src/Physics/Test/PlaneTest.cpp
  6. 4
      src/Physics/Test/SphereTest.cpp
  7. 8
      src/Primitives/Capsule.cpp
  8. 2
      src/Primitives/Cylinder.cpp
  9. 4
      src/Primitives/UVSphere.cpp

30
src/Magnum.h

@ -53,18 +53,20 @@ namespace Corrade {
}
namespace Magnum {
namespace Math {
template<class> class Vector2;
template<class> class Vector3;
template<class> class Vector4;
template<class> class Point2D;
template<class> class Point3D;
template<class> class Matrix3;
template<class> class Matrix4;
template<class T> constexpr T deg(T value);
template<class T> constexpr T rad(T value);
}
namespace Math {
template<class> class Vector2;
template<class> class Vector3;
template<class> class Vector4;
template<class> class Point2D;
template<class> class Point3D;
template<class> class Matrix3;
template<class> class Matrix4;
template<class T> constexpr T deg(T value);
template<class T> constexpr T rad(T value);
template<class T> struct Constants;
}
/* Bring debugging facility from Corrade::Utility namespace */
using Corrade::Utility::Debug;
@ -92,6 +94,10 @@ typedef Math::Matrix3<GLfloat> Matrix3;
/** @brief 4x4 floating-point matrix */
typedef Math::Matrix4<GLfloat> Matrix4;
/** @brief Floating-point constants */
/* Using float instead of GLfloat to not break KDevelop autocompletion */
typedef Math::Constants<float> Constants;
/* Copying angle converters from Math namespace */
using Math::deg;
using Math::rad;

2
src/Physics/Capsule.cpp

@ -30,7 +30,7 @@ namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void Capsule<dimensions>::applyTransformation(const typename DimensionTraits<dimensions>::MatrixType& transformation) {
_transformedA = (transformation*typename DimensionTraits<dimensions>::PointType(_a)).vector();
_transformedB = (transformation*typename DimensionTraits<dimensions>::PointType(_b)).vector();
float scaling = (transformation.rotationScaling()*typename DimensionTraits<dimensions>::VectorType(1/Math::Constants<float>::sqrt3())).length();
float scaling = (transformation.rotationScaling()*typename DimensionTraits<dimensions>::VectorType(1/Constants::sqrt3())).length();
_transformedRadius = scaling*_radius;
}

4
src/Physics/Sphere.cpp

@ -31,11 +31,11 @@ namespace {
template<std::uint8_t dimensions> static typename DimensionTraits<dimensions>::VectorType unitVector();
template<> inline Vector2 unitVector<2>() {
return Vector2(1/Math::Constants<float>::sqrt2());
return Vector2(1/Constants::sqrt2());
}
template<> inline Vector3 unitVector<3>() {
return Vector3(1/Math::Constants<float>::sqrt3());
return Vector3(1/Constants::sqrt3());
}
}

4
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<GLfloat>::sqrt3(), -Math::Constants<GLfloat>::sqrt2(), 2.0f}));
CORRADE_COMPARE(capsule.transformedRadius(), Math::Constants<GLfloat>::sqrt3()*7.0f);
capsule.applyTransformation(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f}));
CORRADE_COMPARE(capsule.transformedRadius(), Constants::sqrt3()*7.0f);
}
void CapsuleTest::collisionPoint() {

6
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<float>::sqrt2(), -Math::Constants<float>::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<float>::sqrt2(), 0, -Math::Constants<float>::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<float>::sqrt2(), -Math::Constants<float>::sqrt2(), 0));
CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), -Constants::sqrt2(), 0));
}
void PlaneTest::collisionLine() {

4
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<GLfloat>::sqrt3(), -Math::Constants<GLfloat>::sqrt2(), 2.0f}));
CORRADE_COMPARE(sphere.transformedRadius(), Math::Constants<GLfloat>::sqrt3()*7.0f);
sphere.applyTransformation(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f}));
CORRADE_COMPARE(sphere.transformedRadius(), Constants::sqrt3()*7.0f);
}
void SphereTest::collisionPoint() {

8
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<GLfloat>::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<GLfloat>::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<GLfloat>::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<GLfloat>::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;

2
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<GLfloat>::pi()/segments;
GLfloat segmentAngleIncrement = 2*Constants::pi()/segments;
for(uint32_t i = 0; i != segments; ++i) {
GLfloat segmentAngle = i*segmentAngleIncrement;

4
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<GLfloat>::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<GLfloat>::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);

Loading…
Cancel
Save