All pastes #919927 Raw Edit

Untitled

public text v1 · immutable
#919927 ·published 2008-02-27 02:29 UTC
rendered paste body
[21:16] <keen> what i want to know is
[21:16] <keen> what kinda freaky rotation tgea uses
[21:16] <fleeky-> its quaternion numbers right keen  
[21:16] <keen> i believe so
[21:16] <keen> but
[21:16] <LordHavoc> quats are commonly used
[21:16] <LordHavoc> rodrigues vectors are necessary for spinning objects though
[21:16] <keen> i've never seen that before in my life, i'm used to T1
[21:16] <LordHavoc> (which is just an axis of rotation and an angle)
[21:16] <keen> t1's standard X Y Z rotations
[21:17] <keen> this has like r1 r2 r3 r4
[21:17] <LordHavoc> X Y Z is euler angles
[21:17] <LordHavoc> pitch/heading/bank (in some order)
[21:17] <keen> and they all control rotation O.o
[21:17] <LordHavoc> very problematic
[21:17] <LordHavoc> yeah r1-4 is quaternion
[21:17] <LordHavoc> you can actually write a quat by hand if you have a calculator handy, but it's hardly convenient
[21:17] <fleeky-> what ive always wanted to know i what the 4th number is for .. 
[21:17] <LordHavoc> fleeky-: cosine of half-angle
[21:17] <keen> if i could get a vector-to-quaternion and vice versa function, i'd be a happy person
[21:18] <LordHavoc> keen: oh sure
[21:18] <LordHavoc> keen: what do you need?
[21:18] <keen> just a conversion function that can convert a vector to a quaternion and a quaternion to a vector
[21:19] <LordHavoc> keen: quats are like wheels rolling, just think of the axle's direction, that's the r1/2/3 and put 1 in the r4, and you have no rotation, but can easily turn it into a rotation with appropriate scaling of the first 3 and the 4 (kind of inversely)
[21:19] <keen> math isn't my strongest point unfortunately
[21:19] <LordHavoc> keen: well I'm sorry to say that the XYZ thing you mentioned is not a vector, it is 3 angles
[21:20] <LordHavoc> keen: http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q60
[21:20] <keen> i see
[21:20] <LordHavoc> keen: see the "The following might also work:" part
[21:20] <LordHavoc> keen: which is 5 lines - not much fun though
[21:21] <LordHavoc> keen: the code directly above it directly generates a quaternion from the pitch yaw and roll
[21:21] <keen> i'll have to work on adapting this to script :o but it's a start
[21:21] <LordHavoc> keen: I actually go through matrix representation first because it gives me less headaches
[21:22] <LordHavoc> http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q36
[21:23] <LordHavoc> http://svn.icculus.org/darkwar/trunk/src/engine/matrixlib.c - the Matrix4x4_CreateFromQuakeEntity function may be insightful, it converts pitch/yaw/roll representation (euler) to a matrix
[21:23] <LordHavoc> I don't have any matrix<->quat conversion code handy though
[21:23] <LordHavoc> the matrix faq does
[21:23] <keen> hmm i see
[21:23] <keen> either way
[21:24] <keen> it looks like it would be extremely helpful for me to brush up on how exactly i get a quaternion to point a direction
[21:24] <LordHavoc> quats are simply not meant to be human-editable
[21:24] <LordHavoc> well that's actually a bit simpler
[21:24] <LordHavoc> a quat does not point a direction per se
[21:24] <LordHavoc> it describes an axis of rotation and an angle around it
[21:24] <LordHavoc> so if you have an old direction and a new direction you want it to point that toward
[21:25] <LordHavoc> then the axis of rotation would be perpendicular to both
[21:25] <fleeky-> ooo
[21:25] <keen> O.o
[21:25] <keen> yep
[21:25] <LordHavoc> which takes a crossproduct
[21:25] <LordHavoc> so that's the r1/r2/r3 in the quat
[21:25] <LordHavoc> it just describes what the rotation is around
[21:25] <LordHavoc> then take the angle*0.5 in radians, I.E. a half-angle
[21:25] <fleeky-> i dont get the angle around it but the wheel analogy helps out for the first part :)
[21:26] <LordHavoc> and multiply r1/r2/r3 by the sin of that, and store the cos into r4
[21:26] <LordHavoc> fleeky-: exactly, it's just an axle
[21:26] <keen> i see
[21:27] <LordHavoc> keen: as far as I can tell the only reason a quat has a half-angle baked into it is that a full angle would have sin = 0 at 180 degrees
[21:27] <LordHavoc> keen: and sin = 0 would mean the r1/r2/r3 would all be zero and the axis would be lost
[21:27] <keen> that makes sense
[21:27] <LordHavoc> keen: so a half-angle allows sin to go from 1 to 0 at 180 degrees and -180 degrees (there are two polar opposite quats that repesent any given rotation)
[21:28] <LordHavoc> err would have sin = 0 at 90 degrees I meant
[21:28] <LordHavoc> where as the half-angle puts sin at 0 at 180 degrees
[21:28] <LordHavoc> it's weird stuff to me
[21:28] <LordHavoc> I've never understood complex numbers
[21:28] <keen> i can imagine