Latest Version

BlitzMax Forums/MiniB3D Module/Latest Version

simonh(Posted 2006) [#1]
Latest Version: 0.52 - 5th Dec 08

Download from here.


simonh(Posted 2008) [#2]
Updated. Adds LoadAnimSeq and fixes bone memory leak.


matty47(Posted 2008) [#3]
Quietly snuck that update in without a fanfare..................: )


*(Posted 2009) [#4]
si can ya please update the download with this change http://www.blitzbasic.com/Community/posts.php?topic=83935#947970

I know its only a small change but to keep changing it every download is a pain, I can imagine that it put a lot of people off from using minib3d as well.


slenkar(Posted 2009) [#5]
hey edzup how are you dealing with the gimble lock issue? You are making a spaceship game with minib3d?


*(Posted 2009) [#6]
Jeremy: well simply keep all rotation (XYZ) and rotate a pivot, store rotations, then rotate the camera. This for me eliminates gimbal lock, I did this first in DB and it works in minib3d too.


Warner(Posted 2009) [#7]
Here is a small test I did last week that uses quaternions to rotate objects. Maybe it can also help avoiding gimbal lock:

Example is at the bottom of the code.


slenkar(Posted 2009) [#8]
yes I stole some of that code to ask about it in this forum in another thread.here:http://www.blitzbasic.com/Community/posts.php?topic=84524

But when I integrated it into minib3d myself the parenting system broke (i see you have sone parenting code now, but minib3d's parent system is different) and I wasnt sure how to implement 'translateentity'

I though it might be faster if Simon integrate it himself because he is also using quaternions for the animation system, but no word from him yet.


*(Posted 2009) [#9]
I will post my new turn entity functions I have somewhere, they use quaternions for rotation :)

Import sidesign.minib3d'"..\minib3d.bmx"					'include the 

minib3d system

' TurnEntity quaternion example - mimics the effect of Blitz3D's TurnEntity with the global 

flag set to false

Strict

Graphics3D 640,480, 32

Local camera:TCamera=CreateCamera()
PositionEntity camera,0,0,-5

Local light:TLight=CreateLight()

Local cone:TMesh=CreateCone(4) ' create cone

While Not KeyDown( KEY_ESCAPE )
	If KeyDown( KEY_UP )=True Then EdzUpTurnEntity( Cone, -1, 0, 0, True )
	If KeyDown( KEY_DOWN )=True Then EdzUpTurnEntity( Cone, 1, 0, 0, True )
	If KeyDown( KEY_LEFT )=True Then EdzUpTurnEntity( Cone, 0, -1, 0, True )
	If KeyDown( KEY_RIGHT )=True Then EdzUpTurnEntity( Cone, 0, 1, 0, True )
	If KeyDown( KEY_Z )=True Then EdzUpTurnEntity( Cone, 0, 0, -1, True )
	If KeyDown( KEY_X )=True Then EdzUpTurnEntity( Cone, 0, 0, 1, True )
	
	RenderWorld
	Flip
Wend
End

Function EdzUpTurnEntity( Ent:TEntity, X:Float, Y:Float, Z:Float, Glob:Int = False )
'	Local P:Float = 0.0
'	Local Y:Float = 0.0
'	Local R:Float = 0.0
	Local Pitch:Float = 0.0
	Local Yaw:Float = 0.0
	Local Roll:Float = 0.0
	
	Local Quat:TQuaternion = EulerToQuat( 0.0, 0.0, 0.0 )		'create cone quat
	Local Turn_Quat:TQuaternion = EulerToQuat( 0.0, 0.0, 0.0 )	'create turn quat
	
	If Glob=False
		Quat = EulerToQuat( EntityPitch( Ent, True ), EntityYaw( Ent, True ), EntityRoll( Ent, True ) )	'Set Ent Quat
		Turn_Quat = EulerToQuat( X, Y, Z )		'Set turn quat
		Quat = MultiplyQuats( Quat, Turn_Quat )	'Multiply Entity quat with turn quat
		Quat = NormalizeQuat( Quat )			'normalise quat
		QuatToEuler2( Quat.x, Quat.y, Quat.z, Quat.w, Pitch, Yaw, Roll )	'Entity quat to euler
		RotateEntity Ent, Pitch, Yaw, Roll
	Else
		RotateEntity Ent, EntityPitch( Ent )+X, EntityYaw( Ent )+Y, EntityRoll( Ent )+Z
	EndIf
End Function

' Leadwerks function
Function EulerToQuat:TQuaternion(pitch#,yaw#,roll#)
	Local cr#=Cos(-roll#/2.0)
	Local cp#=Cos(pitch#/2.0)
	Local cy#=Cos(yaw#/2.0)
	Local sr#=Sin(-roll#/2.0)
	Local sp#=Sin(pitch#/2.0)
	Local sy#=Sin(yaw#/2.0)
	Local cpcy#=cp#*cy#
	Local spsy#=sp#*sy#
	Local spcy#=sp#*cy#
	Local cpsy#=cp#*sy#
	Local q:TQuaternion=New TQuaternion
	q.w#=cr#*cpcy#+sr#*spsy#
	q.x#=sr#*cpcy#-cr#*spsy#
	q.y#=cr#*spcy#+sr#*cpsy#
	q.z#=cr#*cpsy#-sr#*spcy#
	Return q
End Function

' Leadwerks function
Const QuatToEulerAccuracy#=0.001
Function QuatToEuler2(x#,y#,z#,w#,pitch# Var,yaw# Var,roll# Var)
	Local sint#=(2.0*w*y)-(2.0*x*z)
	Local cost_temp#=1.0-(sint#*sint#)
	Local cost#
	If Abs(cost_temp#)>QuatToEulerAccuracy
		cost#=Sqr(cost_temp#)
		Else
		cost#=0.0
	EndIf
	Local sinv#,cosv#,sinf#,cosf#
	If Abs(cost#)>QuatToEulerAccuracy
		sinv#=((2.0*y*z)+(2.0*w*x))/cost#
		cosv#=(1.0-(2.0*x*x)-(2.0*y*y))/cost#
		sinf#=((2.0*x*y)+(2.0*w*z))/cost#
		cosf#=(1.0-(2.0*y*y)-(2.0*z*z))/cost#
		Else
		sinv#=(2.0*w*x)-(2.0*y*z)
		cosv#=1.0-(2.0*x*x)-(2.0*z*z)
		sinf#=0.0
		cosf#=1.0
	EndIf
	pitch#=ATan2(sint#,cost#)
	yaw#=ATan2(sinf#,cosf#)
	roll#=-ATan2(sinv#,cosv#)
End Function

Function MultiplyQuats:TQuaternion(q1:TQuaternion,q2:TQuaternion)

	Local q:TQuaternion=New TQuaternion
	
	q.w = q1.w*q2.w - q1.x*q2.x - q1.y*q2.y - q1.z*q2.z
	q.x = q1.w*q2.x + q1.x*q2.w + q1.y*q2.z - q1.z*q2.y
	q.y = q1.w*q2.y + q1.y*q2.w + q1.z*q2.x - q1.x*q2.z
	q.z = q1.w*q2.z + q1.z*q2.w + q1.x*q2.y - q1.y*q2.x

	Return q

End Function

Function NormalizeQuat:TQuaternion(q:TQuaternion)

	Local uv#=Sqr(q.w*q.w+q.x*q.x+q.y*q.y+q.z*q.z)

	q.w=q.w/uv
	q.x=q.x/uv
	q.y=q.y/uv
	q.z=q.z/uv

	Return q

End Function

This works for me, will be testing it further as soon as I have login sorted and Server selection


slenkar(Posted 2009) [#10]
that seems to work pretty good thanks


*(Posted 2009) [#11]
Was wondering why Si didnt add it to the next release ;)


slenkar(Posted 2009) [#12]
have you ever had problems with Tformpoint?

It applies rotation to a matrix without using quaternions,
this could be the cause of a bug I was having with bullets being placed in the wrong place with Tformpoint.
Parenting also uses Turnentity instead of edzupturnentity which could easily be fixed by us.
Positionentity also applies rotation to a matrix without quaternions

@Warner, very good,
the parenting function needs a global flag to place and rotate the child


*(Posted 2009) [#13]
Never ever had a problem with TFormPoint, for me it works 100% of the time just like it does on Blitz3d. Also I dont have a problem with Parenting entities.


degac(Posted 2009) [#14]
edit: problem solved

I found this thread and I've update the source code to fix the bug.

Sorry, I think you need to update your source code.