Simple question:
Is there an easy way (or what is the best way) to convert a lwjgl Matrix4f to a Vector3f that represents the rotations
cheers and thanks!
j.
Simple question:
Is there an easy way (or what is the best way) to convert a lwjgl Matrix4f to a Vector3f that represents the rotations
cheers and thanks!
j.
I don’t think you understand what the two are, excuse me if you do though I mean no offence.
A Vector is used to store a direction. From what I understand, you have a point (0, 0, 0) (the origin) and then the Vector, say (5, 5, 5). The direction that the vector represents is (0, 0, 0) to (5, 5, 5).
A (Rotation) Matrix on the other hand is almost a Vector, but with rotation in the fourth argument, generally named w, eg (x, y, z, w).
Therefore you couldn’t have a Vector that represents rotation because vectors only contain direction. I suppose if you want you could make a variable named w or rotation in your vector class but that really makes no sense…
Maybe I misunderstood you, would you mind elaborating on what you are trying to do?
I’ve standardized my game using matrixes for storing the rotation / position of my models.
but sometimes i need to do math based on the pitch, yaw, ect.
so i need to be able to convert from the matrix to 3 single angular values.
j.
may have found my answer
public Vector3f getRotation(){
float yaw = 0.0f;
float pitch = 0.0f;
float roll = 0.0f;
if(matrix.m10 == 1.0f || matrix.m10 == -1.0f){
yaw = (float)Math.atan2(matrix.m12, matrix.m33);
//pitch and roll remain = 0;
}else{
yaw = (float) Math.atan2(-matrix.m30, matrix.m10);
pitch = (float) Math.asin(matrix.m20);
roll = (float) Math.atan2(-matrix.m22, matrix.m21);
}
return new Vector3f(yaw, pitch, roll);
}
correction to the code i posted
cause i hate posting code that has errors and thus miss leads other who may follow my examples
public Vector3f getRotation(){
float yaw = 0.0f;
float pitch = 0.0f;
float roll = 0.0f;
if(matrix.m00 == 1.0f || matrix.m00 == -1.0f){
yaw = (float)Math.atan2(matrix.m02, matrix.m23);
//pitch and roll remain = 0;
}else{
yaw = (float) Math.atan2(-matrix.m20, matrix.m00);
pitch = (float) Math.asin(matrix.m10);
roll = (float) Math.atan2(-matrix.m12, matrix.m11);
}
return new Vector3f(yaw, pitch, roll);
}
I’m no maths expert, but I’m pretty sure you’re mistaking Quaternions with Matrices.
A quaternion has 4 elements, x, y, z and w.
A matrix (in the case of the OP’s mentioned matrix, a Matrix4f, which is a class in LWJGL used for representing 4x4 matrices) has 4x4 elements in the OP’s case. The identity matrix of a 4x4 matrix for example looks like this:
I don’t know where you picked this up from, but how would you store 3d rotation in one variable? What you describe wouldn’t be a Quaternion either.
Quoting the english Wikipedia here:[quote]
In practical applications, they are frequently represented as a vector paired with a scalar, which encode an un-normalized direction and an orientation around that direction, respectively.
[/quote]
(http://en.wikipedia.org/wiki/Quaternion)
Sounds like about what he said…
Sorry if I was giving false information, I’m no math expert either. And I suppose I was mixing the two up.