TOKAB_GetUserData(RigidBody%)
Parameters:
RigidBody%
Return value:
User data of the rigid body
Description:
Retrieves the user data of an animated body. User data is simply an integer that can be recalled whenever you have an animated body's handle. You can store pointers to banks, pointers to types, handles of other objects, or a plain number. In this way you can directly link an animated body to a type or bank instead of searching through them.
AnimatedBody = Animated body's handle
A demo using RB and AB user data to store type handles
Const Rigid_Bodies=2,Animated_Bodies=1
TOKSIM_SetRigidBodiesCount Rigid_Bodies
TOKSIM_SetAnimatedBodiesCount Animated_Bodies
TOKSIM_SetRigidParticleCount 0
TOKSIM_SetControllersCount 0
TOKSIM_SetGeometriesCount Rigid_bodies+Animated_Bodies ;Assuming each one only has one geometry.  Not true with more complex rigid bodies and animated bodies.
TOKSIM_CreateSimulator(0,-1,0)

Graphics3D 640,480
;Setup the scene

ColBank=CreateBank(208)
TOKSIM_SetCInfoBank ColBank

l=CreateLight()

cam=CreateCamera()

PositionEntity cam,0,1,-10

Type TokData
  Field Name$
End Type

t.tokdata=New tokdata
t\name$="Ground"

TOKSIM_SetCollisionResponse 2,1,3
TOKSIM_SetCollisionResponse 2,2,3

ground=TOKAB_Create()
TOKAB_AddBox ground,100,10,100
TOKAB_SetPosition ground,0,-5,0
TOKAB_SetUserData ground,Handle(t.tokdata)
groundr=CreateCube()
ScaleEntity groundr,50,5,50
PositionEntity groundr,0,-5,0
TOKRB_SetCollisionID ground,1

t.tokdata=New tokdata
t\name$="Ball"
obj=TOKRB_Create()
TOKRB_AddSphere obj,2
TOKRB_SetPosition obj,0,10,0
TOKRB_SetUserData obj,Handle(t)
objr=CreateSphere(8)
TOKRB_SetCollisionID obj,2

t.tokdata=New tokdata
t\name$="Box"
obj2=TOKRB_Create()
TOKRB_AddBox obj2,2,2,2
TOKRB_SetPosition obj2,2,8,0
TOKRB_SetUserData obj2,Handle(t)
obj2r=CreateCube()
TOKRB_SetCollisionID obj2,2

While Not KeyHit(1)
  TOKSIM_Advance .1,1
  PositionEntity objr,TOKRB_GetX(obj),TOKRB_GetY(obj),TOKRB_GetZ(obj)
  PositionEntity obj2r,TOKRB_GetX(obj2),TOKRB_GetY(obj2),TOKRB_GetZ(obj2)
  RotateEntity obj2r,TOKRB_GetPitch(obj2),TOKRB_GetYaw(obj2),TOKRB_GetRoll(obj2)
  If TOKSIM_GetCollisionCount()>0 Then
     For c=0 To TOKSIM_GetCollisionCount()-1
        If TOKCOL_TypeA(colbank,c)=2 Then a.tokdata=Object.tokdata(TOKAB_GetUserData(TOKCOL_bodyA(colbank,c))) ElseIf TOKCOL_TypeA(colbank,c)=1 Then a.tokdata=Object.tokdata(TOKRB_GetUserData(TOKCOL_bodyA(colbank,c)))
        If TOKCOL_TypeB(colbank,c)=2 Then b.tokdata=Object.tokdata(TOKAB_GetUserData(TOKCOL_bodyB(colbank,c))) ElseIf TOKCOL_TypeB(colbank,c)=1 Then b.tokdata=Object.tokdata(TOKRB_GetUserData(TOKCOL_bodyB(colbank,c)))
      If Abs(TOKCOL_RelativeVelocityY#(colbank,c))>1 Then DebugLog "The "+b\Name$+" hit the "+a\Name$
     Next
  EndIf
  RenderWorld
  Flip
Wend
TOKSIM_DestroySimulator

Function TOKCOL_bodyA(bank,index)
Return PeekInt(bank,index*104)
End Function

Function TOKCOL_bodyB(bank,index)
Return PeekInt(bank,index*104+4)
End Function

Function TOKCOL_TypeA(bank,index)
Return PeekInt(bank,index*104+8)
End Function

Function TOKCOL_TypeB(bank,index)
Return PeekInt(bank,index*104+8)
End Function

Function TOKCOL_RelativeVelocityY#(bank,index)
Return PeekFloat(bank,index*104+84)
End Function



Documentation generated by Cod2Doc on 20 Jun 2004.