Phaelax, the only mistakes I found with your code were in the definitions of
maxTime and
t#. You forgot parentheses around
and then you should've declared
maxTime as a float to typecast the division but I understand you didn't test it out first.
I rewrote my example, so it now uses the system timer and not the number of frames to determine speed. The frame rate is now irrelevant. Also, I liked Phaelax's idea of creating a type for Satellites and incorporated it. The only real difference to the example is the method by which it keeps track of time. Here it is:
set display mode 1024,768,32,1
sync on
hide mouse
autocam off
#constant MilPerSimHour 100.0 `Actual milliseconds per simulation hour
type Satellite
Obj as integer
OriginX as float
OriginZ as float
OrbitPeriod as float `Hours per complete orbit
RotationPeriod as float `Hours per complete rotation
OrbitDistance as float
endtype
make object sphere 1,10,20,20 `Sun
make object sphere 2,3,6,6 `Planet
make object sphere 3,1,6,6 `Moon
Planet as Satellite
Planet.Obj=2
Planet.OriginX=0
Planet.OriginZ=0
Planet.OrbitPeriod=2613.528 `108.897 days
Planet.RotationPeriod=18.8
Planet.OrbitDistance=10
Moon as Satellite
Moon.Obj=3
Moon.OrbitPeriod=15
Moon.RotationPeriod=5
Moon.OrbitDistance=3
StartTime as dword
ElapsedTime as dword
position camera 0,0,30,0
point camera 0,0,0,0
StartTime=timer()
do
ElapsedTime=timer()-StartTime
`Convert the amount of actual time passed to simulation time
SimTime#=ElapsedTime/MilPerSimHour
`Calculate the planet's position around the sun
XPos#=Planet.OriginX+Planet.OrbitDistance*sin(360*((SimTime#%%Planet.OrbitPeriod)/Planet.OrbitPeriod))
ZPos#=Planet.OriginZ+Planet.OrbitDistance*cos(360*((SimTime#%%Planet.OrbitPeriod)/Planet.OrbitPeriod))
position object Planet.Obj,XPos#,0,ZPos#
yrotate object Planet.Obj,360*((SimTime#%%Planet.RotationPeriod)/Planet.RotationPeriod)
`Set the moon to orbit the planet
Moon.OriginX=object position x(Planet.Obj)
Moon.OriginZ=object position z(Planet.Obj)
`Perform the same calculations for the moon
XPos#=Moon.OriginX+Moon.OrbitDistance*sin(360*((SimTime#%%Moon.OrbitPeriod)/Moon.OrbitPeriod))
ZPos#=Moon.OriginZ+Moon.OrbitDistance*cos(360*((SimTime#%%Moon.OrbitPeriod)/Moon.OrbitPeriod))
position object Moon.Obj,XPos#,0,ZPos#
yrotate object Moon.Obj,360*((SimTime#%%Moon.RotationPeriod)/Moon.RotationPeriod)
sync
loop
end
And if you wanted that function to set orbit origins like you said, I recommend creating an array to store all of your satellites in and then write a function to access them by index number. Alas DBPro can't really pass pointers to a function. Something like this:
`Somewhere before the main loop
dim Satellites(10) as Satellite
`and then the function:
function SetSatelliteOrigin(num,x#,y#)
Satellites(num).OriginX=x#
Satellites(num).OriginY=y#
endfunction
Hope all this helps.
Edit: Forgot to mention that the example now shows a moon orbiting a planet as well, but you would've noticed that when you ran the code.
Another thing, if you set a satellite's OrbitPeriod or RotationPeriod to a negative number, it will orbit or rotate counter-clockwise.