Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (624) 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 707 times) 0 Members and 1 Guest 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?

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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: 121
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: 159
Projects: 4
Exp: 3 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: 121
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.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 ClaasJG (30 views) 2015-04-27 13:36:51 BurntPizza (34 views) 2015-04-23 03:42:11 theagentd (37 views) 2015-04-22 16:23:07 Riven (51 views) 2015-04-16 10:48:47 Duke0200 (60 views) 2015-04-16 01:59:01 Fairy Tailz (43 views) 2015-04-14 20:13:12 Riven (47 views) 2015-04-12 21:36:37 bus hotdog (65 views) 2015-04-10 02:39:32 CopyableCougar4 (67 views) 2015-04-10 00:51:04 BurntPizza (72 views) 2015-04-06 22:06:58
 theagentd 23x BurntPizza 17x wessles 15x Spasi 13x kingroka123 11x alwex 11x 65K 11x Hanksha 7x Riven 7x chrislo27 7x kevglass 7x Olo 7x Ecumene 7x ra4king 7x Rayvolution 7x KevinWorkman 6x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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