Browse Source

Point*D Vector* subclasses for homogeneous coordinates.

Vector4 doesn't set W component to one by default anymore, this is now
handled by Point*D itself. This finally allows creating of 2D primitives
and 2D position vectors without messing explicitly with Z = 1.

All classes which should use Point instead of Vector were updated to use
Point instead.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
071afa0b7a
  1. 2
      src/AbstractShaderProgram.h
  2. 8
      src/Magnum.h
  3. 2
      src/Math/CMakeLists.txt
  4. 74
      src/Math/Point2D.h
  5. 75
      src/Math/Point3D.h
  6. 3
      src/Math/Test/CMakeLists.txt
  7. 56
      src/Math/Test/Point2DTest.cpp
  8. 33
      src/Math/Test/Point2DTest.h
  9. 56
      src/Math/Test/Point3DTest.cpp
  10. 33
      src/Math/Test/Point3DTest.h
  11. 1
      src/Math/Test/Vector3Test.cpp
  12. 2
      src/Math/Test/Vector4Test.cpp
  13. 3
      src/Math/Vector3.h
  14. 16
      src/Math/Vector4.h
  15. 2
      src/MeshTools/CombineIndexedArrays.h
  16. 4
      src/MeshTools/GenerateFlatNormals.cpp
  17. 4
      src/MeshTools/GenerateFlatNormals.h
  18. 2
      src/MeshTools/Test/GenerateFlatNormalsTest.cpp
  19. 3
      src/Physics/AxisAlignedBox.cpp
  20. 5
      src/Physics/Capsule.cpp
  21. 5
      src/Physics/Line.cpp
  22. 3
      src/Physics/Plane.cpp
  23. 3
      src/Physics/Point.cpp
  24. 3
      src/Physics/Sphere.cpp
  25. 6
      src/Primitives/Capsule.cpp
  26. 4
      src/Primitives/Cube.cpp
  27. 1
      src/Primitives/Cylinder.cpp
  28. 2
      src/Primitives/Icosphere.cpp
  29. 4
      src/Primitives/Plane.cpp
  30. 6
      src/Primitives/Test/CapsuleTest.cpp
  31. 6
      src/Primitives/Test/CylinderTest.cpp
  32. 6
      src/Primitives/Test/UVSphereTest.cpp
  33. 5
      src/SceneGraph/Light.h
  34. 2
      src/Shaders/PhongShader.h
  35. 9
      src/Trade/MeshData.h
  36. 2
      src/TypeTraits.h

2
src/AbstractShaderProgram.h

@ -41,7 +41,7 @@ functions and properties:
- <strong>%Attribute location</strong> typedefs defining locations and types - <strong>%Attribute location</strong> typedefs defining locations and types
for attribute binding with Mesh::bindAttribute(), for example: for attribute binding with Mesh::bindAttribute(), for example:
@code @code
typedef Attribute<0, Vector4> Position; typedef Attribute<0, Point3D> Position;
typedef Attribute<1, Vector3> Normal; typedef Attribute<1, Vector3> Normal;
typedef Attribute<2, Vector2> TextureCoords; typedef Attribute<2, Vector2> TextureCoords;
@endcode @endcode

8
src/Magnum.h

