132 qua<T, Q>& Orientation,
133 vec<3, T, Q>& Translation,
135 vec<4, T, Q>& Perspective)
137 mat<4, 4, T, Q> LocalMatrix(ModelMatrix);
140 if(epsilonEqual(LocalMatrix[3][3],
static_cast<T
>(0), epsilon<T>()))
142 LocalMatrix[3][3] = T(1);
148 for(length_t i = 0; i < 4; ++i)
149 for(length_t j = 0; j < 4; ++j)
150 LocalMatrix[i][j] /= LocalMatrix[3][3];
154 mat<4, 4, T, Q> PerspectiveMatrix(LocalMatrix);
156 for(length_t i = 0; i < 3; i++)
157 PerspectiveMatrix[i][3] =
static_cast<T
>(0);
158 PerspectiveMatrix[3][3] =
static_cast<T
>(1);
170 if(epsilonNotEqual(LocalMatrix[0][3],
static_cast<T
>(0), epsilon<T>()) ||
171 epsilonNotEqual(LocalMatrix[1][3],
static_cast<T
>(0), epsilon<T>()) ||
172 epsilonNotEqual(LocalMatrix[2][3],
static_cast<T
>(0), epsilon<T>()))
175 vec<4, T, Q> RightHandSide;
176 RightHandSide[0] = LocalMatrix[0][3];
177 RightHandSide[1] = LocalMatrix[1][3];
178 RightHandSide[2] = LocalMatrix[2][3];
179 RightHandSide[3] = LocalMatrix[3][3];
184 mat<4, 4, T, Q> InversePerspectiveMatrix =
185 glm::inverse(PerspectiveMatrix);
186 mat<4, 4, T, Q> TransposedInversePerspectiveMatrix =
187 glm::transpose(InversePerspectiveMatrix);
190 Perspective = TransposedInversePerspectiveMatrix * RightHandSide;
194 LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] =
static_cast<T
>(0);
195 LocalMatrix[3][3] =
static_cast<T
>(1);
200 Perspective = vec<4, T, Q>(0, 0, 0, 1);
204 Translation = vec<3, T, Q>(LocalMatrix[3]);
205 LocalMatrix[3] = vec<4, T, Q>(0, 0, 0, LocalMatrix[3].w);
207 vec<3, T, Q> Row[3], Pdum3;
210 for(length_t i = 0; i < 3; ++i)
211 for(length_t j = 0; j < 3; ++j)
212 Row[i][j] = LocalMatrix[i][j];
220 Skew.z = dot(Row[0], Row[1]);
229 Skew.y = glm::dot(Row[0], Row[2]);
231 Skew.x = glm::dot(Row[1], Row[2]);
243 Pdum3 = cross(Row[1], Row[2]);
244 if(dot(Row[0], Pdum3) < 0)
246 for(length_t i = 0; i < 3; i++)
248 Scale[i] *=
static_cast<T
>(-1);
249 Row[i] *=
static_cast<T
>(-1);
271 T root, trace = Row[0].x + Row[1].y + Row[2].z;
272 if(trace >
static_cast<T
>(0))
274 root = sqrt(trace +
static_cast<T
>(1.0));
275 Orientation.w =
static_cast<T
>(0.5) * root;
276 root =
static_cast<T
>(0.5) / root;
277 Orientation.x = root * (Row[1].z - Row[2].y);
278 Orientation.y = root * (Row[2].x - Row[0].z);
279 Orientation.z = root * (Row[0].y - Row[1].x);
283 static int Next[3] = {1, 2, 0};
285 if(Row[1].
y > Row[0].
x)
287 if(Row[2].
z > Row[i][i])
292#ifdef GLM_FORCE_QUAT_DATA_WXYZ
298 root = sqrt(Row[i][i] - Row[j][j] - Row[k][k] +
static_cast<T
>(1.0));
300 Orientation[i + off] =
static_cast<T
>(0.5) * root;
301 root =
static_cast<T
>(0.5) / root;
302 Orientation[j + off] = root * (Row[i][j] + Row[j][i]);
303 Orientation[k + off] = root * (Row[i][k] + Row[k][i]);
304 Orientation.w = root * (Row[j][k] - Row[k][j]);
GLM_FUNC_QUALIFIER vec< 3, T, Q > combine_impl(vec< 3, T, Q > const &a, vec< 3, T, Q > const &b, T ascl, T bscl)
Make a linear combination of two vectors and return the result.
GLM_FUNC_QUALIFIER void glm_recompose(mat< 4, 4, T, Q > &model_matrix, vec< 3, T, Q > const &in_scale, qua< T, Q > const &in_orientation, vec< 3, T, Q > const &in_translation, vec< 3, T, Q > const &in_skew, vec< 4, T, Q > const &in_perspective)
GLM_FUNC_QUALIFIER mat< 4, 4, T, Q > recompose_impl(vec< 3, T, Q > const &scale, qua< T, Q > const &orientation, vec< 3, T, Q > const &translation, vec< 3, T, Q > const &skew, vec< 4, T, Q > const &perspective)
GLM_FUNC_QUALIFIER bool glm_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)