; PhysicsBodyDamping Example ; -------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,2,-7 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 50,50,50 ; Zero gravity so damping is the only thing slowing the crate world=CreatePhysicsWorld() PhysicsGravity world,0,0,0 ; Orange crate floating at the centre of the scene crate=CreateCube() ScaleEntity crate,0.75,0.75,0.75 PositionEntity crate,0,1.5,0,True EntityColor crate,255,120,70 crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC) crate_shape=PhysicsBodyBox(crate_body,1.5,1.5,1.5,1) ; Start with moderate damping and a healthy spin damping#=0.3 PhysicsBodyDamping crate_body,damping,damping PhysicsBodyAngularVelocity crate_body,1,4,0 While Not KeyDown(1) ; [ and ] change the damping value If KeyHit(26) And damping>0.05 Then damping=damping-0.1 If KeyHit(27) And damping<2 Then damping=damping+0.1 ; Apply the current damping to the body every frame PhysicsBodyDamping crate_body,damping,damping ; Space spins the crate up again so you can watch it decay If KeyHit(57) Then PhysicsBodyAngularVelocity crate_body,1,4,0 ; Advance the Box3D simulation by one 60 Hz step StepPhysics world,1.0/60.0,4 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: spin crate [ / ]: damping Arrow keys: camera Esc: exit" Text 0,20,"PhysicsBodyDamping crate,"+damping+","+damping Text 0,40,"Spin speed Y: "+PhysicsBodyAngularVelocityY(crate_body)+" rad/s" Flip Wend FreePhysicsWorld world FreeEntity crate End