TOKRB_AddSensor(RigidBody%,PosX#,PosY#,PosZ#,DirX#,DirY#,DirZ#) |
Parameters: RigidBody% = Rigid Body handle PosX# = X component of position of the sensor local to the rigid body PosY# = Y component of position of the sensor local to the rigid body PosZ# = Z component of position of the sensor local to the rigid body DirX# = X component of the end of the sensor's line local to the sensor's position and the rigid body's orientation DirY# = Y component of the end of the sensor's line local to the sensor's position and the rigid body's orientation DirZ# = Z component of the end of the sensor's line local to the sensor's position and the rigid body's orientation |
Return value: Handle of the sensor, for later manipulation |
Description: Adds a sensor to a rigid body. A sensor is similar to a blitz linepick except that they are internal to tokamak, and as suck linepick tokamak geometries and static mesh. It's probably faster as well because of this, so you could probably use it for input into your AIs in a car racing game, or to figure out the thrust in a hovercraft game based on the distance from the ground. |
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 |