My first attempt with ODE : drag objects like in HL² (Ok, that's not really fun
).
sync on
sync rate 60
randomize timer()
ode start
ode set world gravity 0.0,-9.81,0.0
rem Don't know exactly what it is
ode set world step 0.07
ode set world erp (0.2)*2.5
ode set world cfm (10^-5)*2.5
rem ground
make object box 1,400,10,400
ODE CREATE STATIC BOX 1
ode set contact fdir1 1, 2
rem objects
maxi=25
for o=2 to maxi
create_object(o,rnd(1))
next o
rem shadows
set shadow position 0,-150,400,-200
set point light 0,-150,400,-200
do
text 0,0,"Mouse buttons to play :)"
mx=mousex()
my=mousey()
rem rotate/move camera
ax#=wrapvalue(ax#+mousemovey()*0.2)
ay#=wrapvalue(ay#+mousemovex()*0.2)
rotate camera ax#,ay#,0
move camera (upkey()-downkey())*5
rem cam coords
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
rem TURN
if mouseclick()=1
if mc=0
mc=1
rem select an object
pick=pick object(mx,my,2,maxi)
if pick>0
rem random angular velocity
ODE SET ANGULAR VELOCITY pick,rnd(2.0)-1,rnd(2.0)-1,rnd(2.0)-1
endif
endif
else
mc=0
endif
rem DRAG
if mouseclick()=2
drag=1
if lmc=0
rem if we haven't got any object
lmc=1
rem pick an object
pick=pick object(mx,my,2,maxi)
if pick>0
rem distance camera/object
dist#=sqrt( (cx#-object position x(pick))^2+(cy#-object position y(pick))^2+(cz#-object position z(pick))^2 )
endif
endif
if pick>0
rem 3d mouse (based on the distance between the cam and the object)
pick screen mx,my,dist#
realx#=cx#+get pick vector x()
realy#=cy#+get pick vector y()
realz#=cz#+get pick vector z()
rem distance object/mouse
movex#=(realx#-object position x(pick))
movey#=(realy#-object position y(pick))
movez#=(realz#-object position z(pick))
rem set the velocity
ODE SET LINEAR VELOCITY pick,movex#,movey#,movez#
endif
else
lmc=0
drag=0
endif
rem move the object
dist#=dist#+mousemovez()/10.0
ode update
sync
loop
function create_object(obj,t)
x=rnd(300)-150
y=rnd(100)+100
z=rnd(300)-150
colour=rgb(rnd(255),rnd(255),rnd(255))
select t
case 0
sizex=20+rnd(40)
sizey=20+rnd(40)
sizez=20+rnd(40)
mass#=(sizex*sizey*sizez)^(1.0/3.0)
make object box obj,sizex,sizey,sizez
position object obj,x,y,z
ode create dynamic box obj
endcase
case 1
size=rnd(10)+10 : mass#=size/10.0
make object sphere obj,size
position object obj,x,y,z
ode create dynamic sphere obj
endcase
endselect
ODE SET BODY MASS obj,mass#/30.0
ode set contact fdir1 obj, 1+rnd(5)
color object obj,colour
set shadow shading on obj,-1,400,1
endfunction