Fixed non-squared products

This commit is contained in:
Christophe Riccio 2010-08-24 14:00:09 +01:00
parent 1a891b9efb
commit 4a599e1b93
7 changed files with 104 additions and 52 deletions

View File

@ -3,5 +3,61 @@
int main() int main()
{ {
//glm::mat2x3 m1(1.0f);
//glm::vec3 v1(1.0f);
//glm::vec2 w1 = m1 * v1;
{
glm::mat2x3 m(1.0f);
glm::vec2 u(1.0f);
glm::vec3 v(1.0f);
glm::vec3 a = m * u;
glm::vec2 b = v * m;
}
{
glm::mat2x4 m(1.0f);
glm::vec2 u(1.0f);
glm::vec4 v(1.0f);
glm::vec4 a = m * u;
glm::vec2 b = v * m;
}
{
glm::mat3x2 m(1.0f);
glm::vec3 u(1.0f);
glm::vec2 v(1.0f);
glm::vec2 a = m * u;
glm::vec3 b = v * m;
}
{
glm::mat3x4 m(1.0f);
glm::vec3 u(1.0f);
glm::vec4 v(1.0f);
glm::vec4 a = m * u;
glm::vec3 b = v * m;
}
{
glm::mat4x2 m(1.0f);
glm::vec4 u(1.0f);
glm::vec2 v(1.0f);
glm::vec2 a = m * u;
glm::vec4 b = v * m;
}
{
glm::mat4x3 m(1.0f);
glm::vec4 u(1.0f);
glm::vec3 v(1.0f);
glm::vec3 a = m * u;
glm::vec4 b = v * m;
}
//{
// glm::mat3x4 m(1.0f);
// glm::vec3 v(1.0f);
// glm::vec4 w = m * v;
//}
} }

View File

@ -398,29 +398,26 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat2x3<T>::row_type operator* inline typename tmat2x3<T>::col_type operator*
( (
tmat2x3<T> const & m, tmat2x3<T> const & m,
typename tmat2x3<T>::col_type const & v typename tmat2x3<T>::row_type const & v)
)
{ {
return detail::tvec3<T>( return typename tmat2x3<T>::col_type(
m[0][0] * v.x + m[1][0] * v.y, m[0][0] * v.x + m[1][0] * v.y,
m[0][1] * v.x + m[1][1] * v.y, m[0][1] * v.x + m[1][1] * v.y,
m[0][2] * v.x + m[1][2] * v.y, m[0][2] * v.x + m[1][2] * v.y);
m[0][3] * v.x + m[1][3] * v.y);
} }
template <typename T> template <typename T>
inline typename tmat2x3<T>::col_type operator* inline typename tmat2x3<T>::row_type operator*
( (
typename tmat2x3<T>::row_type const & v, typename tmat2x3<T>::col_type const & v,
tmat2x3<T> const & m tmat2x3<T> const & m)
)
{ {
return detail::tvec2<T>( return typename tmat2x3<T>::row_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w, v.x * m[0][0] + v.y * m[0][1] + v.z * m[0][2],
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w); v.x * m[1][0] + v.y * m[1][1] + v.z * m[1][2]);
} }
template <typename T> template <typename T>

View File

@ -401,13 +401,13 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat2x4<T>::row_type operator* inline typename tmat2x4<T>::col_type operator*
( (
tmat2x4<T> const & m, tmat2x4<T> const & m,
typename tmat2x4<T>::col_type const & v typename tmat2x4<T>::row_type const & v
) )
{ {
return typename tmat2x4<T>::row_type( return typename tmat2x4<T>::col_type(
m[0][0] * v.x + m[1][0] * v.y, m[0][0] * v.x + m[1][0] * v.y,
m[0][1] * v.x + m[1][1] * v.y, m[0][1] * v.x + m[1][1] * v.y,
m[0][2] * v.x + m[1][2] * v.y, m[0][2] * v.x + m[1][2] * v.y,
@ -415,13 +415,13 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat2x4<T>::col_type operator* inline typename tmat2x4<T>::row_type operator*
( (
typename tmat2x4<T>::row_type const & v, typename tmat2x4<T>::col_type const & v,
tmat2x4<T> const & m tmat2x4<T> const & m
) )
{ {
return typename tmat2x4<T>::col_type( return typename tmat2x4<T>::row_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w, m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w,
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w); m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w);
} }

View File

@ -412,27 +412,26 @@ namespace detail
} }
template <typename T> template <typename T>
inline detail::tvec2<T> operator* inline typename tmat3x2<T>::col_type operator*
( (
tmat3x2<T> const & m, tmat3x2<T> const & m,
detail::tvec3<T> const & v typename tmat3x2<T>::row_type const & v)
)
{ {
return detail::tvec2<T>( return typename tmat3x2<T>::col_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z, m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z,
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z); m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z);
} }
template <typename T> template <typename T>
inline detail::tvec3<T> operator* inline typename tmat3x2<T>::row_type operator*
( (
detail::tvec2<T> const & v, typename tmat3x2<T>::col_type const & v,
tmat3x2<T> const & m tmat3x2<T> const & m)
)
{ {
return detail::tvec3<T>( return typename tmat3x2<T>::row_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w, v.x * m[0][0] + v.y * m[0][1],
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w); v.x * m[1][0] + v.y * m[1][1],
v.x * m[2][0] + v.y * m[2][1]);
} }
template <typename T> template <typename T>

