PhysX for DarkBASIC Professional

Example 2 : Cloth Demo

In one of the cloth demos we get to see how cloth and rigid bodies interact with each other. A simple scene is created and you can then move a ball around. The cloth drapes over the ball smoothly and in real-time.

` shows how a cloth and ball react together

` set up program
phy start
sync on
sync rate 60
autocam off
color backdrop 0

` make attachment object
make object box 1,10,2,2
phy make rigid body static box 1

` create floor
make object box 2,50,1,50
color object 2,rgb(125,125,125)
position object 2,0,-9,0
phy make rigid body static box 2
load image "mediastripe6.png",2
texture object 2,2

` create background sphere
load image "mediastripe5.png",10
make object sphere 10,400,48,48
texture object 10,10
scale object texture 10,6,6
set object cull 10,0
rotate object 10,0,0,90

` create the cloth object
phy make cloth 3
phy set cloth dimensions 3, 10,10,0.2
phy set cloth position 3, -5, 0, 0
phy build cloth 3
phy attach cloth to shape 3, 1, 1
color object 3,rgb(125,125,255)
load image "mediarug512.bmp",  3
texture object 3, 3

` set up our ball object
make object sphere 4,5
color object 4,rgb(255,0,0)
position object 4,0,-5,1
set object ambient 4, 0
phy make rigid body dynamic sphere 4

` display Dark Physics logo
load image "medialogo.png",1000
sprite 1, 0, 600-60, 1000
set sprite 1, 0, 1
hide sprite 1

` position the camera
position camera 0,10,30
rotate camera 0,180,0
point camera 0,0,0

` our main program loop
do
   ` display instructions
   text 10,10, "Rigid body and cloth, use the arrow keys to move the ball"

   ` move ball around
   if upkey()=1 then phy set rigid body linear velocity 4, 0, 0, -5
   if downkey()=1 then phy set rigid body linear velocity 4, 0, 0, 5
   if leftkey()=1 then phy set rigid body linear velocity 4, 5, 0, 0
   if rightkey()=1 then phy set rigid body linear velocity 4, -5, 0, -0

   ` update simulation and screen
   phy update
   sync
loop

Return to the Examples List

Dark Physics Atari forever :)

© Copyright 2006 The Game Creators Ltd. All Rights Reserved.
PhysX and associated imagery are trade marks of Aegia Technologies Inc, used with permission.