11 template<
typename T, qualifier Q>
12 GLM_FUNC_QUALIFIER vec<3, T, Q> combine(
13 vec<3, T, Q>
const& a,
14 vec<3, T, Q>
const& b,
17 return (a * ascl) + (b * bscl);
20 template<
typename T, qualifier Q>
21 GLM_FUNC_QUALIFIER vec<3, T, Q>
scale(vec<3, T, Q>
const& v, T desiredLength)
23 return v * desiredLength / length(v);
31 template<
typename T, qualifier Q>
32 GLM_FUNC_QUALIFIER
bool decompose(
mat<4, 4, T, Q> const& ModelMatrix,
vec<3, T, Q> & Scale,
qua<T, Q> & Orientation,
vec<3, T, Q> & Translation,
vec<3, T, Q> & Skew,
vec<4, T, Q> & Perspective)
40 for(length_t i = 0; i < 4; ++i)
41 for(length_t j = 0; j < 4; ++j)
42 LocalMatrix[i][j] /= LocalMatrix[3][3];
48 for(length_t i = 0; i < 3; i++)
49 PerspectiveMatrix[i][3] =
static_cast<T
>(0);
50 PerspectiveMatrix[3][3] =
static_cast<T
>(1);
64 RightHandSide[0] = LocalMatrix[0][3];
65 RightHandSide[1] = LocalMatrix[1][3];
66 RightHandSide[2] = LocalMatrix[2][3];
67 RightHandSide[3] = LocalMatrix[3][3];
75 Perspective = TransposedInversePerspectiveMatrix * RightHandSide;
79 LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] =
static_cast<T
>(0);
80 LocalMatrix[3][3] =
static_cast<T
>(1);
90 LocalMatrix[3] =
vec<4, T, Q>(0, 0, 0, LocalMatrix[3].w);
95 for(length_t i = 0; i < 3; ++i)
96 for(length_t j = 0; j < 3; ++j)
97 Row[i][j] = LocalMatrix[i][j];
100 Scale.x = length(Row[0]);
102 Row[0] = detail::scale(Row[0],
static_cast<T
>(1));
105 Skew.z = dot(Row[0], Row[1]);
106 Row[1] = detail::combine(Row[1], Row[0],
static_cast<T
>(1), -Skew.z);
109 Scale.y = length(Row[1]);
110 Row[1] = detail::scale(Row[1],
static_cast<T
>(1));
114 Skew.y = glm::dot(Row[0], Row[2]);
115 Row[2] = detail::combine(Row[2], Row[0],
static_cast<T
>(1), -Skew.y);
116 Skew.x = glm::dot(Row[1], Row[2]);
117 Row[2] = detail::combine(Row[2], Row[1],
static_cast<T
>(1), -Skew.x);
120 Scale.z = length(Row[2]);
121 Row[2] = detail::scale(Row[2],
static_cast<T
>(1));
128 Pdum3 =
cross(Row[1], Row[2]);
129 if(dot(Row[0], Pdum3) < 0)
131 for(length_t i = 0; i < 3; i++)
133 Scale[i] *=
static_cast<T
>(-1);
134 Row[i] *=
static_cast<T
>(-1);
156 T root, trace = Row[0].x + Row[1].y + Row[2].z;
157 if(trace >
static_cast<T
>(0))
159 root =
sqrt(trace +
static_cast<T
>(1.0));
160 Orientation.w =
static_cast<T
>(0.5) * root;
161 root =
static_cast<T
>(0.5) / root;
162 Orientation.x = root * (Row[1].z - Row[2].y);
163 Orientation.y = root * (Row[2].x - Row[0].z);
164 Orientation.z = root * (Row[0].y - Row[1].x);
168 static int Next[3] = {1, 2, 0};
170 if(Row[1].y > Row[0].x) i = 1;
171 if(Row[2].z > Row[i][i]) i = 2;
175 root =
sqrt(Row[i][i] - Row[j][j] - Row[k][k] +
static_cast<T
>(1.0));
177 Orientation[i] =
static_cast<T
>(0.5) * root;
178 root =
static_cast<T
>(0.5) / root;
179 Orientation[j] = root * (Row[i][j] + Row[j][i]);
180 Orientation[k] = root * (Row[i][k] + Row[k][i]);
181 Orientation.w = root * (Row[j][k] - Row[k][j]);
GLM_FUNC_QUALIFIER vec< L, T, Q > sqrt(vec< L, T, Q > const &x)
Definition func_exponential.inl:128
GLM_FUNC_QUALIFIER vec< 3, T, Q > cross(vec< 3, T, Q > const &x, vec< 3, T, Q > const &y)
Definition func_geometric.inl:175
GLM_FUNC_QUALIFIER mat< C, R, T, Q >::transpose_type transpose(mat< C, R, T, Q > const &m)
Definition func_matrix.inl:374
GLM_FUNC_QUALIFIER mat< C, R, T, Q > inverse(mat< C, R, T, Q > const &m)
Definition func_matrix.inl:388
GLM_FUNC_QUALIFIER T determinant(mat< C, R, T, Q > const &m)
Definition func_matrix.inl:381
GLM_FUNC_DECL GLM_CONSTEXPR genType epsilon()
Return the epsilon constant for floating point types.
Definition scalar_constants.inl:6
GLM_FUNC_DECL vec< L, bool, Q > epsilonNotEqual(vec< L, T, Q > const &x, vec< L, T, Q > const &y, T const &epsilon)
Definition epsilon.inl:56
GLM_FUNC_DECL vec< L, bool, Q > epsilonEqual(vec< L, T, Q > const &x, vec< L, T, Q > const &y, T const &epsilon)
Definition epsilon.inl:32
GLM_FUNC_DECL bool decompose(mat< 4, 4, T, Q > const &modelMatrix, vec< 3, T, Q > &scale, qua< T, Q > &orientation, vec< 3, T, Q > &translation, vec< 3, T, Q > &skew, vec< 4, T, Q > &perspective)
Definition matrix_decompose.inl:32
detail namespace with internal helper functions
Definition json.h:249
Core features
Definition common.hpp:21
Definition qualifier.hpp:36
Definition type_quat.hpp:20
Definition qualifier.hpp:35