computing quaternian values for Pitch/Yaw/Roll ?

Blitz3D Forums/Blitz3D Programming/computing quaternian values for Pitch/Yaw/Roll ?

Stickman(Posted 2003) [#1]
Working with the B3D file formate,and need to be enable to get EntityPitch,Yaw,Roll to a quaternian values.

Got a book on the math and well,You need to be a mathamaniac
to figure this out,somthing Im not.

Im confussed and need some help on the math equations,Like the whole equation would be nice.

Any help would be appreciated.
Thanks........


Michael Reitzenstein(Posted 2003) [#2]
There is code in the code archive somewhere to do this.


Stickman(Posted 2003) [#3]
I just came back from there Now.

It seems to work but not as I expected.

If my entitys Yaw is at -90,when converted to a Quat,
loaded into B3d file then reloaded the new Yaw is
somthing like 91.0, I dont get it.

There is more to it then this like (slerp)
witch ill need to work on yet.That my help.

Function ComputQuat(pitch#,yaw#,roll#)
	; NB roll is inverted due to change in handedness of coordinate systems
	Local cr# = Cos(-roll/2)
	Local cp# = Cos(pitch/2)
	Local cy# = Cos(yaw/2)

	Local sr# = Sin(-roll/2)
	Local sp# = Sin(pitch/2)
	Local sy# = Sin(yaw/2)

	; These variables are only here to cut down on the number of multiplications
	Local cpcy# = cp * cy
	Local spsy# = sp * sy
	Local spcy# = sp * cy
	Local cpsy# = cp * sy

	; Generate the output quat
	qw# = cr * cpcy + sr * spsy
	qx# = sr * cpcy - cr * spsy
	qy# = cr * spcy + sr * cpsy
	qz# = cr * cpsy - sr * spcy
End Function



Drago(Posted 2003) [#4]
I had to modify that above code to get my smd2b3d program working 100%, since it didn't generate the correct values.

Function EulerToQuat(out.Quat, src.Rotation)
	; NB roll is inverted due to change in handedness of coordinate systems
	Local cr# = Cos(-src\roll/2)
	Local cp# = Cos(-src\pitch/2)
	Local cy# = Cos(src\yaw/2)

	Local sr# = Sin(-src\roll/2)
	Local sp# = Sin(-src\pitch/2)
	Local sy# = Sin(src\yaw/2)

	; These variables are only here to cut down on the number of multiplications
	Local cpcy# = cp * cy
	Local spsy# = sp * sy
	Local spcy# = sp * cy
	Local cpsy# = cp * sy

	; Generate the output quat
	out\w = cr*cp*cy+sr*sp*sy
	out\x = sr*cp*cy-cr*sp*sy
	out\y = cr*sp*cy+sr*cp*sy
	out\z =	cr*cp*sy-sr*sp*cy
	out\z = -out\z

End Function


EDIT: Oh, here are the two types that where sent to it :)
Type Rotation
	Field pitch#, yaw#, roll#
End Type

Type Quat
	Field w#, x#, y#, z#
End Type



JoshK(Posted 2003) [#5]
maths3d.dll will handle this


Stickman(Posted 2003) [#6]
Thanks Drago,
The origanal code I tryed before I even posted this was very simaller,but I couldn't get results.
After serching the code arcives I saw a code simmaler ( the one posted earlier ) and well like I said it works its just that the acruacy is not there.
Gona have to take a good hard look at your code and my origanal one to see where I may have made any mistakes.

Rockstar Where can I get that? Id like to try it.


My Origanal Attempt From the Book( Tricks of the 3D Game Programming Gurus )pg.449

where Theta_?# = pitch,yaw,roll acordingly.
Function ComputQuat( theta_x#,theta_y#,theta_z# )

cos_z_2# = 0.5*Cos( -theta_z/2 )
cos_y_2# = 0.5*Cos( theta_y/2 )
cos_z_2# = 0.5*Cos( theta_x/2 )
sin_z_2# = 0.5*Sin( -theta_z/2 )
sin_y_2# = 0.5*Sin( theta_y/2 )
sin_z_2# = 0.5*Sin( theta_x/2 )

qw#= cos_z_2*cos_y_2*cos_x_2 + sin_z_2*sin_y_2*sin_x_2 
qx#= cos_z_2*cos_y_2*sin_x_2 - sin_z_2*sin_y_2*cos_x_2 
qy#= cos_z_2*sin_y_2*cos_x_2 + sin_z_2*cos_y_2*sin_x_2 
qz#= sin_z_2*cos_y_2*cos_x_2 - cos_z_2*sin_y_2*sin_x_2

End Function