Show & Tell Time
edit: image deleted
I have been working on a Bullets Physics Library wrapper and have attached a zipped .exe of it working with DBPro. I'm using the latest Bullet 2.77 Physics SDK to make the wrapper dll from.
My plans are doing more than just doing a physics wrapper. But, I am stuck at the moment with the bullet physics because of two little problems that's pestering me.
First, as you can see in the picture above, the text output is suppose to show the x,y,z locations of each rigidbody box. Somehow when I apply the motionstate's trans matrix to the dbpro object, it positions and rotates the box perfectly, but I then no longer able to get the dbpro commands to report the x,y,z locations.
Second, because of directly applying the physic's matrix to the dbpro's object, somehow the culling of the object's gets all mucked up when moving the camera around. Thus, I have the attached example to show what I mean.
* I'm getting familiar with the DBPro Open Source Code from Google Code. Even though obviously different, I'm trying to look at the implemented ODE Physics on how it deals with updating DBPro objects. It's like I need to update other internal dbpro structures to be able to get this fix'd...
* use W,A,S,D to move around and press the right mouse button to rotate the camera. Esc to end program.
* I do plan on having this physics library itself for free.
Here's the code for this program to look at. The current physic command list at top of it. The dlls I use are not publicly available yet.
`BT STEP SIMULATION==DynamicsWorldID,DeltaTime#
`BT NEW DEFAULT COLLISION CONFIGURATION==Returns: DefaultCollisionConfigurationID
`BT NEW SEQUENTIALIMPULSE CONSTRAINTSOLVER==Returns: ConstraintSolverID
`BT AXIS SWEEP3==(Vector3_worldAabbMin,Vector3_worldAabbMax,maxProxies),Returns: BroadphaseInterfaceID
`BT NEW COLLISION DISPATCHER==(DefaultCollisionConfigurationID),Returns: CollisionDispatcherID
`BT NEW DISCRETE DYNAMICS WORLD==(CollisionDispatcherID,BroadphaseInterfaceID,ConstraintSolverID,DefaultCollisionConfigurationID),Returns: DynamicsWorldID
`BT NEW DEFAULT MOTION STATE==(Vector3_Position,yaw#,pitch#,roll#),Returns: MotionStateID
`BT NEW BOX SHAPE==(Vector3_Size),Returns: CollisionShapeID
`BT CALCULATE LOCAL INERTIA==CollisionShapeID,mass#,Vector3Result
`BT ADD RIGIDBODY==(DynamicsWorldID,mass#,MotionStateID,CollisionShapeID,Vector3_LocalInertia),Returns: RigidBodyID
`BT POSITION OBJECT TO RIGIDBODY==ObjectID,RigidBodyID
global global_UserControlMouseClickIs2 as integer
global Global_Position as integer
global Global_Rotation as integer
global Global_Size as integer
global Global_localInertia as integer
#CONSTANT SHAPE_BOX 1
#CONSTANT SHAPE_CUBE 2
Type RigidBodyType
RigidBodyID as DWORD
ObjectID as integer
EndType
DIM array_RigidBody(0) as RigidBodyType
sync on
sync rate 60
hide mouse
Set Window Position 0,0
Set Window Layout 0,0,0
`Maximize Window
set display mode DESKTOP WIDTH(),DESKTOP HEIGHT(),DWH DESKTOP DEPTH(), 0
`set display mode 640,480,DWH DESKTOP DEPTH(), 0
set window off
make camera 1
position camera 1,0,15,-400
color backdrop 1, rgb(32,64,64)
`New default Collision configuration
DefaultCollisionConfigurationID=BT NEW DEFAULT COLLISION CONFIGURATION()
`New default Constraint solver
ConstraintSolverID=BT NEW SEQUENTIALIMPULSE CONSTRAINTSOLVER()
`New axis sweep broadphase
worldAabbMin=DWH MAKE VECTOR3()
worldAabbMax=DWH MAKE VECTOR3()
SET VECTOR3 worldAabbMin,-1000,-1000,-1000
SET VECTOR3 worldAabbMax,1000,1000,1000
maxProxies = 32766;
BroadphaseInterfaceID=BT AXIS SWEEP3(worldAabbMin, worldAabbMax, maxProxies)
`New dispatcher
CollisionDispatcherID=BT NEW COLLISION DISPATCHER(DefaultCollisionConfigurationID)
`Finally create the dynamics world
DynamicsWorldID=BT NEW DISCRETE DYNAMICS WORLD(CollisionDispatcherID,BroadphaseInterfaceID,ConstraintSolverID,DefaultCollisionConfigurationID)
Global_Position=DWH MAKE VECTOR3()
Global_Size=DWH MAKE VECTOR3()
Global_localInertia=DWH MAKE VECTOR3()
RigidBody_Ground = CreateRigidBody(SHAPE_BOX,0,-10,0,1000,10,1000,0,0,"woodfloor1.bmp",10,10)
for local_i=1 to 10
RigidBody_Cube = CreateRigidBody(SHAPE_CUBE,0,230+(local_i*50),0,50,0,0,35.0,1,"metal1.bmp",1,1)
next
Global_Rotation=DWH MAKE VECTOR3()
repeat
DeltaTime# = DWH TIMER GET ELASPED TIME()
BT STEP SIMULATION DynamicsWorldID,DeltaTime#
UpdateRigidBodies()
UserControls(DeltaTime#)
text 1,1,str$(screen fps())
sync
until escapekey()=1
DWH DELETE VECTOR3 worldAabbMin
DWH DELETE VECTOR3 worldAabbMax
DWH DELETE VECTOR3 Global_Position
DWH DELETE VECTOR3 Global_Rotation
DWH DELETE VECTOR3 Global_Size
DWH DELETE VECTOR3 Global_localInertia
end
REM #############################################################
REM Functions
REM #############################################################
Function UserControls(DeltaTime#)
local_mmovex = mousemovex()
local_mmovey = mousemovey()
` Camera Control
`W=17
if (keystate(17)=1)
Move Camera 1,100.0*DeltaTime#
endif
`S=31
if (keystate(31)=1)
Move Camera 1,-100.0*DeltaTime#
endif
`A=30
if (keystate(30)=1)
DWH STRAFE CAMERA 1,-100.0*DeltaTime#
endif
`D=32
if (keystate(32)=1)
DWH STRAFE CAMERA 1,100.0*DeltaTime#
endif
if mouseclick()=2
if global_UserControlMouseClickIs2 = 0
global_UserControlMouseClickIs2 = 1
hide mouse
endif
position mouse screen width()/2, screen height()/2
` Get Current Anlges
local_CameraAngleX = Camera Angle X(1)
local_CameraAngleY = Camera Angle Y(1)
` create a rotation axis based on controller movement
local_CameraAngleX = WrapValue ( local_CameraAngleX + (local_mmovey) )
local_CameraAngleY = WrapValue ( local_CameraAngleY + (local_mmovex) )
` rotate camera
if ((( local_CameraAngleX >= 0 ) and ( local_CameraAngleX <= 90 )) or (( local_CameraAngleX >= 270 ) and ( local_CameraAngleX < 360 )))
XRotate Camera 1, local_CameraAngleX
endif
YRotate Camera 1, local_CameraAngleY
else
if mouseclick()=0 and global_UserControlMouseClickIs2 = 1
global_UserControlMouseClickIs2 = 0
position mouse screen width()/2, screen height()/2
show mouse
endif
endif
EndFunction
Function CreateRigidBody(ShapeType,PosX#,PosY#,PosZ#,SizeX#,SizeY#,SizeZ#,Mass#,Dynamic,ImageFileName$,ScaleU#,ScaleV#)
LOCAL local_image as integer = 0
LOCAL local_object as integer = 0
LOCAL local_RigidBodyCount as DWORD
ADD TO STACK array_RigidBody(0)
local_RigidBodyCount = ARRAY COUNT(array_RigidBody(0))
if ImageFileName$<>""
local_image = GetNewImageID()
endif
`Create Starting Motion State
SET VECTOR3 Global_Position,PosX#,PosY#,PosZ#
MotionStateID=BT NEW DEFAULT MOTION STATE(Global_Position,0,0,0)
`Create Collision Shape
if ShapeType=SHAPE_BOX then SET VECTOR3 Global_Size,SizeX#/2.0,SizeY#/2.0,SizeZ#/2.0
if ShapeType=SHAPE_CUBE then SET VECTOR3 Global_Size,SizeX#/2.0,SizeX#/2.0,SizeX#/2.0
CollisionShapeID=BT NEW BOX SHAPE(Global_Size)
`No Local Inertia and Mass=0 makes this body a static
if Dynamic=1
BT CALCULATE LOCAL INERTIA CollisionShapeID,Mass#,Global_localInertia ` localInertia is filled with a Vector3 Result
else
SET VECTOR3 Global_localInertia,0,0,0
endif
`Create Rigid Body and Add the new body to the dynamics world
array_RigidBody(local_RigidBodyCount).RigidBodyID=BT ADD RIGIDBODY(DynamicsWorldID,Mass#,MotionStateID,CollisionShapeID,Global_localInertia)
local_object = GetNewObjectID()
array_RigidBody(local_RigidBodyCount).ObjectID = local_object
if ShapeType=SHAPE_BOX then make object box local_object,SizeX#,SizeY#,SizeZ#
if ShapeType=SHAPE_CUBE then make object cube local_object,SizeX#
if local_image>0
load image ImageFileName$,local_image
texture object local_object,local_image
scale object texture local_object,ScaleU#,ScaleV#
endif
EndFunction local_ActorCount
Function UpdateRigidBodies()
LOCAL local_i as integer
LOCAL local_RBID as dword
LOCAL local_OID as integer
for local_i=1 to ARRAY COUNT(array_RigidBody(0))
local_RBID=array_RigidBody(local_i).RigidBodyID
local_OID=array_RigidBody(local_i).ObjectID
BT POSITION OBJECT TO RIGIDBODY local_OID,local_RBID
text 10,50+(local_i*20),"i="+Str$(local_i)+", x="+str$(object position x(local_OID))+", y="+str$(object position y(local_OID))+", z="+str$(object position z(local_OID))
next
EndFunction
Function GetNewImageID()
imageID=0
repeat
inc imageID
until image exist(imageID)=0
EndFunction imageID
Function GetNewObjectID()
ObjectID=0
repeat
inc ObjectID
until object exist(ObjectID)=0
EndFunction ObjectID