Blitz3D Quaternions

Blitz3D Forums/Blitz3D Programming/Blitz3D Quaternions

JoshK(Posted 2005) [#1]
I am having trouble converting eulers into quaternions for use in .b3d files. I am using the code from Mark Sibly's MS3D .b3d exporter, but it does not produce correct results:

Procedure EulerAsQuat(pitch.f,yaw.f,roll.f)
sp.f=Sine(pitch/2.0)
cp.f=Cosine(pitch/2.0)
sy.f=Sine(yaw/2.0)
cy.f=Cosine(yaw/2.0)
sr.f=Sine(roll/2.0)
cr.f=Cosine(roll/2.0)
vectorw.f=cr*cp*cy+sr*sp*sy
vectorx.f=sr*cp*cy-cr*sp*sy
vectory.f=cr*sp*cy+sr*cp*sy
vectorz.f=-(cr*cp*sy-sr*sp*cy)
EndProcedure



Shambler(Posted 2005) [#2]
From what I can figure out,bearing in mind it is late ^^ try

vectorw.f =cy*cp*cr - sy*sp*sr
vectorx.f =cy*cp*sr + sy*sp*cr
vectory.f =sy*cp*cr + cy*sp*sr
vectorz.f =cy*sp*cr - sy*cp*sr



JoshK(Posted 2005) [#3]
That did not work.

I am checking the euler I put into the function, and the euler Blitz3D calculates is NOT the same.

My exporter says 0.0,90.0,-90.0 --> Blitz3D says 0.0,-90.0,90.0

When I rotate the object in Blitz3D to 0.0,90.0,-90.0, the same angles my editor says, it has the exact same orientation. So the problem is definitely the translation of the euler to the quaternion and back.


Tom(Posted 2005) [#4]
Halo, if it's any help an entitys current Quat is at:

w#= peekmemfloat(ent+48)
x#= peekmemfloat(ent+52)
y#= peekmemfloat(ent+56)
z#= peekmemfloat(ent+60)


I've not got a working function for euler>quat as when certain values exceed +/- 90 degrees, the quat is completely negative.


JoshK(Posted 2005) [#5]
Thanks for that.

I wrote a program that shows that the EulerAsQuat function in the MS3D exporter does not convert a Euler to the same Quaternion Blitz3D does:



JoshK(Posted 2005) [#6]
.


JoshK(Posted 2005) [#7]
.


JoshK(Posted 2005) [#8]
I uploaded the source code and required userlib:
http://www.leadwerks.com/post/quatprob.zip


JoshK(Posted 2005) [#9]
I got it working, using this code. This is THE RIGHT WAY to convert a euler into a Blitz3D quaternion!:

Procedure EulerAsQuat(pitch.f,yaw.f,roll.f)
sp.f=Sine(yaw/2)
cp.f=Cosine(yaw/2)
sy.f=Sine(roll/2)
cy.f=Cosine(roll/2)
sr.f=Sine(pitch/2)
cr.f=Cosine(pitch/2)
vectorw.f=(cr*cp*cy-sr*sp*sy)
vectorx.f=-(sr*cp*cy-cr*sp*sy)
vectory.f=(cr*sp*cy+sr*cp*sy)
vectorz.f=-(sr*sp*cy+cr*cp*sy)
EndProcedure



Shambler(Posted 2005) [#10]
Great work!
After half an hour I could see that a Blitz quaternions are unique and different to the way the rest of the planet does them lol! -.-

[edit] think its a typo in the blitz3d sourcecode? or does Mark just love to be different ;)


JoshK(Posted 2005) [#11]
Still, now that you can convert a euler to a Blitz3D quaternion, you can use it with the geometry code Mark posted.


Tom(Posted 2005) [#12]
cool :P