@ -41,6 +41,8 @@ namespace Magnum {
template<class> class Vector2; template<class> class Vector2;
template<class> class Vector3; template<class> class Vector3;
template<class> class Vector4; template<class> class Vector4;
template<class> class Point2D;
template<class> class Point3D;
template<class> class Matrix3; template<class> class Matrix3;
template<class> class Matrix4; template<class> class Matrix4;
@ -62,6 +64,12 @@ typedef Math::Vector3<GLfloat> Vector3;
/** @brief Four-component floating-point vector */ /** @brief Four-component floating-point vector */
typedef Math::Vector4<GLfloat> Vector4; typedef Math::Vector4<GLfloat> Vector4;
/** @brief Two-dimensional floating-point homogeneous coordinates */
typedef Math::Point2D<GLfloat> Point2D;
/** @brief Three-dimensional floating-point homogeneous coordinates */
typedef Math::Point3D<GLfloat> Point3D;
/** @brief 3x3 floating-point matrix */ /** @brief 3x3 floating-point matrix */
typedef Math::Matrix3<GLfloat> Matrix3; typedef Math::Matrix3<GLfloat> Matrix3;

2
src/Math/CMakeLists.txt

@ -7,6 +7,8 @@ set(MagnumMath_HEADERS
Matrix.h Matrix.h
Matrix3.h Matrix3.h
Matrix4.h Matrix4.h
Point2D.h
Point3D.h
RectangularMatrix.h RectangularMatrix.h
Vector.h Vector.h
Vector2.h Vector2.h

74
src/Math/Point2D.h

@ -0,0 +1,74 @@
#ifndef Magnum_Math_Point2D_h
#define Magnum_Math_Point2D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Math::Point2D
*/
#include "Vector3.h"
namespace Magnum { namespace Math {
/**
@brief Two-dimensional homogeneous coordinates
@tparam T Data type
Same as Vector3, except that constructors have default value for Z component
set to one. See also @ref matrix-vector for brief introduction.
@configurationvalueref{Magnum::Math::Point2D}
*/
template<class T> class Point2D: public Vector3<T> {
public:
/**
* @brief Default constructor
*
* X and Y components are set to zero, Z is set to one.
*/
inline constexpr Point2D(): Vector3<T>(T(0), T(0), T(1)) {}
/** @brief Copy constructor */
inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3<T>(other) {}
/**
* @brief Constructor
* @param x X component
* @param y Y component
* @param z Z component
*/
inline constexpr Point2D(T x, T y, T z = T(1)): Vector3<T>(x, y, z) {}
/**
* @brief Constructor
* @param xy Two-component vector
* @param z Z component
*/
inline constexpr Point2D(const Vector<2, T>& xy, T z = T(1)): Vector3<T>(xy, z) {}
};
/** @debugoperator{Magnum::Math::Point2D} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D<T>& value) {
return debug << static_cast<const Magnum::Math::Vector<3, T>&>(value);
}
}}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Point2D} */
template<class T> struct ConfigurationValue<Magnum::Math::Point2D<T>>: public ConfigurationValue<Magnum::Math::Vector<3, T>> {};
}}
#endif

75
src/Math/Point3D.h

@ -0,0 +1,75 @@
#ifndef Magnum_Math_Point3D_h
#define Magnum_Math_Point3D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Math::Point3D
*/
#include "Vector4.h"
namespace Magnum { namespace Math {
/**
@brief Three-dimensional homogeneous coordinates
@tparam T Data type
Same as Vector4, except that constructors have default value for W component
set to one. See also @ref matrix-vector for brief introduction.
@configurationvalueref{Magnum::Math::Point3D}
*/
template<class T> class Point3D: public Vector4<T> {
public:
/**
* @brief Default constructor
*
* X, Y and Z components are set to zero, W is set to one.
*/
inline constexpr Point3D(): Vector4<T>(T(0), T(0), T(0), T(1)) {}
/** @brief Copy constructor */
inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4<T>(other) {}
/**
* @brief Constructor
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
*/
inline constexpr Point3D(T x, T y, T z, T w = T(1)): Vector4<T>(x, y, z, w) {}
/**
* @brief Constructor
* @param xyz Three-component vector
* @param w W component
*/
inline constexpr Point3D(const Vector<3, T>& xyz, T w = T(1)): Vector4<T>(xyz, w) {}
};
/** @debugoperator{Magnum::Math::Point3D} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D<T>& value) {
return debug << static_cast<const Magnum::Math::Vector<4, T>&>(value);
}
}}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Point3D} */
template<class T> struct ConfigurationValue<Magnum::Math::Point3D<T>>: public ConfigurationValue<Magnum::Math::Vector<4, T>> {};
}}
#endif

3
src/Math/Test/CMakeLists.txt

@ -10,6 +10,9 @@ corrade_add_test2(MathVector2Test Vector2Test.cpp)
corrade_add_test2(MathVector3Test Vector3Test.cpp) corrade_add_test2(MathVector3Test Vector3Test.cpp)
corrade_add_test2(MathVector4Test Vector4Test.cpp) corrade_add_test2(MathVector4Test Vector4Test.cpp)
corrade_add_test2(MathPoint2DTest Point2DTest.cpp)
corrade_add_test2(MathPoint3DTest Point3DTest.cpp)
corrade_add_test2(MathMatrixTest MatrixTest.cpp) corrade_add_test2(MathMatrixTest MatrixTest.cpp)
corrade_add_test2(MathMatrix3Test Matrix3Test.cpp) corrade_add_test2(MathMatrix3Test Matrix3Test.cpp)
corrade_add_test2(MathMatrix4Test Matrix4Test.cpp) corrade_add_test2(MathMatrix4Test Matrix4Test.cpp)

56
src/Math/Test/Point2DTest.cpp

@ -0,0 +1,56 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include "Point2DTest.h"
#include <sstream>
#include "Point2D.h"
CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest)
using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace Math { namespace Test {
typedef Math::Point2D<float> Point2D;
Point2DTest::Point2DTest() {
addTests(&Point2DTest::construct,
&Point2DTest::debug,
&Point2DTest::configuration);
}
void Point2DTest::construct() {
CORRADE_COMPARE(Point2D(), (Vector<3, float>(0.0f, 0.0f, 1.0f)));
CORRADE_COMPARE(Point2D(1, 2), (Vector<3, float>(1.0f, 2.0f, 1.0f)));
CORRADE_COMPARE(Point2D(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f)));
}
void Point2DTest::debug() {
ostringstream o;
Debug(&o) << Point2D(0.5f, 15.0f, 1.0f);
CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n");
}
void Point2DTest::configuration() {
Point2D vec(3.0f, 3.125f, 9.55f);
string value("3 3.125 9.55");
CORRADE_COMPARE(ConfigurationValue<Point2D>::toString(vec), value);
CORRADE_COMPARE(ConfigurationValue<Point2D>::fromString(value), vec);
}
}}}

