; Physics soft bodies example (an ArcBasic extension) ; A flag of cloth pinned to a pole, a balloon and a blob of jelly. ; Space: a gust of wind B: drop the balloon again J: squash the jelly Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,4,-11 TurnEntity camera,12,0,0 light=CreateLight() RotateEntity light,50,30,0 ground=CreatePlane() EntityColor ground,70,90,70 EntityPhysics ground,1 ; the flag: a grid of vertices, pinned along the edge at the pole pole=CreateCylinder(8) ScaleEntity pole,.08,3,.08 PositionEntity pole,-4,3,0 EntityPhysics pole,1 Const N=12 flag=CreateMesh() surf=CreateSurface(flag) For y=0 To N For x=0 To N AddVertex surf,-3.9+x*3.0/N,5.8-y*2.0/N,0,x/Float(N),y/Float(N) Next Next For y=0 To N-1 For x=0 To N-1 v=y*(N+1)+x AddTriangle surf,v,v+1,v+N+2 AddTriangle surf,v,v+N+2,v+N+1 Next Next UpdateNormals flag EntityColor flag,230,60,80 EntityFX flag,16 EntitySoftBody flag,1,.9 For y=0 To N SoftBodyPin flag,y*(N+1) Next ; a balloon: a closed mesh with air pressure inside, and a shelf for it to land on shelf=CreateCube() ScaleEntity shelf,.6,.6,.6 PositionEntity shelf,1.5,.6,0 EntityPhysics shelf,1 balloon=CreateSphere(12) PositionEntity balloon,1.5,5,0 EntityColor balloon,80,160,255 EntitySoftBody balloon,1,.6,3 ; jelly: a squashed ball, soft and only lightly filled, so it wobbles ; (soft bodies bend at their vertices: a plain cube has too few to wobble) jelly=CreateSphere(12) ScaleEntity jelly,1,.6,1 PositionEntity jelly,4.5,.6,0 EntityColor jelly,120,255,120 EntityAlpha jelly,.8 EntitySoftBody jelly,1,.4,2.5 While Not KeyHit(1) ; a light breeze all the time, and a gust while Space is held If KeyDown(57) Then ApplyForce flag,0,0,6 Else ApplyForce flag,1,0,.6 If KeyHit(48) FreeEntity balloon balloon=CreateSphere(12) PositionEntity balloon,1.5,5,0 EntityColor balloon,80,160,255 EntitySoftBody balloon,1,.6,3 EndIf If KeyHit(36) Then ApplyImpulse jelly,0,-8,0 UpdateWorld RenderWorld Text 0,0,"Space: gust of wind B: drop the balloon again J: squash the jelly" Flip Wend End