TOKSENSOR_GetDetectContactPointZ(Sensor%)
Parameters:
Sensor% = The sensor's handle
Return value:
The Z component of the first contact point's position
Description:
Retrieves the position of the first contact point. NOTE: This value is only available if TOKSENSOR_GetDetectDepth() is greater than 0.
Demo that came with the new wrapper version showing how to use a sensor

Const FPS=90

Graphics3D 800,600,0,2
SetBuffer BackBuffer()

Wireframe False

camera = CreateCamera()
PositionEntity camera,0,10,-50

TOKSIM_CreateSimulator(0,-10,0)

SeedRnd Millisecs()  

ground = CreateCube()
ScaleEntity ground,50,5,50
PositionEntity ground,0,-5,0
abground = TOKAB_Create()
TOKAB_AddBox abground,100.0,10.0,100.0
TOKAB_SetPosition abground,0.0,-5.0,0.0
EntityColor ground,Rnd(50,130),Rnd(50,130),Rnd(50,130)

obj = CreateCube()
ScaleEntity obj,1,0.1,1

rb = TOKRB_Create()
TOKRB_AddBox rb,2.0,0.2,2.0
TOKRB_SetPosition rb,0.0,5.0,0
TOKRB_SetLinearDamping rb,0.005
TOKRB_SetAngularDamping rb,0.02
TOKRB_SetMass rb,1.0
TOKRB_SetBoxInertiaTensor rb,2.0,0.2,2.0,1.0  
EntityColor obj,Rnd(100,230),Rnd(100,230),Rnd(100,230)

; Visualise the sensor with a cylinder
sensormesh=CreateCylinder(8,True,obj)
ScaleEntity sensormesh,0.1,4,0.1
PositionEntity sensormesh,0,-2.8,1

; Create the actual sensor
sensor = TOKRB_AddSensor(rb,0,0,1,0,-1.0,0)

Centerpivot = CreatePivot()

light=CreateLight()
PositionEntity light,7,15,-5
PointEntity light,Centerpivot
rot#=90

period=1000/FPS
time=Millisecs()-period

imptime=Millisecs()
; MainLoop
While Not KeyHit(1)

  Repeat
    elapsed=Millisecs()-time
  Until elapsed

  ticks=elapsed/period
  tween#=Float(elapsed Mod period)/Float(period)

  For k=1 To ticks
    time=time+period
    If k=ticks Then CaptureWorld

    TOKSIM_Advance(1.5/FPS,1)

camx#=Cos(rot#)*10
camz#=Sin(rot#)*10

;rot#=rot#+0.5

If rot#>360 Then rot#=0

PositionEntity camera,camx#,5.0,camz#
PointEntity camera,centerpivot  

  DetectDepth#=TOKSENSOR_GetDetectDepth#(sensor)

  If DetectDepth>0.0 Then
   TOKRB_ApplyImpulse2 rb,0,0.3*DetectDepth#,0,TOKSENSOR_GetDetectContactPointX#(sensor),TOKSENSOR_GetDetectContactPointY#(sensor),TOKSENSOR_GetDetectContactPointZ#(sensor)  
   EntityColor sensormesh,255,0,0
  Else
   EntityColor sensormesh,255,255,255
  EndIf

  UpdateWorld

  Next

PositionEntity obj,TOKRB_GetX(rb),TOKRB_GetY(rb),TOKRB_GetZ(rb)
RotateEntity obj,TOKRB_GetPitch(rb),TOKRB_GetYaw(rb),TOKRB_GetRoll(rb),False
  
If KeyHit(57) Then
  TOKRB_ApplyImpulse rb,0,5,0
EndIf

  RenderWorld tween



Text 0,10,"Render Time:"+Str(elapsed)+ " milliseconds"
Text 0,20,"Sensor DetectDepth:"+Str(TOKSENSOR_GetDetectDepth#(sensor))
  Flip False

Wend

TOKSIM_DestroySimulator()

End



Documentation generated by Cod2Doc on 20 Jun 2004.