FINNMAN
I think this example will demonstrate how to attract all objects to a point. Specifically the Gravity function.
phy start
sync on
sync rate 0
set ambient light 60
autocam off
color backdrop 0
randomize timer()
GLOBAL n =100 rem number of objects adjust to taste and cpu speed
rem this makes an anchor object mainly so the camera has a position to lock onto
make object sphere 1, 10
position object 1, 0,0,0
phy make rigid body dynamic sphere 1
phy set rigid body mass 1, 10000
color object 1, rgb(rnd(255),rnd(255),rnd(2))
remstart
f# = 500.0 ' Force
'this section was to test a binary system
make object sphere 2, 10
position object 2, 500,100,0
phy make rigid body dynamic sphere 2
phy set rigid body mass 2, 10000
phy set rigid body linear velocity 2, rnd(f#) - f#/2, rnd(f#) - f#/2, rnd(f#) - f#/2
color object 2, rgb(rnd(2),rnd(255),rnd(255))
remend
f# = 10.0 ' Force
for i = 2 to n
make object cube i, 5
d# = 1000.0 ' distance
position object i, rnd(d#) - d#/2, rnd(d#) - d#/2, rnd(d#) - d#/2
phy make rigid body dynamic box i
phy set rigid body linear velocity i, rnd(f#) - f#/2, rnd(f#) - f#/2, rnd(f#) - f#/2
m# = rnd(500.0)+1 ' Mass
phy set rigid body mass i, m#
scale object i, m#,m#,m# ' just to show relative mass
color object i, rgb(rnd(255),rnd(255),rnd(255))
next i
phy set gravity 0, 0, 0
position camera 0, 0, 0, -1000
point camera 0, 0, 0, 0
null = make vector3(1)
do
for i = 1 to n
for j = 1 to n
if i <> j then Gravity(i,j) ' test every object againt every object
next j
next i
if controlkey() <> 0
position camera 0,object position x(1), object position y(1), object position z(1)
move camera 0, -800
' point camera 0,object position x(1), object position y(1), object position z(1)
endif
phy update
control camera using arrowkeys 0,1,1
text 10,10, str$(screen fps())
sync
loop
phy end
flush video memory
end
Function Gravity(Obj1,Obj2)
set vector3 1, object position x(Obj1) - object position x(Obj2), object position y(Obj1) - object position y(Obj2), object position z(Obj1) - object position z(Obj2)
normalize vector3 1, 1
rem multiply vector3 1, 5
m# = phy get rigid body mass(obj1)+ phy get rigid body mass(obj2)
phy add rigid body force Obj2, x vector3(1)*m#, y vector3(1)*m#, z vector3(1)*m#, 3
Endfunction
Codger
p.s I included the rest of the program as i really like the way it looks
System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem