The ragdoll commands in Dark Physics can be applied to meshes to create things such as characters, ropes etc. In this example we look at how the commands are used to create a rope with a ball attached to the end of it. The rope is released into the scene and smacks into a pile of bricks toppling them over.
rem uses a bone based model of a rope
rem and the ragdoll commands to create
rem a jointed rigid body structure that
rem uses mesh animation to create a
rem smooth rope that responds with full
rem physics awareness.
rem set up program
sync on : sync rate 60 : color backdrop rgb(0,0,0)
rem create physics and model
gosub _rope_make
rem position the camera
camr#=250.0 : camh#=170.0 : a#=45
rem main
do
`
rem camera
a#=a#+(mousemovex()/10.0)
camr#=camr#-(mousemovez()/10.0)
position camera sin(a#)*camr#,camh#,cos(a#)*(camr#*-1)
point camera 0,camh#/1.75,0
`
rem place light
set point light 0,object position x(150),object position y(150),object position z(150)
color light 0,rgb(255,255,0)
set light range 0,1000
`
rem cheap double the speed of physics
for quadruple=0 to 3 : phy update : next quadruple
`
rem update
sync
`
rem end loop
loop
_rope_make:
`
rem physics
phy start
`
rem create spot light
set normalization on
set ambient light 0
make light 1
set spot light 1,5,80
set light range 1,2000
position light 1,0,300,0
point light 1,0,0,0
`
rem create ground object
load object "Densefloor.X",100
load image "Densefloor.TGA",100
scale object 100,600,100,600
scale object texture 100,2,2
texture object 100,100
phy make rigid body static box 100
`
rem display the Dark Physics logo
load image "logo.png", 10000
sprite 1, 0, 0, 10000
size sprite 1,screen width(),60
`
rem make bone representation
make object sphere 10,2
make object box 11,10,0.1,0.2
make mesh from object 11,11
add limb 10,1,11
offset limb 10,1,5,0,0
make mesh from object 10,10
delete object 11
delete object 10
make object 10,10,0
hide object 10
`
rem create rag doll rope
load object "ropebones.X", 1
position object 1,0,230,0
rotate object 1,1,2,3
set object light 1,0
`
rem make seperate objects to represent the rope
objid=199
perform checklist for object limbs 1
cm=checklist quantity()
for c=1 to cm-1
`
rem info from bones
x#=limb position x(1,c-1)
y#=limb position y(1,c-1)
z#=limb position z(1,c-1)
rx#=limb direction x(1,c-1)
ry#=limb direction y(1,c-1)
rz#=limb direction z(1,c-1)
`
rem new obj
inc objid : if object exist(objid)=1 then delete object objid
`
rem only make capsules out of 'qualifying bones'
c$=checklist string$(c)
if c=1
rem make root object
make object cube objid,0.1
position object objid,x#,y#,z#
rotate object objid,rx#,ry#,rz#
phy make rigid body static box objid
else
if lower$(c$)<>"$noname$"
rem make capsule
make object box objid,10,1,1
position object objid,x#,y#,z#
rotate object objid,rx#,ry#,rz#
move object left objid,-5.0
phy make rigid body dynamic box objid
phy set rigid body mass objid,10
endif
endif
`
next c
`
rem JOINT SPECIFIC SECTION
rem join the seperate objects to make copy of the rope model
jid=0
for c=1 to cm-1
c$=checklist string$(c)
if c=1
link=c-1
else
if lower$(c$)<>"$noname$"
linkto=c-1 : a=200+link : b=200+linkto
inc jid : phy make revolute joint jid, a, b, 1, 0, 0, limb position x(1,linkto),limb position y(1,linkto),limb position z(1,linkto)
link=linkto
endif
endif
next c
rem add heavy ball to rope
make object sphere 150,20,30,30 : linkto=20
position object 150,limb position x(1,linkto),limb position y(1,linkto),limb position z(1,linkto)-11
color object 150,rgb(255,255,0)
set object emissive 150,rgb(128,128,0)
phy make rigid body dynamic sphere 150
phy set rigid body mass 150,2000
inc jid : phy make revolute joint jid, 150, 218, 1, 0, 0, limb position x(1,linkto),limb position y(1,linkto),limb position z(1,linkto)-20
scale object 150,150,150,150
`
rem RAGDOLL SPECIFIC SECTION
rem set the model to become a ragdoll model, and use the 'base physics object - the first capsule'
phy make rag doll 1, 1, 200
rem assign ragdoll model limbs to point to real world jointed physics objects
phy assign rag doll part 1, 0, 17, 201
phy assign rag doll part 1, 0, 16, 202
phy assign rag doll part 1, 0, 15, 203
phy assign rag doll part 1, 0, 14, 204
phy assign rag doll part 1, 0, 13, 205
phy assign rag doll part 1, 0, 12, 206
phy assign rag doll part 1, 0, 11, 207
phy assign rag doll part 1, 0, 10, 208
phy assign rag doll part 1, 0, 9, 209
phy assign rag doll part 1, 0, 8, 210
phy assign rag doll part 1, 0, 7, 211
phy assign rag doll part 1, 0, 6, 212
phy assign rag doll part 1, 0, 5, 213
phy assign rag doll part 1, 0, 4, 214
phy assign rag doll part 1, 0, 3, 215
phy assign rag doll part 1, 0, 2, 216
phy assign rag doll part 1, 0, 1, 217
phy assign rag doll part 1, 0, 0, 218
`
rem hide physics objects controlling tagdoll model
for o=200 to 218 : hide object o : next o
`
rem make a small brick wall
make object box 300,20,10,10 : objid=300
for y=0 to 9
st=0 : if y=1 or y=3 or y=5 or y=7 or y=9 then st=10
for x=0 to 3
inc objid : instance object objid,300
position object objid,((x-2)*21)+st,y*10,0
rotate object objid,0,rnd(10)/10.0,0
phy make rigid body dynamic box objid
phy set rigid body mass objid,50
next x
next y
`
return