33
src/Math/Test/Point2DTest.h

@ -0,0 +1,33 @@
#ifndef Magnum_Math_Test_Point2DTest_h
#define Magnum_Math_Test_Point2DTest_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test {
class Point2DTest: public Corrade::TestSuite::Tester<Point2DTest> {
public:
Point2DTest();
void construct();
void debug();
void configuration();
};
}}}
#endif

56
src/Math/Test/Point3DTest.cpp

@ -0,0 +1,56 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include "Point3DTest.h"
#include <sstream>
#include "Point3D.h"
CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest)
using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace Math { namespace Test {
typedef Math::Point3D<float> Point3D;
Point3DTest::Point3DTest() {
addTests(&Point3DTest::construct,
&Point3DTest::debug,
&Point3DTest::configuration);
}
void Point3DTest::construct() {
CORRADE_COMPARE(Point3D(), Point3D(0.0f, 0.0f, 0.0f, 1.0f));
CORRADE_COMPARE(Point3D(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
CORRADE_COMPARE(Point3D(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
}
void Point3DTest::debug() {
ostringstream o;
Debug(&o) << Point3D(0.5f, 15.0f, 1.0f, 1.0f);
CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n");
}
void Point3DTest::configuration() {
Point3D vec(3.0f, 3.125f, 9.0f, 9.55f);
string value("3 3.125 9 9.55");
CORRADE_COMPARE(ConfigurationValue<Point3D>::toString(vec), value);
CORRADE_COMPARE(ConfigurationValue<Point3D>::fromString(value), vec);
}
}}}

33
src/Math/Test/Point3DTest.h

@ -0,0 +1,33 @@
#ifndef Magnum_Math_Test_Point3DTest_h
#define Magnum_Math_Test_Point3DTest_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test {
class Point3DTest: public Corrade::TestSuite::Tester<Point3DTest> {
public:
Point3DTest();
void construct();
void debug();
void configuration();
};
}}}
#endif

1
src/Math/Test/Vector3Test.cpp

@ -40,6 +40,7 @@ Vector3Test::Vector3Test() {
} }
void Vector3Test::construct() { void Vector3Test::construct() {
CORRADE_COMPARE(Vector3(), Vector3(0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, float>(1.0f, 2.0f, 3.0f)));
CORRADE_COMPARE(Vector3(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); CORRADE_COMPARE(Vector3(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f)));
} }

2
src/Math/Test/Vector4Test.cpp

@ -39,7 +39,7 @@ Vector4Test::Vector4Test() {
} }
void Vector4Test::construct() { void Vector4Test::construct() {
CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
CORRADE_COMPARE(Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); CORRADE_COMPARE(Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
} }

3
src/Math/Vector3.h

@ -27,7 +27,8 @@ namespace Magnum { namespace Math {
@brief Three-component vector @brief Three-component vector
@tparam T Data type @tparam T Data type
See @ref matrix-vector for brief introduction. See @ref matrix-vector for brief introduction. See also Point2D for
homogeneous two-dimensional coordinates.
@configurationvalueref{Magnum::Math::Vector3} @configurationvalueref{Magnum::Math::Vector3}
*/ */
template<class T> class Vector3: public Vector<3, T> { template<class T> class Vector3: public Vector<3, T> {

16
src/Math/Vector4.h

@ -27,16 +27,14 @@ namespace Magnum { namespace Math {
@brief Four-component vector @brief Four-component vector
@tparam T Data type @tparam T Data type
See @ref matrix-vector for brief introduction. See @ref matrix-vector for brief introduction. See also Point3D for
homogeneous three-dimensional coordinates.
@configurationvalueref{Magnum::Math::Vector4} @configurationvalueref{Magnum::Math::Vector4}
*/ */
template<class T> class Vector4: public Vector<4, T> { template<class T> class Vector4: public Vector<4, T> {
public: public:
/** /** @copydoc Vector::Vector() */
* @copydoc Vector::Vector inline constexpr Vector4() {}
* W component is set to one.
*/
inline constexpr Vector4(): Vector<4, T>(T(0), T(0), T(0), T(1)) {}
/** @copydoc Vector::Vector(T) */ /** @copydoc Vector::Vector(T) */
inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {} inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {}
@ -51,16 +49,14 @@ template<class T> class Vector4: public Vector<4, T> {
* @param z Z component * @param z Z component
* @param w W component * @param w W component
*/ */
inline constexpr Vector4(T x, T y, T z, T w = T(1)): Vector<4, T>(x, y, z, w) {} inline constexpr Vector4(T x, T y, T z, T w): Vector<4, T>(x, y, z, w) {}
/** /**
* @brief Constructor * @brief Constructor
* @param xyz Three-component vector * @param xyz Three-component vector
* @param w W component * @param w W component
*/ */
/* Not marked as explicit, because conversion from Vector3 to Vector4 inline constexpr Vector4(const Vector<3, T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {}
is fairly common, nearly always with W set to 1 */
inline constexpr Vector4(const Vector<3, T>& xyz, T w = T(1)): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {}
inline T& x() { return (*this)[0]; } /**< @brief X component */ inline T& x() { return (*this)[0]; } /**< @brief X component */
inline constexpr T x() const { return (*this)[0]; } /**< @overload */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */

2
src/MeshTools/CombineIndexedArrays.h

@ -106,7 +106,7 @@ of some STL functions like shown below. Also if one index array is shader by
more than one attribute array, just pass the index array more times. Example: more than one attribute array, just pass the index array more times. Example:
@code @code
std::vector<unsigned int> vertexIndices; std::vector<unsigned int> vertexIndices;
std::vector<Vector4> positions; std::vector<Point3D> positions;
std::vector<unsigned int> normalTextureIndices; std::vector<unsigned int> normalTextureIndices;
std::vector<Vector3> normals; std::vector<Vector3> normals;
std::vector<Vector2> textureCoordinates; std::vector<Vector2> textureCoordinates;

4
src/MeshTools/GenerateFlatNormals.cpp

@ -15,14 +15,14 @@
#include "GenerateFlatNormals.h" #include "GenerateFlatNormals.h"
#include "Math/Vector4.h" #include "Math/Point3D.h"
#include "MeshTools/Clean.h" #include "MeshTools/Clean.h"
using namespace std; using namespace std;
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
tuple<vector<unsigned int>, vector<Vector3>> generateFlatNormals(const vector<unsigned int>& indices, const vector<Vector4>& positions) { tuple<vector<unsigned int>, vector<Vector3>> generateFlatNormals(const vector<unsigned int>& indices, const vector<Point3D>& positions) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple<vector<unsigned int>, vector<Vector3>>())); CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple<vector<unsigned int>, vector<Vector3>>()));
/* Create normal for every triangle (assuming counterclockwise winding) */ /* Create normal for every triangle (assuming counterclockwise winding) */

4
src/MeshTools/GenerateFlatNormals.h

@ -38,7 +38,7 @@ For each face generates one normal vector, removes duplicates before
returning. Example usage: returning. Example usage:
@code @code
std::vector<unsigned int> vertexIndices; std::vector<unsigned int> vertexIndices;
std::vector<Vector4> positions; std::vector<Point3D> positions;
std::vector<unsigned int> normalIndices; std::vector<unsigned int> normalIndices;
std::vector<Vector3> normals; std::vector<Vector3> normals;
@ -50,7 +50,7 @@ use the same indices.
@attention Index count must be divisible by 3, otherwise zero length result @attention Index count must be divisible by 3, otherwise zero length result
is generated. is generated.
*/ */
std::tuple<std::vector<unsigned int>, std::vector<Vector3>> MESHTOOLS_EXPORT generateFlatNormals(const std::vector<unsigned int>& indices, const std::vector<Vector4>& positions); std::tuple<std::vector<unsigned int>, std::vector<Vector3>> MESHTOOLS_EXPORT generateFlatNormals(const std::vector<unsigned int>& indices, const std::vector<Point3D>& positions);
}} }}

2
src/MeshTools/Test/GenerateFlatNormalsTest.cpp

@ -17,7 +17,7 @@
#include <sstream> #include <sstream>
#include "Math/Vector4.h" #include "Math/Point3D.h"
#include "MeshTools/GenerateFlatNormals.h" #include "MeshTools/GenerateFlatNormals.h"
CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest)

3
src/Physics/AxisAlignedBox.cpp

@ -16,11 +16,12 @@
#include "AxisAlignedBox.h" #include "AxisAlignedBox.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Point3D.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
void AxisAlignedBox::applyTransformation(const Matrix4& transformation) { void AxisAlignedBox::applyTransformation(const Matrix4& transformation) {
_transformedPosition = (transformation*Vector4(_position)).xyz(); _transformedPosition = (transformation*Point3D(_position)).xyz();
_transformedSize = transformation.rotationScaling()*_size; _transformedSize = transformation.rotationScaling()*_size;
} }

5
src/Physics/Capsule.cpp

@ -18,6 +18,7 @@
#include "Math/Constants.h" #include "Math/Constants.h"
#include "Math/Math.h" #include "Math/Math.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Point3D.h"
#include "Math/Geometry/Distance.h" #include "Math/Geometry/Distance.h"
#include "Point.h" #include "Point.h"
#include "Sphere.h" #include "Sphere.h"
@ -27,8 +28,8 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
void Capsule::applyTransformation(const Matrix4& transformation) { void Capsule::applyTransformation(const Matrix4& transformation) {
_transformedA = (transformation*Vector4(_a)).xyz(); _transformedA = (transformation*Point3D(_a)).xyz();
_transformedB = (transformation*Vector4(_b)).xyz(); _transformedB = (transformation*Point3D(_b)).xyz();
float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants<float>::sqrt3())).length(); float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants<float>::sqrt3())).length();
_transformedRadius = scaling*_radius; _transformedRadius = scaling*_radius;
} }

