Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Matrix4f getRotation Vector3f  (Read 324 times)
0 Members and 1 Guest are viewing this topic.
Offline jmguillemette
« Posted 2013-12-28 04: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!=-
Offline Slyth2727
« Reply #1 - Posted 2013-12-28 04: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?

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Offline jmguillemette
« Reply #2 - Posted 2013-12-28 05: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!=-
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jmguillemette
« Reply #3 - Posted 2013-12-28 05:25:33 »

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

-=Like a post.. give the author a medal!=-
Offline jmguillemette
« Reply #4 - Posted 2013-12-28 07: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!=-
Online matheus23

JGO Kernel


Medals: 98
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2013-12-29 18: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
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 121
Projects: 4
Exp: 3 years



« Reply #6 - Posted 2013-12-29 18: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.
Online matheus23

JGO Kernel


Medals: 98
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2013-12-29 19: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
Offline Slyth2727
« Reply #8 - Posted 2013-12-29 20:34:01 »

Sorry if I was giving false information, I'm no math expert either. And I suppose I was mixing the two up.

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!