Browse Source

Convenience functions for accessing Matrix[34] vectors.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
6dda7e4c1f
  1. 32
      src/Math/Matrix3.h
  2. 42
      src/Math/Matrix4.h
  3. 14
      src/Math/Test/Matrix3Test.cpp
  4. 2
      src/Math/Test/Matrix3Test.h
  5. 17
      src/Math/Test/Matrix4Test.cpp
  6. 2
      src/Math/Test/Matrix4Test.h
  7. 4
      src/Math/Vector2.h
  8. 6
      src/Math/Vector3.h

32
src/Math/Matrix3.h

@ -127,21 +127,31 @@ template<class T> class Matrix3: public Matrix<3, T> {
}
/**
* @brief 2D translation part of the matrix
* @brief Right-pointing 2D vector
*
* First two elements of last column.
* @see translation(const Vector2&), Matrix4::translation()
* First two elements of first column.
* @see Vector2::xAxis()
*/
inline Vector2<T>& translation() {
return (*this)[2].xy();
}
inline Vector2<T>& right() { return (*this)[0].xy(); }
inline constexpr Vector2<T> right() const { return (*this)[0].xy(); } /**< @overload */
/** @overload */
inline constexpr Vector2<T> translation() const {
return (*this)[2].xy();
}
/**
* @brief Up-pointing 2D vector
*
* First two elements of second column.
* @see Vector2::yAxis()
*/
inline Vector2<T>& up() { return (*this)[1].xy(); }
inline constexpr Vector2<T> up() const { return (*this)[1].xy(); } /**< @overload */
/** @todo up(), right() */
/**
* @brief 2D translation part of the matrix
*
* First two elements of third column.
* @see translation(const Vector2&), Matrix4::translation()
*/
inline Vector2<T>& translation() { return (*this)[2].xy(); }
inline constexpr Vector2<T> translation() const { return (*this)[2].xy(); } /**< @overload */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Point2D<T> operator*(const Point2D<T>& other) const {

42
src/Math/Matrix4.h

@ -223,22 +223,42 @@ template<class T> class Matrix4: public Matrix<4, T> {
(*this)[2].xyz().normalized());
}
/**
* @brief 3D translation part of the matrix
* @brief Right-pointing 3D vector
*
* First three elements of last column.
* @see translation(const Vector3&), Matrix3::translation()
* First three elements of first column.
* @see Vector3::xAxis()
*/
inline Vector3<T>& translation() {
return (*this)[3].xyz();
}
inline Vector3<T>& right() { return (*this)[0].xyz(); }
inline constexpr Vector3<T> right() const { return (*this)[0].xyz(); } /**< @overload */
/** @overload */
inline constexpr Vector3<T> translation() const {
return (*this)[3].xyz();
}
/**
* @brief Up-pointing 3D vector
*
* First three elements of second column.
* @see Vector3::yAxis()
*/
inline Vector3<T>& up() { return (*this)[1].xyz(); }
inline constexpr Vector3<T> up() const { return (*this)[1].xyz(); } /**< @overload */
/** @todo up(), forward(), right() */
/**
* @brief Backward-pointing 3D vector
*
* First three elements of third column.
* @see Vector3::yAxis()
*/
inline Vector3<T>& backward() { return (*this)[2].xyz(); }
inline constexpr Vector3<T> backward() const { return (*this)[2].xyz(); } /**< @overload */
/**
* @brief 3D translation part of the matrix
*
* First three elements of fourth column.
* @see translation(const Vector3&), Matrix3::translation()
*/
inline Vector3<T>& translation() { return (*this)[3].xyz(); }
inline constexpr Vector3<T> translation() const { return (*this)[3].xyz(); } /**< @overload */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Point3D<T> operator*(const Point3D<T>& other) const {

14
src/Math/Test/Matrix3Test.cpp

@ -38,7 +38,7 @@ Matrix3Test::Matrix3Test() {
&Matrix3Test::rotation,
&Matrix3Test::rotationScalingPart,
&Matrix3Test::rotationPart,
&Matrix3Test::translationPart,
&Matrix3Test::vectorParts,
&Matrix3Test::debug,
&Matrix3Test::configuration);
}
@ -123,12 +123,14 @@ void Matrix3Test::rotationPart() {
CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart);
}
void Matrix3Test::translationPart() {
Matrix3 m(1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
void Matrix3Test::vectorParts() {
Matrix3 m(15.0f, 0.0f, 0.0f,
0.0f, -3.0f, 0.0f,
-5.0f, 12.0f, 1.0f);
Vector2 expected(-5.0f, 12.0f);
CORRADE_COMPARE(m.translation(), expected);
CORRADE_COMPARE(m.right(), Vector2::xAxis(15.0f));
CORRADE_COMPARE(m.up(), Vector2::yAxis(-3.0f));
CORRADE_COMPARE(m.translation(), Vector2(-5.0f, 12.0f));
}
void Matrix3Test::debug() {

2
src/Math/Test/Matrix3Test.h

@ -30,7 +30,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester<Matrix3Test> {
void rotation();
void rotationScalingPart();
void rotationPart();
void translationPart();
void vectorParts();
void debug();
void configuration();

17
src/Math/Test/Matrix4Test.cpp

@ -41,7 +41,7 @@ Matrix4Test::Matrix4Test() {
&Matrix4Test::rotationZ,
&Matrix4Test::rotationScalingPart,
&Matrix4Test::rotationPart,
&Matrix4Test::translationPart,
&Matrix4Test::vectorParts,
&Matrix4Test::debug,
&Matrix4Test::configuration);
}
@ -166,13 +166,16 @@ void Matrix4Test::rotationPart() {
CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart);
}
void Matrix4Test::translationPart() {
Matrix4 m(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
void Matrix4Test::vectorParts() {
Matrix4 m(-1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 12.0f, 0.0f, 0.0f,
0.0f, 0.0f, 35.0f, 0.0f,
-5.0f, 12.0f, 0.5f, 1.0f);
Vector3 expected(-5.0f, 12.0f, 0.5f);
CORRADE_COMPARE(m.translation(), expected);
CORRADE_COMPARE(m.right(), Vector3::xAxis(-1.0f));
CORRADE_COMPARE(m.up(), Vector3::yAxis(12.0f));
CORRADE_COMPARE(m.backward(), Vector3::zAxis(35.0f));
CORRADE_COMPARE(m.translation(), Vector3(-5.0f, 12.0f, 0.5f));
}
void Matrix4Test::debug() {

2
src/Math/Test/Matrix4Test.h

@ -33,7 +33,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester<Matrix4Test> {
void rotationZ();
void rotationScalingPart();
void rotationPart();
void translationPart();
void vectorParts();
void debug();
void configuration();

4
src/Math/Vector2.h

@ -39,7 +39,7 @@ template<class T> class Vector2: public Vector<2, T> {
* @code
* Matrix3::translation(Vector2::xAxis(5.0f)); // same as Matrix3::translation({5.0f, 0.0f});
* @endcode
* @see yAxis(), xScale()
* @see yAxis(), xScale(), Matrix3::right()
*/
inline constexpr static Vector2<T> xAxis(T length = T(1)) { return Vector2<T>(length, T()); }
@ -47,7 +47,7 @@ template<class T> class Vector2: public Vector<2, T> {
* @brief %Vector in direction of Y axis (up)
*
* See xAxis() for more information.
* @see yScale()
* @see yScale(), Matrix3::up()
*/
inline constexpr static Vector2<T> yAxis(T length = T(1)) { return Vector2<T>(T(), length); }

6
src/Math/Vector3.h

@ -41,7 +41,7 @@ template<class T> class Vector3: public Vector<3, T> {
* Matrix4::translation(Vector3::xAxis(5.0f)); // same as Matrix4::translation({5.0f, 0.0f, 0.0f});
* Matrix4::rotation(deg(30.0f), Vector3::xAxis()); // same as Matrix::rotation(deg(30.0f), {1.0f, 0.0f, 0.0f});
* @endcode
* @see yAxis(), zAxis(), xScale()
* @see yAxis(), zAxis(), xScale(), Matrix4::right()
*/
inline constexpr static Vector3<T> xAxis(T length = T(1)) { return Vector3<T>(length, T(), T()); }
@ -49,7 +49,7 @@ template<class T> class Vector3: public Vector<3, T> {
* @brief %Vector in direction of Y axis (up)
*
* See xAxis() for more information.
* @see yScale()
* @see yScale(), Matrix4::up()
*/
inline constexpr static Vector3<T> yAxis(T length = T(1)) { return Vector3<T>(T(), length, T()); }
@ -57,7 +57,7 @@ template<class T> class Vector3: public Vector<3, T> {
* @brief %Vector in direction of Z axis (backward)
*
* See xAxis() for more information.
* @see zScale()
* @see zScale(), Matrix4::backward()
*/
inline constexpr static Vector3<T> zAxis(T length = T(1)) { return Vector3<T>(T(), T(), length); }

Loading…
Cancel
Save