5
src/Physics/Line.cpp

@ -16,12 +16,13 @@
#include "Line.h" #include "Line.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Point3D.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
void Line::applyTransformation(const Matrix4& transformation) { void Line::applyTransformation(const Matrix4& transformation) {
_transformedA = (transformation*Vector4(_a)).xyz(); _transformedA = (transformation*Point3D(_a)).xyz();
_transformedB = (transformation*Vector4(_b)).xyz(); _transformedB = (transformation*Point3D(_b)).xyz();
} }
}} }}

3
src/Physics/Plane.cpp

@ -18,6 +18,7 @@
#include <limits> #include <limits>
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Point3D.h"
#include "Math/Geometry/Intersection.h" #include "Math/Geometry/Intersection.h"
#include "LineSegment.h" #include "LineSegment.h"
@ -27,7 +28,7 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
void Plane::applyTransformation(const Matrix4& transformation) { void Plane::applyTransformation(const Matrix4& transformation) {
_transformedPosition = (transformation*Vector4(_position)).xyz(); _transformedPosition = (transformation*Point3D(_position)).xyz();
_transformedNormal = transformation.rotation()*_normal; _transformedNormal = transformation.rotation()*_normal;
} }

3
src/Physics/Point.cpp

@ -16,11 +16,12 @@
#include "Point.h" #include "Point.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Point3D.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
void Point::applyTransformation(const Matrix4& transformation) { void Point::applyTransformation(const Matrix4& transformation) {
_transformedPosition = (transformation*Vector4(_position)).xyz(); _transformedPosition = (transformation*Point3D(_position)).xyz();
} }
}} }}

3
src/Physics/Sphere.cpp