View File

@ -433,13 +433,13 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat3x4<T>::row_type operator* inline typename tmat3x4<T>::col_type operator*
( (
tmat3x4<T> const & m, tmat3x4<T> const & m,
typename tmat3x4<T>::col_type const & v typename tmat3x4<T>::row_type const & v
) )
{ {
return typename tmat3x4<T>::row_type( return typename tmat3x4<T>::col_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z, m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z,
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z, m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z,
m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z, m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z,
@ -447,13 +447,13 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat3x4<T>::col_type operator* inline typename tmat3x4<T>::row_type operator*
( (
typename tmat3x4<T>::row_type const & v, typename tmat3x4<T>::col_type const & v,
tmat3x4<T> const & m tmat3x4<T> const & m
) )
{ {
return typename tmat3x4<T>::col_type( return typename tmat3x4<T>::row_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w, m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w,
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w, m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w,
m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2] * v.w); m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2] * v.w);

View File

@ -465,13 +465,12 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat4x2<T>::row_type operator* inline typename tmat4x2<T>::col_type operator*
( (
tmat4x2<T> const & m, tmat4x2<T> const & m,
typename tmat4x2<T>::col_type const & v typename tmat4x2<T>::row_type const & v)
)
{ {
return typename tmat4x2<T>::row_type( return typename tmat4x2<T>::col_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w, m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w,
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w); m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w);
} }
@ -479,9 +478,8 @@ namespace detail
template <typename T> template <typename T>
inline typename tmat4x2<T>::row_type operator* inline typename tmat4x2<T>::row_type operator*
( (
typename tmat4x2<T>::row_type const & v, typename tmat4x2<T>::col_type const & v,
tmat4x2<T> const & m tmat4x2<T> const & m)
)
{ {
return typename tmat4x2<T>::row_type( return typename tmat4x2<T>::row_type(
v.x * m[0][0] + v.y * m[0][1], v.x * m[0][0] + v.y * m[0][1],

View File

@ -455,22 +455,24 @@ namespace detail
} }
template <typename T> template <typename T>
inline typename tmat4x3<T>::row_type operator* ( inline typename tmat4x3<T>::col_type operator*
(
tmat4x3<T> const & m, tmat4x3<T> const & m,
typename tmat4x3<T>::col_type const & v) typename tmat4x3<T>::row_type const & v)
{ {
return row_type( return typename tmat4x3<T>::col_type(
m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w, m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w,
m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w, m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w,
m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2] * v.w); m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2] * v.w);
} }
template <typename T> template <typename T>
inline typename tmat4x3<T>::col_type operator* ( inline typename tmat4x3<T>::row_type operator*
typename tmat4x3<T>::row_type const & v, (
typename tmat4x3<T>::col_type const & v,
tmat4x3<T> const & m) tmat4x3<T> const & m)
{ {
return col_type( return typename tmat4x3<T>::row_type(
v.x * m[0][0] + v.y * m[0][1] + v.z * m[0][2], v.x * m[0][0] + v.y * m[0][1] + v.z * m[0][2],
v.x * m[1][0] + v.y * m[1][1] + v.z * m[1][2], v.x * m[1][0] + v.y * m[1][1] + v.z * m[1][2],
v.x * m[2][0] + v.y * m[2][1] + v.z * m[2][2], v.x * m[2][0] + v.y * m[2][1] + v.z * m[2][2],