parent
8693d06297
commit
561fbbd94c
9 changed files with 474 additions and 70 deletions
@ -0,0 +1,91 @@ |
||||
/// @ref ext_matrix_integer
|
||||
/// @file glm/ext/matrix_integer.hpp
|
||||
///
|
||||
/// @defgroup ext_matrix_integer GLM_EXT_matrix_integer
|
||||
/// @ingroup ext
|
||||
///
|
||||
/// Defines functions that generate common transformation matrices.
|
||||
///
|
||||
/// The matrices generated by this extension use standard OpenGL fixed-function
|
||||
/// conventions. For example, the lookAt function generates a transform from world
|
||||
/// space into the specific eye space that the projective matrix functions
|
||||
/// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility
|
||||
/// specifications defines the particular layout of this eye space.
|
||||
///
|
||||
/// Include <glm/ext/matrix_integer.hpp> to use the features of this extension.
|
||||
///
|
||||
/// @see ext_matrix_projection
|
||||
/// @see ext_matrix_clip_space
|
||||
|
||||
#pragma once |
||||
|
||||
// Dependencies
|
||||
#include "../gtc/constants.hpp" |
||||
#include "../geometric.hpp" |
||||
#include "../trigonometric.hpp" |
||||
#include "../matrix.hpp" |
||||
|
||||
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) |
||||
# pragma message("GLM: GLM_EXT_matrix_integer extension included") |
||||
#endif |
||||
|
||||
namespace glm |
||||
{ |
||||
/// @addtogroup ext_matrix_integer
|
||||
/// @{
|
||||
|
||||
/// Multiply matrix x by matrix y component-wise, i.e.,
|
||||
/// result[i][j] is the scalar product of x[i][j] and y[i][j].
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number a column
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number a row
|
||||
/// @tparam T Floating-point or signed integer scalar types
|
||||
/// @tparam Q Value from qualifier enum
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/matrixCompMult.xml">GLSL matrixCompMult man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template<length_t C, length_t R, typename T, qualifier Q> |
||||
GLM_FUNC_DECL mat<C, R, T, Q> matrixCompMult(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y); |
||||
|
||||
/// Treats the first parameter c as a column vector
|
||||
/// and the second parameter r as a row vector
|
||||
/// and does a linear algebraic matrix multiply c * r.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number a column
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number a row
|
||||
/// @tparam T Floating-point or signed integer scalar types
|
||||
/// @tparam Q Value from qualifier enum
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/outerProduct.xml">GLSL outerProduct man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template<length_t C, length_t R, typename T, qualifier Q> |
||||
GLM_FUNC_DECL typename detail::outerProduct_trait<C, R, T, Q>::type outerProduct(vec<C, T, Q> const& c, vec<R, T, Q> const& r); |
||||
|
||||
/// Returns the transposed matrix of x
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number a column
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number a row
|
||||
/// @tparam T Floating-point or signed integer scalar types
|
||||
/// @tparam Q Value from qualifier enum
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/transpose.xml">GLSL transpose man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template<length_t C, length_t R, typename T, qualifier Q> |
||||
GLM_FUNC_DECL typename mat<C, R, T, Q>::transpose_type transpose(mat<C, R, T, Q> const& x); |
||||
|
||||
/// Return the determinant of a squared matrix.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number a column
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number a row
|
||||
/// @tparam T Floating-point or signed integer scalar types
|
||||
/// @tparam Q Value from qualifier enum
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/determinant.xml">GLSL determinant man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template<length_t C, length_t R, typename T, qualifier Q> |
||||
GLM_FUNC_DECL T determinant(mat<C, R, T, Q> const& m); |
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
#include "matrix_integer.inl" |
@ -0,0 +1,38 @@ |
||||
namespace glm{ |
||||
namespace detail |
||||
{ |
||||
template<length_t C, length_t R, typename T, qualifier Q, bool Aligned> |
||||
struct compute_matrixCompMult_type<C, R, T, Q, false, Aligned> { |
||||
GLM_FUNC_QUALIFIER static mat<C, R, T, Q> call(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y) |
||||
{ |
||||
return detail::compute_matrixCompMult<C, R, T, Q, detail::is_aligned<Q>::value>::call(x, y); |
||||
} |
||||
}; |
||||
|
||||
template<length_t DA, length_t DB, typename T, qualifier Q> |
||||
struct compute_outerProduct_type<DA, DB, T, Q, false> { |
||||
GLM_FUNC_QUALIFIER static typename detail::outerProduct_trait<DA, DB, T, Q>::type call(vec<DA, T, Q> const& c, vec<DB, T, Q> const& r) |
||||
{ |
||||
return detail::compute_outerProduct<DA, DB, T, Q>::call(c, r); |
||||
} |
||||
}; |
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q, bool Aligned> |
||||
struct compute_transpose_type<C, R, T, Q, false, Aligned> |
||||
{ |
||||
GLM_FUNC_QUALIFIER static mat<R, C, T, Q> call(mat<C, R, T, Q> const& m) |
||||
{ |
||||
return detail::compute_transpose<C, R, T, Q, detail::is_aligned<Q>::value>::call(m); |
||||
} |
||||
}; |
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q, bool Aligned> |
||||
struct compute_determinant_type<C, R, T, Q, false, Aligned>{ |
||||
|
||||
GLM_FUNC_QUALIFIER static T call(mat<C, R, T, Q> const& m) |
||||
{ |
||||
return detail::compute_determinant<C, R, T, Q, detail::is_aligned<Q>::value>::call(m); |
||||
} |
||||
}; |
||||
}//namespace detail |
||||
}//namespace glm |
@ -0,0 +1,237 @@ |
||||
#include <glm/ext/matrix_relational.hpp> |
||||
#include <glm/ext/matrix_integer.hpp> |
||||
#include <glm/ext/matrix_int2x2.hpp> |
||||
#include <glm/ext/matrix_int2x3.hpp> |
||||
#include <glm/ext/matrix_int2x4.hpp> |
||||
#include <glm/ext/matrix_int3x2.hpp> |
||||
#include <glm/ext/matrix_int3x3.hpp> |
||||
#include <glm/ext/matrix_int3x4.hpp> |
||||
#include <glm/ext/matrix_int4x2.hpp> |
||||
#include <glm/ext/matrix_int4x3.hpp> |
||||
#include <glm/ext/matrix_int4x4.hpp> |
||||
|
||||
using namespace glm; |
||||
|
||||
int test_matrixCompMult() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
{ |
||||
imat2 m(0, 1, 2, 3); |
||||
imat2 n = matrixCompMult(m, m); |
||||
imat2 expected = imat2(0, 1, 4, 9); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat2x3 m(0, 1, 2, 3, 4, 5); |
||||
imat2x3 n = matrixCompMult(m, m); |
||||
imat2x3 expected = imat2x3(0, 1, 4, 9, 16, 25); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); |
||||
imat2x4 n = matrixCompMult(m, m); |
||||
imat2x4 expected = imat2x4(0, 1, 4, 9, 16, 25, 36, 49); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); |
||||
imat3 n = matrixCompMult(m, m); |
||||
imat3 expected = imat3(0, 1, 4, 9, 16, 25, 36, 49, 64); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3x2 m(0, 1, 2, 3, 4, 5); |
||||
imat3x2 n = matrixCompMult(m, m); |
||||
imat3x2 expected = imat3x2(0, 1, 4, 9, 16, 25); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); |
||||
imat3x4 n = matrixCompMult(m, m); |
||||
imat3x4 expected = imat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); |
||||
imat4 n = matrixCompMult(m, m); |
||||
imat4 expected = imat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); |
||||
imat4x2 n = matrixCompMult(m, m); |
||||
imat4x2 expected = imat4x2(0, 1, 4, 9, 16, 25, 36, 49); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); |
||||
imat4x3 n = matrixCompMult(m, m); |
||||
imat4x3 expected = imat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121); |
||||
Error += all(equal(n, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int test_outerProduct() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
{
|
||||
glm::imat2x2 const m = glm::outerProduct(glm::ivec2(1), glm::ivec2(1)); |
||||
Error += all(equal(m, glm::imat2x2(1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
{
|
||||
glm::imat2x3 const m = glm::outerProduct(glm::ivec3(1), glm::ivec2(1));
|
||||
Error += all(equal(m, glm::imat2x3(1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
{
|
||||
glm::imat2x4 const m = glm::outerProduct(glm::ivec4(1), glm::ivec2(1));
|
||||
Error += all(equal(m, glm::imat2x4(1, 1, 1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
glm::imat3x2 const m = glm::outerProduct(glm::ivec2(1), glm::ivec3(1)); |
||||
Error += all(equal(m, glm::imat3x2(1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
{
|
||||
glm::imat3x3 const m = glm::outerProduct(glm::ivec3(1), glm::ivec3(1));
|
||||
Error += all(equal(m, glm::imat3x3(1, 1, 1, 1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
{ |
||||
glm::imat3x4 const m = glm::outerProduct(glm::ivec4(1), glm::ivec3(1)); |
||||
Error += all(equal(m, glm::imat3x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
|
||||
|
||||
{
|
||||
glm::imat4x2 const m = glm::outerProduct(glm::ivec2(1), glm::ivec4(1));
|
||||
Error += all(equal(m, glm::imat4x2(1, 1, 1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
{
|
||||
glm::imat4x3 const m = glm::outerProduct(glm::ivec3(1), glm::ivec4(1)); |
||||
Error += all(equal(m, glm::imat4x3(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
{
|
||||
glm::imat4x4 const m = glm::outerProduct(glm::ivec4(1), glm::ivec4(1));
|
||||
Error += all(equal(m, glm::imat4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))) ? 0 : 1; |
||||
} |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int test_transpose() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
{ |
||||
imat2 const m(0, 1, 2, 3); |
||||
imat2 const t = transpose(m); |
||||
imat2 const expected = imat2(0, 2, 1, 3); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat2x3 m(0, 1, 2, 3, 4, 5); |
||||
imat3x2 t = transpose(m); |
||||
imat3x2 const expected = imat3x2(0, 3, 1, 4, 2, 5); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); |
||||
imat4x2 t = transpose(m); |
||||
imat4x2 const expected = imat4x2(0, 4, 1, 5, 2, 6, 3, 7); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); |
||||
imat3 t = transpose(m); |
||||
imat3 const expected = imat3(0, 3, 6, 1, 4, 7, 2, 5, 8); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3x2 m(0, 1, 2, 3, 4, 5); |
||||
imat2x3 t = transpose(m); |
||||
imat2x3 const expected = imat2x3(0, 2, 4, 1, 3, 5); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); |
||||
imat4x3 t = transpose(m); |
||||
imat4x3 const expected = imat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); |
||||
imat4 t = transpose(m); |
||||
imat4 const expected = imat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); |
||||
imat2x4 t = transpose(m); |
||||
imat2x4 const expected = imat2x4(0, 2, 4, 6, 1, 3, 5, 7); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); |
||||
imat3x4 t = transpose(m); |
||||
imat3x4 const expected = imat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11); |
||||
Error += all(equal(t, expected)) ? 0 : 1; |
||||
} |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int test_determinant() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
{ |
||||
imat2 const m(1, 1, 1, 1); |
||||
int const t = determinant(m); |
||||
Error += t == 0 ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat3 m(1, 1, 1, 1, 1, 1, 1, 1, 1); |
||||
int t = determinant(m); |
||||
Error += t == 0 ? 0 : 1; |
||||
} |
||||
|
||||
{ |
||||
imat4 m(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1); |
||||
int t = determinant(m); |
||||
Error += t == 0 ? 0 : 1; |
||||
} |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int main() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
Error += test_matrixCompMult(); |
||||
Error += test_outerProduct(); |
||||
Error += test_transpose(); |
||||
Error += test_determinant(); |
||||
|
||||
return Error; |
||||
} |
Loading…
Reference in New Issue