@ -18,6 +18,7 @@
#include "Math/Constants.h" #include "Math/Constants.h"
#include "Math/Math.h" #include "Math/Math.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Point3D.h"
#include "Math/Geometry/Distance.h" #include "Math/Geometry/Distance.h"
#include "LineSegment.h" #include "LineSegment.h"
#include "Point.h" #include "Point.h"
@ -27,7 +28,7 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
void Sphere::applyTransformation(const Matrix4& transformation) { void Sphere::applyTransformation(const Matrix4& transformation) {
_transformedPosition = (transformation*Vector4(_position)).xyz(); _transformedPosition = (transformation*Point3D(_position)).xyz();
float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants<float>::sqrt3())).length(); float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants<float>::sqrt3())).length();
_transformedRadius = scaling*_radius; _transformedRadius = scaling*_radius;
} }

6
src/Primitives/Capsule.cpp

@ -16,13 +16,13 @@
#include "Capsule.h" #include "Capsule.h"
#include "Math/Constants.h" #include "Math/Constants.h"
#include "Math/Vector4.h" #include "Math/Point3D.h"
using namespace std; using namespace std;
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector<unsigned int>, {new vector<Vector4>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) { Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector<unsigned int>, {new vector<Point3D>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", );
GLfloat height = 2.0f+length; GLfloat height = 2.0f+length;
@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig
topFaceRing(); topFaceRing();
} }
Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector<unsigned int>, {new std::vector<Vector4>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {} Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector<unsigned int>, {new std::vector<Point3D>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {}
void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) {
positions(0)->push_back({0.0f, y, 0.0f}); positions(0)->push_back({0.0f, y, 0.0f});

4
src/Primitives/Cube.cpp

@ -15,7 +15,7 @@
#include "Cube.h" #include "Cube.h"
#include "Math/Vector4.h" #include "Math/Point3D.h"
using namespace std; using namespace std;
@ -34,7 +34,7 @@ Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector<unsigned int>{
2, 6, 7, 2, 6, 7,
4, 1, 5, 4, 1, 5,
4, 0, 1 4, 0, 1
}, {new vector<Vector4>}, {new vector<Vector3>{ }, {new vector<Point3D>}, {new vector<Vector3>{
{-1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f},
{ 1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, -1.0f},
{-1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f},

1
src/Primitives/Cylinder.cpp

@ -16,7 +16,6 @@
#include "Cylinder.h" #include "Cylinder.h"
#include "Math/Constants.h" #include "Math/Constants.h"
#include "Math/Vector4.h"
using namespace std; using namespace std;

2
src/Primitives/Icosphere.cpp

@ -42,7 +42,7 @@ Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vector<u
7, 1, 0, 7, 1, 0,
3, 9, 8, 3, 9, 8,
4, 8, 0 4, 8, 0
}, {new vector<Vector4>}, {new vector<Vector3>{ }, {new vector<Point3D>}, {new vector<Vector3>{
Vector3(0, -0.525731f, 0.850651f), Vector3(0, -0.525731f, 0.850651f),
Vector3(0.850651f, 0, 0.525731f), Vector3(0.850651f, 0, 0.525731f),
Vector3(0.850651f, 0, -0.525731f), Vector3(0.850651f, 0, -0.525731f),

4
src/Primitives/Plane.cpp

@ -15,13 +15,13 @@
#include "Plane.h" #include "Plane.h"
#include "Math/Vector4.h" #include "Math/Point3D.h"
using namespace std; using namespace std;
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector<Vector4>{ Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector<Point3D>{
{1.0f, -1.0f, 0.0f}, {1.0f, -1.0f, 0.0f},
{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f},
{-1.0f, -1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f},

6
src/Primitives/Test/CapsuleTest.cpp

@ -20,7 +20,7 @@
#include <TestSuite/Compare/Container.h> #include <TestSuite/Compare/Container.h>
#include "Math/Vector4.h" #include "Math/Point3D.h"
#include "Primitives/Capsule.h" #include "Primitives/Capsule.h"
using namespace std; using namespace std;
@ -38,7 +38,7 @@ CapsuleTest::CapsuleTest() {
void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withoutTextureCoords() {
Capsule capsule(2, 2, 3, 1.0f); Capsule capsule(2, 2, 3, 1.0f);
CORRADE_COMPARE_AS(*capsule.positions(0), (vector<Vector4>{ CORRADE_COMPARE_AS(*capsule.positions(0), (vector<Point3D>{
{0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 0.0f},
{0.0f, -1.20711f, 0.707107f}, {0.0f, -1.20711f, 0.707107f},
@ -103,7 +103,7 @@ void CapsuleTest::withoutTextureCoords() {
void CapsuleTest::withTextureCoords() { void CapsuleTest::withTextureCoords() {
Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate);
CORRADE_COMPARE_AS(*capsule.positions(0), (vector<Vector4>{ CORRADE_COMPARE_AS(*capsule.positions(0), (vector<Point3D>{
{0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 0.0f},
{0.0f, -1.20711f, 0.707107f}, {0.0f, -1.20711f, 0.707107f},

6
src/Primitives/Test/CylinderTest.cpp

@ -17,7 +17,7 @@
#include <TestSuite/Compare/Container.h> #include <TestSuite/Compare/Container.h>
#include "Math/Vector4.h" #include "Math/Point3D.h"
#include "Primitives/Cylinder.h" #include "Primitives/Cylinder.h"
using namespace std; using namespace std;
@ -35,7 +35,7 @@ CylinderTest::CylinderTest() {
void CylinderTest::withoutAnything() { void CylinderTest::withoutAnything() {
Cylinder cylinder(2, 3, 3.0f); Cylinder cylinder(2, 3, 3.0f);
CORRADE_COMPARE_AS(*cylinder.positions(0), (vector<Vector4>{ CORRADE_COMPARE_AS(*cylinder.positions(0), (vector<Point3D>{
{0.0f, -1.5f, 1.0f}, {0.0f, -1.5f, 1.0f},
{0.866025f, -1.5f, -0.5f}, {0.866025f, -1.5f, -0.5f},
{-0.866025f, -1.5f, -0.5f}, {-0.866025f, -1.5f, -0.5f},
@ -72,7 +72,7 @@ void CylinderTest::withoutAnything() {
void CylinderTest::withTextureCoordsAndCaps() { void CylinderTest::withTextureCoordsAndCaps() {
Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds); Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds);
CORRADE_COMPARE_AS(*cylinder.positions(0), (vector<Vector4>{ CORRADE_COMPARE_AS(*cylinder.positions(0), (vector<Point3D>{
{0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 0.0f},
{0.0f, -1.5f, 1.0f}, {0.0f, -1.5f, 1.0f},

6
src/Primitives/Test/UVSphereTest.cpp

@ -17,7 +17,7 @@
#include <TestSuite/Compare/Container.h> #include <TestSuite/Compare/Container.h>
#include "Math/Vector4.h" #include "Math/Point3D.h"
#include "Primitives/UVSphere.h" #include "Primitives/UVSphere.h"
using namespace std; using namespace std;
@ -35,7 +35,7 @@ UVSphereTest::UVSphereTest() {
void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withoutTextureCoords() {
UVSphere sphere(3, 3); UVSphere sphere(3, 3);
CORRADE_COMPARE_AS(*sphere.positions(0), (vector<Vector4>{ CORRADE_COMPARE_AS(*sphere.positions(0), (vector<Point3D>{
{0.0f, -1.0f, 0.0f}, {0.0f, -1.0f, 0.0f},
{0.0f, -0.5f, 0.866025f}, {0.0f, -0.5f, 0.866025f},
@ -73,7 +73,7 @@ void UVSphereTest::withoutTextureCoords() {
void UVSphereTest::withTextureCoords() { void UVSphereTest::withTextureCoords() {
UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate);
CORRADE_COMPARE_AS(*sphere.positions(0), (vector<Vector4>{ CORRADE_COMPARE_AS(*sphere.positions(0), (vector<Point3D>{
{0.0f, -1.0f, 0.0f}, {0.0f, -1.0f, 0.0f},
{0.0f, -0.5f, 0.866025f}, {0.0f, -0.5f, 0.866025f},

5
src/SceneGraph/Light.h

@ -19,6 +19,7 @@
* @brief Class Magnum::SceneGraph::Light * @brief Class Magnum::SceneGraph::Light
*/ */
#include "Math/Point3D.h"
#include "Object.h" #include "Object.h"
namespace Magnum { namespace SceneGraph { namespace Magnum { namespace SceneGraph {
@ -39,7 +40,7 @@ class SCENEGRAPH_EXPORT Light: public Object3D {
/** /**
* @brief Light position relative to root object (scene) * @brief Light position relative to root object (scene)
*/ */
inline Vector4 position() { inline Point3D position() {
setClean(); setClean();
return _position; return _position;
} }
@ -51,7 +52,7 @@ class SCENEGRAPH_EXPORT Light: public Object3D {
void clean(const Matrix4& absoluteTransformation); void clean(const Matrix4& absoluteTransformation);
private: private:
Vector4 _position; Point3D _position;
}; };
}} }}

2
src/Shaders/PhongShader.h

@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders {
*/ */
class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { class SHADERS_EXPORT PhongShader: public AbstractShaderProgram {
public: public:
typedef Attribute<0, Vector4> Position; /**< @brief Vertex position */ typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */
typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */
/** @brief Constructor */ /** @brief Constructor */

9
src/Trade/MeshData.h

@ -21,6 +21,7 @@
#include <string> #include <string>
#include "Math/Point3D.h"
#include "Mesh.h" #include "Mesh.h"
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
@ -50,7 +51,7 @@ class MAGNUM_EXPORT MeshData {
* @param textureCoords2D Array with two-dimensional texture * @param textureCoords2D Array with two-dimensional texture
* coordinate arrays or empty array * coordinate arrays or empty array
*/ */
inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector<unsigned int>* indices, std::vector<std::vector<Vector4>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector<unsigned int>* indices, std::vector<std::vector<Point3D>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {}
/** @brief Destructor */ /** @brief Destructor */
~MeshData(); ~MeshData();
@ -77,8 +78,8 @@ class MAGNUM_EXPORT MeshData {
* @return Positions or nullptr if there is no vertex array with given * @return Positions or nullptr if there is no vertex array with given
* ID. * ID.
*/ */
inline std::vector<Vector4>* positions(unsigned int id) { return _positions[id]; } inline std::vector<Point3D>* positions(unsigned int id) { return _positions[id]; }
inline const std::vector<Vector4>* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ inline const std::vector<Point3D>* positions(unsigned int id) const { return _positions[id]; } /**< @overload */
/** @brief Count of normal arrays */ /** @brief Count of normal arrays */
inline unsigned int normalArrayCount() const { return _normals.size(); } inline unsigned int normalArrayCount() const { return _normals.size(); }
@ -108,7 +109,7 @@ class MAGNUM_EXPORT MeshData {
std::string _name; std::string _name;
Mesh::Primitive _primitive; Mesh::Primitive _primitive;
std::vector<unsigned int>* _indices; std::vector<unsigned int>* _indices;
std::vector<std::vector<Vector4>*> _positions; std::vector<std::vector<Point3D>*> _positions;
std::vector<std::vector<Vector3>*> _normals; std::vector<std::vector<Vector3>*> _normals;
std::vector<std::vector<Vector2>*> _textureCoords2D; std::vector<std::vector<Vector2>*> _textureCoords2D;
}; };

2
src/TypeTraits.h

@ -242,6 +242,8 @@ template<class T, size_t vectorSize> struct TypeTraits<Math::Vector<vectorSize,
template<class T> struct TypeTraits<Math::Vector2<T>>: public TypeTraits<Math::Vector<2, T>> {}; template<class T> struct TypeTraits<Math::Vector2<T>>: public TypeTraits<Math::Vector<2, T>> {};
template<class T> struct TypeTraits<Math::Vector3<T>>: public TypeTraits<Math::Vector<3, T>> {}; template<class T> struct TypeTraits<Math::Vector3<T>>: public TypeTraits<Math::Vector<3, T>> {};
template<class T> struct TypeTraits<Math::Vector4<T>>: public TypeTraits<Math::Vector<4, T>> {}; template<class T> struct TypeTraits<Math::Vector4<T>>: public TypeTraits<Math::Vector<4, T>> {};
template<class T> struct TypeTraits<Math::Point2D<T>>: public TypeTraits<Math::Vector<3, T>> {};
template<class T> struct TypeTraits<Math::Point3D<T>>: public TypeTraits<Math::Vector<4, T>> {};
template<class T> struct TypeTraits<Color3<T>>: public TypeTraits<Math::Vector<3, T>> {}; template<class T> struct TypeTraits<Color3<T>>: public TypeTraits<Math::Vector<3, T>> {};
template<class T> struct TypeTraits<Color4<T>>: public TypeTraits<Math::Vector<4, T>> {}; template<class T> struct TypeTraits<Color4<T>>: public TypeTraits<Math::Vector<4, T>> {};

Loading…
Cancel
Save