Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Errm, does anyone happen to be really good at 3d math? (limb system)

Author
Message
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Mar 2011 10:33 Edited at: 23rd Mar 2011 10:34
So... Basically, I'm trying to create a limb system. When an object sits on top of another object, it moves, and rotates with it. My problem is the rotation.

You have an object in another object's local coordinates. So, this object in another object's local coordinates (called obj1), has position and rotation. Then, you transform the "parent" object (called obj2) to world space. Now, the transformation (dealing with row vectors) is LocalMatrix*ParentMatrix. That's all well and good, but then there's the transition from the resulting matrix, to euler angles. That's what's getting me.

So, you have a 3x3 matrix, M, and that's equal to:
[M11 M12 M13]
[M21 M22 M23]
[M31 M32 M33]
So you have 9 variables that you know the values of. That matrix, is equal to this matrix transposed:

(it's transposed because that is in column major format, where I'm working in row-major - because DBPro uses row-major.)

So, you need to find x,y, and z of that rotation matrix, given all the values of matrix M. Converting a rotation matrix to euler angles.

This is my function that converts a matrix to euler angles:
(it uses the algorithm described in this paper)

However... there is one this glaring at me in this code - the variable y can only vary by 180 degrees! A circle is 360 degrees, 180 isn't enough. However, it seems like everywhere I look, papers about getting euler angles from rotation matrices are content with saying y=-asin(x). (like http://www.geometrictools.com and this paper)

So... You obviously have to overcome this problem (this way, or another way) if you want to make a parent/child 3d positioning system, like the one in DBPro. How?!

This code demonstrates how the function doesn't work.



[edit]
aaaand this is obviously geared towards DBPro at the moment, but I do believe I need to know this for OpenGL/Direct3D/other stuff.

BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Mar 2011 12:57
I use the EZrotate plugin. I don't need to know how it happens, I just want to focus on my game, so maybe my needs are different to yours. But if you just want to move stuff...EZrotate!

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Mar 2011 13:21
Quote: "But if you just want to move stuff...EZrotate!"


And money!
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Mar 2011 13:30
Quote: "And money!"


It's not that costly is it?

Although if you're in no hurry to solve this problem I'd suggest figuring it out yourself (or looking it up) rather than relying on a library to do it for you. You'll learn stuff that you will be able to use in the future.

I'd help you but I know very little about 3D maths.



Support a charitable indie game project!
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Mar 2011 15:53
Argh... wait... I think the error is in my matrix multiplication routine... I think I have translations and inverse translations mucking everything up.

Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Mar 2011 22:37
I'm sure Coffee Coder did this at some point, if you can attract his attention he might be able to help you.
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Mar 2011 03:45
I have some C++/DGDK/D3D code if you want to see it. It's rather simple but it's up to you if you want to translate it into DBP. Also it uses quaternions so I dunno if it'll be possible.

"everyone forgets a semi-colon sometimes." - Phaelax
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Mar 2011 03:51
Sure, I'm not familiar with d3d but... I've been learning openGL, so some stuff should translate over. You can post it here or e-mail me, whichever's better.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Mar 2011 07:44
OHHHHHHHHHH!

I figured out what I was doing wrong! I think I was just too tired last night.

First of all, in the main loop, I was setting object 3's z rotation to 0, which just doesn't work (that takes away a degree of freedom)

Secondly, the original method I was using had a typo, a bug at +-90 degrees on the y axis.

Thirdly, the way I'm rotating the object is bad. Full yaw/pitch/roll can be achieved even if the y axis is limited to 180 degrees, HOWEVER, you CAN'T rotate your object just by adding to the y axis - which is what I was doing.

I should have a working demo of this soon in the code snippets section! :3

Login to post a reply

Server time is: 2025-05-23 07:13:09
Your offset time is: 2025-05-23 07:13:09