diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 8078c9e6f..2d5b410b9 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -41,7 +41,7 @@ functions and properties: - %Attribute location typedefs defining locations and types for attribute binding with Mesh::bindAttribute(), for example: @code -typedef Attribute<0, Vector4> Position; +typedef Attribute<0, Point3D> Position; typedef Attribute<1, Vector3> Normal; typedef Attribute<2, Vector2> TextureCoords; @endcode diff --git a/src/Magnum.h b/src/Magnum.h index 49fe94f59..63bcc00c7 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -41,6 +41,8 @@ namespace Magnum { template class Vector2; template class Vector3; template class Vector4; + template class Point2D; + template class Point3D; template class Matrix3; template class Matrix4; @@ -62,6 +64,12 @@ typedef Math::Vector3 Vector3; /** @brief Four-component floating-point vector */ typedef Math::Vector4 Vector4; +/** @brief Two-dimensional floating-point homogeneous coordinates */ +typedef Math::Point2D Point2D; + +/** @brief Three-dimensional floating-point homogeneous coordinates */ +typedef Math::Point3D Point3D; + /** @brief 3x3 floating-point matrix */ typedef Math::Matrix3 Matrix3; diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index edcfe14ac..a92da34c4 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -7,6 +7,8 @@ set(MagnumMath_HEADERS Matrix.h Matrix3.h Matrix4.h + Point2D.h + Point3D.h RectangularMatrix.h Vector.h Vector2.h diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h new file mode 100644 index 000000000..953438d51 --- /dev/null +++ b/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š + + 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 Point2D: public Vector3 { + public: + /** + * @brief Default constructor + * + * X and Y components are set to zero, Z is set to one. + */ + inline constexpr Point2D(): Vector3(T(0), T(0), T(1)) {} + + /** @brief Copy constructor */ + inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3(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(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(xy, z) {} +}; + +/** @debugoperator{Magnum::Math::Point2D} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D& value) { + return debug << static_cast&>(value); +} + +}} + +namespace Corrade { namespace Utility { + /** @configurationvalue{Magnum::Math::Point2D} */ + template struct ConfigurationValue>: public ConfigurationValue> {}; +}} + +#endif diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h new file mode 100644 index 000000000..e92e1e7b1 --- /dev/null +++ b/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š + + 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 Point3D: public Vector4 { + public: + /** + * @brief Default constructor + * + * X, Y and Z components are set to zero, W is set to one. + */ + inline constexpr Point3D(): Vector4(T(0), T(0), T(0), T(1)) {} + + /** @brief Copy constructor */ + inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4(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(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(xyz, w) {} +}; + +/** @debugoperator{Magnum::Math::Point3D} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D& value) { + return debug << static_cast&>(value); +} + +}} + +namespace Corrade { namespace Utility { + /** @configurationvalue{Magnum::Math::Point3D} */ + template struct ConfigurationValue>: public ConfigurationValue> {}; +}} + +#endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 8f3690ea8..a62ecefca 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -10,6 +10,9 @@ corrade_add_test2(MathVector2Test Vector2Test.cpp) corrade_add_test2(MathVector3Test Vector3Test.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(MathMatrix3Test Matrix3Test.cpp) corrade_add_test2(MathMatrix4Test Matrix4Test.cpp) diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp new file mode 100644 index 000000000..64d5540bc --- /dev/null +++ b/src/Math/Test/Point2DTest.cpp @@ -0,0 +1,56 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + 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 + +#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 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::toString(vec), value); + CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); +} + +}}} diff --git a/src/Math/Test/Point2DTest.h b/src/Math/Test/Point2DTest.h new file mode 100644 index 000000000..39ec72d3b --- /dev/null +++ b/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š + + 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 + +namespace Magnum { namespace Math { namespace Test { + +class Point2DTest: public Corrade::TestSuite::Tester { + public: + Point2DTest(); + + void construct(); + void debug(); + void configuration(); +}; + +}}} + +#endif diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp new file mode 100644 index 000000000..092f5a0f0 --- /dev/null +++ b/src/Math/Test/Point3DTest.cpp @@ -0,0 +1,56 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + 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 + +#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 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::toString(vec), value); + CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); +} + +}}} diff --git a/src/Math/Test/Point3DTest.h b/src/Math/Test/Point3DTest.h new file mode 100644 index 000000000..9560e01d5 --- /dev/null +++ b/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š + + 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 + +namespace Magnum { namespace Math { namespace Test { + +class Point3DTest: public Corrade::TestSuite::Tester { + public: + Point3DTest(); + + void construct(); + void debug(); + void configuration(); +}; + +}}} + +#endif diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 710c60cd0..6ffdc267d 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -40,6 +40,7 @@ Vector3Test::Vector3Test() { } 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(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); } diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index b8765b65b..c12838a20 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -39,7 +39,7 @@ Vector4Test::Vector4Test() { } 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(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); } diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 990a6cba2..79a3a9075 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -27,7 +27,8 @@ namespace Magnum { namespace Math { @brief Three-component vector @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} */ template class Vector3: public Vector<3, T> { diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 2fc35f9de..0df339f24 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -27,16 +27,14 @@ namespace Magnum { namespace Math { @brief Four-component vector @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} */ template class Vector4: public Vector<4, T> { public: - /** - * @copydoc Vector::Vector - * W component is set to one. - */ - inline constexpr Vector4(): Vector<4, T>(T(0), T(0), T(0), T(1)) {} + /** @copydoc Vector::Vector() */ + inline constexpr Vector4() {} /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {} @@ -51,16 +49,14 @@ template class Vector4: public Vector<4, T> { * @param z Z 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 * @param xyz Three-component vector * @param w W component */ - /* Not marked as explicit, because conversion from Vector3 to Vector4 - 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 constexpr Vector4(const Vector<3, T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 6f4f8f699..25a8cca4e 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/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: @code std::vector vertexIndices; -std::vector positions; +std::vector positions; std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 50866eb18..5d4868a3b 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -15,14 +15,14 @@ #include "GenerateFlatNormals.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "MeshTools/Clean.h" using namespace std; namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { +tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index 48f289e19..bdbcca05a 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -38,7 +38,7 @@ For each face generates one normal vector, removes duplicates before returning. Example usage: @code std::vector vertexIndices; -std::vector positions; +std::vector positions; std::vector normalIndices; std::vector normals; @@ -50,7 +50,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 8cf127a46..1de255976 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "MeshTools/GenerateFlatNormals.h" CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index b0ef33339..30ad3551b 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -16,11 +16,12 @@ #include "AxisAlignedBox.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Physics { void AxisAlignedBox::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); _transformedSize = transformation.rotationScaling()*_size; } diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 3f7936901..b6d175f7d 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -18,6 +18,7 @@ #include "Math/Constants.h" #include "Math/Math.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" #include "Math/Geometry/Distance.h" #include "Point.h" #include "Sphere.h" @@ -27,8 +28,8 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Capsule::applyTransformation(const Matrix4& transformation) { - _transformedA = (transformation*Vector4(_a)).xyz(); - _transformedB = (transformation*Vector4(_b)).xyz(); + _transformedA = (transformation*Point3D(_a)).xyz(); + _transformedB = (transformation*Point3D(_b)).xyz(); float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 010cf5c37..3dec9a602 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -16,12 +16,13 @@ #include "Line.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Physics { void Line::applyTransformation(const Matrix4& transformation) { - _transformedA = (transformation*Vector4(_a)).xyz(); - _transformedB = (transformation*Vector4(_b)).xyz(); + _transformedA = (transformation*Point3D(_a)).xyz(); + _transformedB = (transformation*Point3D(_b)).xyz(); } }} diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 5ca9d49c3..124b28ccf 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -18,6 +18,7 @@ #include #include "Math/Matrix4.h" +#include "Math/Point3D.h" #include "Math/Geometry/Intersection.h" #include "LineSegment.h" @@ -27,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Plane::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); _transformedNormal = transformation.rotation()*_normal; } diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index eef45829f..6ec43579b 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -16,11 +16,12 @@ #include "Point.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Physics { void Point::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); } }} diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 54a656168..f3b0579b1 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -18,6 +18,7 @@ #include "Math/Constants.h" #include "Math/Math.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" #include "Math/Geometry/Distance.h" #include "LineSegment.h" #include "Point.h" @@ -27,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Sphere::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 11fa8f9f0..c65c87d36 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -16,13 +16,13 @@ #include "Capsule.h" #include "Math/Constants.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" using namespace std; 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, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), 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, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), 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", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index c524fb77e..ec1917c5f 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -15,7 +15,7 @@ #include "Cube.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" using namespace std; @@ -34,7 +34,7 @@ Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector{ 2, 6, 7, 4, 1, 5, 4, 0, 1 -}, {new vector}, {new vector{ +}, {new vector}, {new vector{ {-1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 30a031538..709c7dfb9 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -16,7 +16,6 @@ #include "Cylinder.h" #include "Math/Constants.h" -#include "Math/Vector4.h" using namespace std; diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 436937906..100858b8f 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -42,7 +42,7 @@ Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vector}, {new vector{ +}, {new vector}, {new vector{ Vector3(0, -0.525731f, 0.850651f), Vector3(0.850651f, 0, 0.525731f), Vector3(0.850651f, 0, -0.525731f), diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 6db0eec5c..74d9a2054 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -15,13 +15,13 @@ #include "Plane.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" using namespace std; namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ +Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 45e16738f..7d95515c3 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -20,7 +20,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "Primitives/Capsule.h" using namespace std; @@ -38,7 +38,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 2, 3, 1.0f); - CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, @@ -103,7 +103,7 @@ void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withTextureCoords() { Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); - CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 43efb5845..cb94fa6d7 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "Primitives/Cylinder.h" using namespace std; @@ -35,7 +35,7 @@ CylinderTest::CylinderTest() { void CylinderTest::withoutAnything() { Cylinder cylinder(2, 3, 3.0f); - CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ {0.0f, -1.5f, 1.0f}, {0.866025f, -1.5f, -0.5f}, {-0.866025f, -1.5f, -0.5f}, @@ -72,7 +72,7 @@ void CylinderTest::withoutAnything() { void CylinderTest::withTextureCoordsAndCaps() { Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds); - CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 1.0f}, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 269c52419..cff3f77b9 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "Primitives/UVSphere.h" using namespace std; @@ -35,7 +35,7 @@ UVSphereTest::UVSphereTest() { void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); - CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, @@ -73,7 +73,7 @@ void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); - CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, diff --git a/src/SceneGraph/Light.h b/src/SceneGraph/Light.h index 3e604f584..74070122c 100644 --- a/src/SceneGraph/Light.h +++ b/src/SceneGraph/Light.h @@ -19,6 +19,7 @@ * @brief Class Magnum::SceneGraph::Light */ +#include "Math/Point3D.h" #include "Object.h" namespace Magnum { namespace SceneGraph { @@ -39,7 +40,7 @@ class SCENEGRAPH_EXPORT Light: public Object3D { /** * @brief Light position relative to root object (scene) */ - inline Vector4 position() { + inline Point3D position() { setClean(); return _position; } @@ -51,7 +52,7 @@ class SCENEGRAPH_EXPORT Light: public Object3D { void clean(const Matrix4& absoluteTransformation); private: - Vector4 _position; + Point3D _position; }; }} diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index a27b5d047..a6dd5c6dc 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders { */ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { 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 */ /** @brief Constructor */ diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData.h index daf4f3cfa..d3b19bb2e 100644 --- a/src/Trade/MeshData.h +++ b/src/Trade/MeshData.h @@ -21,6 +21,7 @@ #include +#include "Math/Point3D.h" #include "Mesh.h" namespace Magnum { namespace Trade { @@ -50,7 +51,7 @@ class MAGNUM_EXPORT MeshData { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData(); @@ -77,8 +78,8 @@ class MAGNUM_EXPORT MeshData { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(unsigned int id) { return _positions[id]; } - inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(unsigned int id) { return _positions[id]; } + inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ /** @brief Count of normal arrays */ inline unsigned int normalArrayCount() const { return _normals.size(); } @@ -108,7 +109,7 @@ class MAGNUM_EXPORT MeshData { std::string _name; Mesh::Primitive _primitive; std::vector* _indices; - std::vector*> _positions; + std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D; }; diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 00d590078..5b15c9832 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -242,6 +242,8 @@ template struct TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {};