Wanted to see if I could do Bullet Time during a DarkPhysics simulation
It worked pretty well, I just modified the explosion demo that came with DarkPhysics.
Use the arrow keys to fly around.
` Bullet Time camera modification, of the Physx eplosion demo code
` by - Bill R. - San Francisco.
` Arrow keys - fly camera around during Bullet Time freeze
` create a set of spheres and apply forces on them
` to create an explosion effect
` set up the program
sync on
sync rate 60
autocam off
color backdrop 0
backdrop off
phy start
make light 1
set directional light 1, -5,-5,5
` make the background
load image "stripe5.png",10000
make object sphere 10000,400,48,48
texture object 10000,10000
scale object texture 10000,6,6
set object cull 10000,0
ghost object on 10000, 0
rotate object 10000,0,0,90
load image "stripe6.png", 3
` make the floor object
make object box 1,40,1,40
phy make rigid body static box 1
ghost object on 1, 0
texture object 1, 3
` make the four walls
make object box 2,60,1,50
xrotate object 2,60
position object 2,0,20,-25
phy make rigid body static box 2
ghost object on 2, 0
texture object 2, 3
make object box 3,50,1,60
zrotate object 3,-60
position object 3,-25,20,0
phy make rigid body static box 3
ghost object on 3, 0
texture object 3, 3
make object box 4,60,1,50
xrotate object 4,-60
position object 4,0,20,25
phy make rigid body static box 4
ghost object on 4, 0
texture object 4, 3
make object box 5,50,1,60
zrotate object 5,60
position object 5,25,20,0
phy make rigid body static box 5
ghost object on 5, 0
texture object 5, 3
` set up the pile of spheres
levels = 4
xcount = 5
zcount = 5
boxID = 10
boxsize#=1.0
for l=0 to levels-1
lf#=l
for x=-xcount to xcount
for z=-zcount to zcount
make object sphere boxID, 1
position object boxID, x*2, boxsize#*lf# + 1, z*2
phy make rigid body dynamic sphere boxID
color object boxID, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular boxID, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power boxID, 255
set object ambient boxID,0
inc boxID
next z
next x
next l
global numBoxes as integer : numBoxes = boxID-1
` position the camera
position camera -20,20,-15
point camera 0,0,0
xcount = (xcount+1)*2000
zcount = (zcount+1)*2000
count = 0
` display the Dark Physics logo
load image "logo.png", 100000
sprite 1, 0, 600 - 60, 100000
` main program loop
do
phyflag=1 :`just a flag, whether to allow physx update or not
keypress=scancode()
camspeed#=camera position y()/50.0 :`rotate the camera the same speed, whether you're near or far the objects
` If a key is pressed, pause Physx updates, and move camera with arrow keys
if keypress>0
phyflag=0
if keypress= 200 :`up arrow
move camera camspeed#
point camera 0,0,0
endif
if keypress= 203 :`left arrow
turn camera right -90
move camera camspeed#
turn camera left -90
point camera 0,0,0
endif
if keypress= 205 :`down arrow
turn camera left -90
move camera camspeed#
turn camera right -90
point camera 0,0,0
endif
if keypress= 208 :`right arrow
move camera -camspeed#
point camera 0,0,0
endif
endif
` Update Physx if Bullet Time is not reqested
if phyflag=1
inc count
` automatic explosion
if count > 100 and object exist(500)=0
x# = (rnd(xcount)-xcount/2)/500.0
y# = (rnd(1000)+500)/1000.0
z# = (rnd(zcount)-zcount/2)/500.0
make object sphere 500,12
color object 500, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
position object 500,x#,y#,z#
set alpha mapping on 500,50
createExplosion(x#,y#,z#,180,12)
count = 0
explos = 100
endif
if explos>0
dec explos
scale object 500,explos,explos,explos
if explos=0 then delete object 500
endif
` update the simulation and screen only when arrow keys (Bullet Time) is not wanted
phy update
endif
sync
loop
function createExplosion(x#,y#,z#,force#,size#)
sqrSize# = size#*size#
rem cycle through all objects to receive the force
for i=2 to numBoxes
if Object exist(i)=1
difx# = (object position x(i)-x#)
dify# = (object position y(i)-y#)
difz# = (object position z(i)-z#)
dist# = difx#*difx# + dify#*dify# + difz#*difz#
rem if close enough, apply a force relative to objects distance from the exlposion
if dist#<sqrSize#
dist# = sqrt(dist#)
forcex# = difx#/dist# * force#*1
forcey# = dify#/dist# * force#*1
forcez# = difz#/dist# * force#*1
phy add rigid body force i,forcex#,forcey#,forcez#, 1
endif
endif
next i
endfunction