Hard Light Productions Forums

Off-Topic Discussion => Programming => Topic started by: Scooby_Doo on December 29, 2012, 05:12:37 am

Title: Fun time with angles
Post by: Scooby_Doo on December 29, 2012, 05:12:37 am
Alright I'm having a hard enough time with ship rotation deltas I've started diving into quaternions.
Using excel spreadsheet:

Assume it starts at A1
=COS(Z) * COS(Y)=SIN(Z)*COS(X) + COS(Z)*SIN(Y)*SIN(X)=SIN(Z)*SIN(X) -COS(Z)*SIN(Y)*COS(X)
=-SIN(Z)*COS(Y)=COS(Z)*COS(X) - SIN(Z)*SIN(Y)*SIN(X)=-COS(Z)*SIN(X)+SIN(Z)*SIN(Y)*COS(X)
=SIN(Y)=COS(Y) * SIN(X)=COS(Y)*COS(X)

If I punch in the right X,Y,Z then the results will look good compared to the in-game Orientation matrix. 

Then I convert that matrix into a quaternion:
QW =SQRT(1+A1+B2+C3)/2
QX =(C2-B3)/(4*qw)
QY =(A3-C1)/(4*qw)
QZ =(B1-A2)/(4*qw)

Say i take (0,0,45)
I get :
.713.700  0
-.700.713  0
00  1

Problem is the results are W=.92541 X = 90, Y = 90 Z = 45
Why the 90's?


Or better yet.. does anyone have a good way of taking the change in a ships rotation and comparing it to the previous frame's  i.e. the delta change in pitch/bank/roll for all three axises?
Title: Re: Fun time with angles
Post by: Aardwolf on December 31, 2012, 06:10:23 pm
Here's a resource that looks like it should have everything you need... http://www.flipcode.com/documents/matrfaq.html

Euler to quat is #60

Oddly, I don't see anything about quat to euler angles, but it seems to have quat to rotation matrix, so maybe that's good enough?
Title: Re: Fun time with angles
Post by: Scooby_Doo on January 01, 2013, 01:30:30 pm
Sorry aardwolf, should have deleted this thread.  Turns out I was doing this the hard way.  The values I was trying to calculate were already done  (ship.Physics.RotationalVelocity)
Title: Re: Fun time with angles
Post by: Nuke on January 01, 2013, 06:26:29 pm
meh dont worry about it, that link has some useful information in it (namely all the stuff i didnt know about quats :D ).
Title: Re: Fun time with angles
Post by: Aardwolf on January 01, 2013, 07:59:59 pm
Sorry aardwolf, should have deleted this thread.  Turns out I was doing this the hard way.  The values I was trying to calculate were already done  (ship.Physics.RotationalVelocity)

Oh! I saw the post where you said that, but I thought you were saying you had found a way around some other aspect of it or something idk derp :)

@Nuke: be sure to unit test anything you take from there... IIRC I had to make some corrections to get the Mat3-->quat conversion working right, there might be other errors as well
Title: Re: Fun time with angles
Post by: Nuke on January 02, 2013, 01:07:18 am
there were some things i didnt know, like that conjugates are easy as **** to compute, and you cant just use an axis and a rotation as a quat (hince most of the quat functions i posted for scooby were completely wrong).