Matrix result converting to quaternion and back has values flipped?
Tag : chash , By : user187301
Date : March 29 2020, 07:55 AM
it helps some times One of the other solutions for converting quaternions to matrixes seems to work: /// <summary>
/// Converts the quaternion to it's matrix representation.
/// </summary>
/// <returns>A matrix representing the quaternion.</returns>
public Matrix ToMatrix()
{
if (!this.Normalized)
return this.Normalize().ToMatrix();
double xx = X * X;
double xy = X * Y;
double xz = X * Z;
double xw = X * W;
double yy = Y * Y;
double yz = Y * Z;
double yw = Y * W;
double zz = Z * Z;
double zw = Z * W;
return new Matrix(new double[,]
{
{ 1 - 2 * (yy + zz), 2 * (xy - zw), 2 * (xz + yw), 0 },
{ 2 * (xy + zw), 1 - 2 * (xx + zz), 2 * (yz - xw), 0 },
{ 2 * (xz - yw), 2 * (yz + xw), 1 - 2 * (xx + yy), 0 },
{ 0, 0, 0, 1 }
});
}
|
Converting glm quaternion to rotation matrix and using it with opengl
Tag : cpp , By : user165871
Date : March 29 2020, 07:55 AM
Hope that helps GLM won't/can't(?) automagically cast a mat4 to GLfloat* so you have to help it along a bit. Try this: #include <glm/gtc/type_ptr.hpp>
glMultMatrixf( glm::value_ptr( glm::mat4_cast(orientation) ) );
glMultMatrixf( &glm::mat4_cast(orientation)[0][0] );
|
Eigen: matrix to quaternion and back have different result
Date : March 29 2020, 07:55 AM
will help you Just checked the implementation of Eigen's matrix to quaternion conversion. It is based on "Quaternion Calculus and Fast Animation", by Ken Shoemake. And as one can see when analyzing the source, this assumes that the matrix is indeed a rotation matrix (or close to one). In fact all symmetric matrices with M.trace()>0 will result in a (scaled) identity quaternion. If you expect anything else for invalid rotation matrices, you need to implement your own conversion method.
|
Glm Quaternion lookat function
Tag : cpp , By : AnToni00
Date : November 25 2020, 01:01 AM
|
Trouble converting matrix to quaternion and back
Tag : cpp , By : Dominique Vocat
Date : March 29 2020, 07:55 AM
|