Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  Converting a 3x3 rotation matrix to euler angles to 4x4 matrix  (Read 733 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Posted 2014-03-20 01:39:25 »

I've been trying to get a MD3 loader to work for awhile now. With help from goussej I got the loader to load all the geometry, surfaces, skins, and tags. I now, however, found a new issue that I am not quite sure how to tackle.

the MD3 model format stores it's rotation matrix as a 3x3. The generic model format I use in my game uses euler angles for rotations (before sending it to the shader), expressed like this:
1  
2  
3  
Matrix4f.rotate((float)Math.toRadians(modelAngle.z), new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
Matrix4f.rotate((float)Math.toRadians(modelAngle.y), new Vector3f(0, 1, 0), modelMatrix, modelMatrix);
Matrix4f.rotate((float)Math.toRadians(modelAngle.x), new Vector3f(1, 0, 0), modelMatrix, modelMatrix);


So, to try to break down the 3x3 matrix to euler angles, I did this:
1  
2  
3  
rotX = (float) Math.toDegrees(Math.atan2(tag._axis.m21, tag._axis.m22));
rotY = (float) Math.toDegrees(-Math.asin(tag._axis.m20));
rotZ = (float) Math.toDegrees(Math.atan2(tag._axis.m10, tag._axis.m00));


This doesn't seem to work quite right, and matrices are not my strong suit.
I will point out that the Z axis is used for height in my engine (instead of the Y axis).

Any ideas? :x

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline The Lion King
« Reply #1 - Posted 2014-03-20 02:33:52 »

M00. M10 M20 0
M01  M11 M21 0
M02  M12 M22 0
   0       0         0  1

Just turn it to this mat4 it will do the same thing

"You have to want it more than you want to breath, then you will be successful"
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #2 - Posted 2014-03-20 03:41:51 »

My model class uses euler angles, and it's used beyond just MD3 models; so I can't just convert the 3x3 matrix directly to a 4x4 matrix.

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline The Lion King
« Reply #3 - Posted 2014-03-20 04:00:54 »

If it is just a simple rotation matrix, why not? It does the same task

"You have to want it more than you want to breath, then you will be successful"
Offline gouessej
« Reply #4 - Posted 2014-03-20 09:00:53 »

You can look at Ardor3D or any other engine, they have methods to convert matrices into Euler angles.

Offline EgonOlsen
« Reply #5 - Posted 2014-03-20 17:02:16 »

I would think that you have to negate the parameter in your asin-call and not the result. Anyway, you have to keep in mind that the angles that you derive from the matrix are only one way to create the resulting matrix. So they are angles that will create the resulting matrix, but they might not be the angles that you expect to get.
It's a better idea to work with matrices directly anyway...

Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #6 - Posted 2014-03-20 18:22:35 »

I guess I'll just bite the bullet and get rid of my euler angle dependancy.
Seems to work fine now Wink

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #7 - Posted 2014-03-21 21:00:03 »

One thing that I haven't been able to get to work right...
I wanted to change the "whole" direction of the md3 model.

My model class now uses a Matrix4f to express it's current rotation/position. Because the quake player model is made up of three separate models welded together by "tags", I need to add a new rotation to each model starting from the root one. So to do this, I stored the matrix4 value from the previous model, applied it to the current one, an then added that current models rotation. While this works, I'm not able to set a global direction for the model, as I overwrite the rotation.

So I guess my problem boils down to this...
I have a matrix4f, and I want to add it to a matrix3f.
I tried converting the matrix3f to a matrix4f, and then doing Matrix4f.add(m1, m2, src) but it doesn't seem to work...

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline The Lion King
« Reply #8 - Posted 2014-03-21 21:02:45 »

Assuming i understand the question right,

you should multiply them not add them. The initial rotation (the source/root rotation) should be on the right hand side of the multiplication and the additional rotation will be on the left.

so

CombinedMatrix = additionalRotationMatrix * initialRotationMatrix;

"You have to want it more than you want to breath, then you will be successful"
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #9 - Posted 2014-03-21 21:42:01 »

Thanks Wink
Worked perfectly Smiley

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (59 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!