Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Matrix4f getRotation Vector3f  (Read 2584 times) 0 Members and 2 Guests are viewing this topic.
jmguillemette
 « Posted 2013-12-28 03:06:54 »

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.

-=Like a post.. give the author a medal!=-
Slyth2727
 « Reply #1 - Posted 2013-12-28 03:58:39 »

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?
jmguillemette
 « Reply #2 - Posted 2013-12-28 04:07:00 »

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.

-=Like a post.. give the author a medal!=-
jmguillemette
 « Reply #3 - Posted 2013-12-28 04:25:33 »

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);
}

-=Like a post.. give the author a medal!=-
jmguillemette
 « Reply #4 - Posted 2013-12-28 06:58:36 »

correction to the code i posted
cause i hate posting code that has errors and thus miss leads other who may follow my examples

 1  2  3  4  5  6  7  8  9  10  11  12  13  14 `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);   }`

-=Like a post.. give the author a medal!=-
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #5 - Posted 2013-12-29 17:22:49 »

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).

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:

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 6 years

 « Reply #6 - Posted 2013-12-29 17:50:53 »

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).
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.
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #7 - Posted 2013-12-29 18:40:03 »

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).
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.
(http://en.wikipedia.org/wiki/Quaternion)

Sounds like about what he said...

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Slyth2727
 « Reply #8 - Posted 2013-12-29 19:34:01 »

Sorry if I was giving false information, I'm no math expert either. And I suppose I was mixing the two up.
Pages: [1]
 ignore  |  Print

 ivj94 (586 views) 2018-03-24 14:47:39 ivj94 (49 views) 2018-03-24 14:46:31 ivj94 (383 views) 2018-03-24 14:43:53 Solater (63 views) 2018-03-17 05:04:08 nelsongames (110 views) 2018-03-05 17:56:34 Gornova (159 views) 2018-03-02 22:15:33 buddyBro (704 views) 2018-02-28 16:59:18 buddyBro (93 views) 2018-02-28 16:45:17 xxMrPHDxx (494 views) 2017-12-31 17:17:51 xxMrPHDxx (734 views) 2017-12-31 17:15:51
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org