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.

DarkBASIC Professional Discussion / Converting from local to global angles

Author
Message
Michael P
19
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 24th Dec 2010 22:18 Edited at: 24th Dec 2010 22:19
Hopefully this will be the last maths question I post in the near future. This is part of my attempt at solving a problem I recently posted.

Using Eular angles (as DBP does) I have a global frame of reference where everything is described as rotations around axis which originate from the point 0,0,0 and propagate through the global space.

I have an entity with a position and orientation (with X, Y and Z angles) all described in the global frame of reference.

I want to locally turn the entity by an angle as if its current orientation were 0,0,0 angles and then convert the result back into a global set of angles.

So basically I want to treat the entity independently but then recombine it with the global 3D world. Here is a rubbish picture which might (but probably won't) help to explain:


The problem is with the Y and Z angles e.g. if the entity is facing directly upwards then a rotation left would involve a change in its global Z angle and no change in the Y angle. If the entity is facing directly forwards then a rotation left would involve a change in its global Y angle and no change in its Z angle. I can't quite see an obvious way of getting around this issue, but hopefully there is!

Any help is much appreciated.

Attachments

Login to view attachments
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 24th Dec 2010 23:01
I'm very bad at math, but here goes...

If you use TURN, PITCH, and ROLL, you can rotate the object from its local facing. Then you can get its global rotations using the OBJECT ANGLE expressions.

If you need to keep track of the local angles, I guess you could just add or subtract every time you made a local rotation.

But I could be wrong.

Neuro Fuzzy
18
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 25th Dec 2010 01:04 Edited at: 25th Dec 2010 01:33
OOH I know this one! let me dig up the code...

[edit]
arrgghhh can't find it... Basically, first you have your object in its own space, that is at position <x,y,z>, with angle <a,b,c>. So using x/y/z and a/b/c, construct the 4 by 4 matrix defining the objects position. Call this matrix A.

Now, construct a matrix that transforms the object's space into world space. Call this matrix B.

Now have a matrix C, C=B*A


wait, no, scratch that explanation, I found the post!!!
http://www.youtube.com/watch?v=A-UTPKL-UGY&feature=grec_index


Quote: "press qwe/asd to change the angle of the plane, mouse to look around, and the up and down arrowkeys to move. You'll notice absolutely nothing special, but press the spacekey to view yourself standing on a plane, rotating around."




uhh I'm not sure if this will actually help you with your problem... but its what you were asking for

the rotMatrixToEulerAng function originates from this matrix:

which is the combination of (rotation around z axis)*(rotation around y axis)*(rotation around x axis) in a left handed coordinate system.

So, that matrix, given three euler angles, equals the rotation matrix passed into the function. So you can pick and choose which ones are easiest to solve for! First you solve for the y angle in the bottom left of the matrix, and then you continue on - with a couple if statements to avoid division by zero screwups and stuff.


[edit]

oh yeah, if your world transformation scales anything, you'll want to normalize the first three columns (it might be a good idea anyways), since the idea of a plain ol' rotation matrix is to have orthogonal unit vectors.

Michael P
19
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 25th Dec 2010 02:08
Thanks alot !!! I will get stuck into this ASAP. You posted the wrong link though, its http://forum.thegamecreators.com/?m=forum_view&t=174828&b=7 (google'd your quote).


Merry Christmas!

Neuro Fuzzy
18
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 25th Dec 2010 12:16
ahahahhhh whoops... I was linking that song to someone else... I guess I hit windows-c instead of ctrl-c or something xD

Login to post a reply

Server time is: 2025-06-12 10:56:52
Your offset time is: 2025-06-12 10:56:52