Browse Source

Documented convenience functions on vectors and angles.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
d96cb96d60
  1. 16
      src/Math/Math.h
  2. 4
      src/Math/Matrix3.h
  3. 4
      src/Math/Matrix4.h
  4. 16
      src/Math/Vector2.h
  5. 23
      src/Math/Vector3.h

16
src/Math/Math.h

@ -130,17 +130,23 @@ template<class Integral, class FloatingPoint> inline constexpr typename std::ena
} }
/** /**
* @brief Angle in degrees @brief Angle in degrees
*
* Function to make angle entering less error-prone. Converts the value to Function to make angle entering less error-prone. Converts the value to
* radians at compile time. For example `deg(180.0f)` is converted to `3.14f`. radians at compile time. For example `deg(180.0f)` is converted to `3.14f`.
Usable for entering e.g. rotation:
@code
Matrix4::rotation(deg(30.0f), Vector3::yAxis());
@endcode
@see rad()
*/ */
template<class T> inline constexpr T deg(T value) { return value*Constants<T>::pi()/180; } template<class T> inline constexpr T deg(T value) { return value*Constants<T>::pi()/180; }
/** /**
* @brief Angle in radians * @brief Angle in radians
* *
* See also deg(). * See deg() for more information.
*/ */
template<class T> inline constexpr T rad(T value) { return value; } template<class T> inline constexpr T rad(T value) { return value; }

4
src/Math/Matrix3.h

@ -36,7 +36,7 @@ template<class T> class Matrix3: public Matrix<3, T> {
* @brief 2D translation matrix * @brief 2D translation matrix
* @param vec Translation vector * @param vec Translation vector
* *
* @see Matrix4::translation() * @see Matrix4::translation(), Vector2::xAxis(), Vector2::yAxis()
*/ */
inline constexpr static Matrix3<T> translation(const Vector2<T>& vec) { inline constexpr static Matrix3<T> translation(const Vector2<T>& vec) {
return Matrix3<T>( /* Column-major! */ return Matrix3<T>( /* Column-major! */
@ -64,7 +64,7 @@ template<class T> class Matrix3: public Matrix<3, T> {
* @brief 3D rotation matrix * @brief 3D rotation matrix
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise, in radians)
* *
* @see Matrix4::rotation() * @see Matrix4::rotation(), deg(), rad()
*/ */
static Matrix3<T> rotation(T angle) { static Matrix3<T> rotation(T angle) {
return Matrix3<T>( /* Column-major! */ return Matrix3<T>( /* Column-major! */

4
src/Math/Matrix4.h

@ -38,7 +38,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @brief 3D translation matrix * @brief 3D translation matrix
* @param vec Translation vector * @param vec Translation vector
* *
* @see Matrix3::translation() * @see Matrix3::translation(), Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis()
*/ */
inline constexpr static Matrix4<T> translation(const Vector3<T>& vec) { inline constexpr static Matrix4<T> translation(const Vector3<T>& vec) {
return Matrix4<T>( /* Column-major! */ return Matrix4<T>( /* Column-major! */
@ -69,7 +69,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise, in radians)
* @param vec Rotation vector * @param vec Rotation vector
* *
* @see Matrix3::rotation() * @see Matrix3::rotation(), Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), deg(), rad()
* @todo optimize - Assume the vectors are normalized? * @todo optimize - Assume the vectors are normalized?
*/ */
static Matrix4<T> rotation(T angle, const Vector3<T>& vec) { static Matrix4<T> rotation(T angle, const Vector3<T>& vec) {

16
src/Math/Vector2.h

@ -26,10 +26,22 @@ namespace Magnum { namespace Math {
/** @brief Two-component vector */ /** @brief Two-component vector */
template<class T> class Vector2: public Vector<2, T> { template<class T> class Vector2: public Vector<2, T> {
public: public:
/** @brief %Vector in direction of X axis */ /**
* @brief %Vector in direction of X axis
*
* Usable for translation in given axis, for example:
* @code
* Matrix3::translation(Vector2::xAxis(5.0f)); // same as Matrix3::translation({5.0f, 0.0f});
* @endcode
* @see yAxis()
*/
inline constexpr static Vector2<T> xAxis(T length = T(1)) { return Vector2<T>(length, T()); } inline constexpr static Vector2<T> xAxis(T length = T(1)) { return Vector2<T>(length, T()); }
/** @brief %Vector in direction of Y axis */ /**
* @brief %Vector in direction of Y axis
*
* See xAxis() for more information.
*/
inline constexpr static Vector2<T> yAxis(T length = T(1)) { return Vector2<T>(T(), length); } inline constexpr static Vector2<T> yAxis(T length = T(1)) { return Vector2<T>(T(), length); }
/** @copydoc Vector::Vector(T) */ /** @copydoc Vector::Vector(T) */

23
src/Math/Vector3.h

@ -26,13 +26,30 @@ namespace Magnum { namespace Math {
/** @brief Three-component vector */ /** @brief Three-component vector */
template<class T> class Vector3: public Vector<3, T> { template<class T> class Vector3: public Vector<3, T> {
public: public:
/** @brief %Vector in direction of X axis */ /**
* @brief %Vector in direction of X axis
*
* Usable for translation or rotation along given axis, for example:
* @code
* 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()
*/
inline constexpr static Vector3<T> xAxis(T length = T(1)) { return Vector3<T>(length, T(), T()); } inline constexpr static Vector3<T> xAxis(T length = T(1)) { return Vector3<T>(length, T(), T()); }
/** @brief %Vector in direction of Y axis */ /**
* @brief %Vector in direction of Y axis
*
* See xAxis() for more information.
*/
inline constexpr static Vector3<T> yAxis(T length = T(1)) { return Vector3<T>(T(), length, T()); } inline constexpr static Vector3<T> yAxis(T length = T(1)) { return Vector3<T>(T(), length, T()); }
/** @brief %Vector in direction of Z axis */ /**
* @brief %Vector in direction of Z axis
*
* See xAxis() for more information.
*/
inline constexpr static Vector3<T> zAxis(T length = T(1)) { return Vector3<T>(T(), T(), length); } inline constexpr static Vector3<T> zAxis(T length = T(1)) { return Vector3<T>(T(), T(), length); }
/** /**

Loading…
Cancel
Save