this is a fun one
you don't need to use the PITCH OBJECT commands. using sin and cos is all you need. oh, the joys of math.
` setup for the program
sync on
sync rate 50
` constants to use throughout the code
#constant SUN 1
#constant PLANET 2
#constant MOON 3
` create the planets
make object sphere SUN, 20 : color object SUN, rgb(255,255,128)
make object sphere PLANET, 5 : color object PLANET, rgb(0,0,192)
make object sphere MOON, 1 : color object MOON, rgb(0,255,255)
` some vars we need in the program
Planet_Angle# = 0
Moon_Angle# = 0
StartTime = timer()
` main loop
do
if timer() > StartTime + 20
` we only want to do this so many times a second
StartTime = timer()
` every frame, we'll adjust the angle of the objects as they pertain to
` one another. the planet's angle is from the sun, and the moon's angle
` is from the planet. the moon moves slower, in the opposite direction.
inc Planet_Angle#, 3.0
dec Moon_Angle#, 2.0
` calculate the positions of the planet
x# = (sin(wrapvalue(Planet_Angle#)) * 15.0) + object position x(SUN)
y# = (sin(wrapvalue(Planet_Angle#)) * 4.0) + object position y(SUN)
z# = (cos(wrapvalue(Planet_Angle#)) * 15.0) + object position z(SUN)
position object PLANET, x#, y#, z#
` now, calculate the positions of the moon...note that the y angle of
` the moon is inversed for effect
x# = (sin(wrapvalue(Moon_Angle#)) * 5.0) + object position x(PLANET)
y# = (sin(360-wrapvalue(Moon_Angle#)) * 1.5) + object position y(PLANET)
z# = (cos(wrapvalue(Moon_Angle#)) * 5.0) + object position z(PLANET)
position object MOON, x#, y#, z#
` update the camera
set camera to follow object position x(SUN), object position y(SUN), object position z(SUN), 0, 80, 5, 10, 0
sync
endif
loop
-= i only do what my rice krispies tell me to do =-