Browse Source

Matrix4 code cleanup

* Don't assume the values are float, use T(0) instead of 0.0f.
 * Explicitly specify templated type.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
6ae92d5056
  1. 34
      src/Math/Matrix4.h

34
src/Math/Matrix4.h

@ -37,11 +37,11 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @param vec Translation vector
*/
inline constexpr static Matrix4<T> translation(const Vector3<T>& vec) {
return Matrix4( /* Column-major! */
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
vec.x(), vec.y(), vec.z(), 1.0f
return Matrix4<T>( /* Column-major! */
T(1), T(0), T(0), T(0),
T(0), T(1), T(0), T(0),
T(0), T(0), T(1), T(0),
vec.x(), vec.y(), vec.z(), T(1)
);
}
@ -49,12 +49,12 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @brief Scaling matrix
* @param vec Scaling vector
*/
inline constexpr static Matrix4 scaling(const Vector3<T>& vec) {
return Matrix4( /* Column-major! */
vec.x(), 0.0f, 0.0f, 0.0f,
0.0f, vec.y(), 0.0f, 0.0f,
0.0f, 0.0f, vec.z(), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
inline constexpr static Matrix4<T> scaling(const Vector3<T>& vec) {
return Matrix4<T>( /* Column-major! */
vec.x(), T(0), T(0), T(0),
T(0), vec.y(), T(0), T(0),
T(0), T(0), vec.z(), T(0),
T(0), T(0), T(0), T(1)
);
}
@ -63,7 +63,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @param angle Rotation angle (counterclockwise, in radians)
* @param vec Rotation vector
*/
static Matrix4 rotation(T angle, const Vector3<T>& vec) {
static Matrix4<T> rotation(T angle, const Vector3<T>& vec) {
Vector3<T> vn = vec.normalized();
T sine = sin(angle);
@ -77,7 +77,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
T yz = vn.y()*vn.z();
T zz = vn.z()*vn.z();
return Matrix4( /* Column-major! */
return Matrix4<T>( /* Column-major! */
cosine + xx*oneMinusCosine,
xy*oneMinusCosine + vn.z()*sine,
xz*oneMinusCosine - vn.y()*sine,
@ -99,10 +99,10 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** @copydoc Matrix::Matrix(IdentityType, T) */
inline constexpr explicit Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>(
value, 0.0f, 0.0f, 0.0f,
0.0f, value, 0.0f, 0.0f,
0.0f, 0.0f, value, 0.0f,
0.0f, 0.0f, 0.0f, value
value, T(0), T(0), T(0),
T(0), value, T(0), T(0),
T(0), T(0), value, T(0),
T(0), T(0), T(0), value
) {}
/** @copydoc Matrix::Matrix(T, U...) */

Loading…
Cancel
Save