I seem to be having a very annoying problem which I can't seem to fix. I'm creating a model which partially simulates newtonian physics and I set the camera rotation before the main loop to 110,0,162 respectively for X,Y and Z but as soon as the loop starts, it reverts back to 0,0,0 again and I seem to be stuck on how to fix this!
Also, I want to be able to add planets at all without having to manually modify the accelerations of every single other celestial body involved because it gets very tedious. Is there a way I can do this? The code I have so far is below. Some help on how to clean up the code would also be appreciated. Thank you.
set display mode 1152,864,32
draw to front
set text size 24
set text to bold
text 10,10,"Planet Simulator v0.9"
set text size 18
set text to normal
text 10,35,"Control camera pitch and yaw with arrow keys"
text 10,60,"Roll using the A and D keys"
text 10,85,"Left click to move forwards, right click to move back"
text 10, 135,"Press any key to continue"
suspend for key
position mouse 512,384
hide mouse
make camera 1
color backdrop 1,rgb(0,0,0)
position camera 1,512,-1941,551
make light 1
set light range 1,100000
fog off
set ambient light 0
draw to front
ax#=0
ay#=0
vx#=2.8
vy#=0
dx#=512
dy#=1800
a2x#=0
a2y#=0
v2x#=0
v2y#=0
d2x#=512
d2y#=384
a3x#=0
a3y#=0
v3x#=2.3
v3y#=0
d3x#=512
d3y#=2000
flag=0
flag2=0
flag3=0
flag4=0
rotate#=0
constant#=2
rotatex#=0
rotatey#=0
load image "D:\Ahmets\Stuff\Images\Vue D'esprit\Suntexture.jpg",1,0
load image "D:\Ahmets\Stuff\Images\Vue D'esprit\Planettexture1.jpg",2,1
load image "D:\Ahmets\Stuff\Images\Vue D'esprit\Startexture.jpg",3,1
load image "D:\Ahmets\Stuff\Images\Vue D'esprit\Asteroidtexture.jpg",4,1
make object sphere 1,600,30,30
make object sphere 2,35,30,30
make object sphere 3,50,30,30
set object light 1,0
fog off
texture object 1,1
scale object texture 1,1.5,1.5
texture object 2,2
texture object 3,2
set camera FOV 1,80
set camera range 1,1,100000
for a=5 to 355
make object sphere a,4+(rnd(10))
move object a,600
fix object pivot a
xrotate object a,rnd(360)
yrotate object a,85+rnd(10)
texture object a,4
next a
for p=1 to 3
fix object pivot p
next p
for b=356 to 1455
make object plain b,4+rnd(2),4+rnd(2)
color object b,rgb((b/10)+129,(b/10)+129,(b/10)+129)
position object b,512,384,0
fix object pivot b
rotate object b,rnd(360),rnd(360),rnd(360)
move object b,5000
next b
for c=1456 to 1463
make object sphere c,40+rnd(60),15,15
texture object c,2
position object c,d2x#,d2y#,0
next c
rotate camera 1,110,0,162
do
text 10,10,"X pos: " + str$(camera position x(1))
text 10,30,"Y pos: " + str$(camera position y(1))
text 10,50,"Z pos: " + str$(camera position z(1))
text 10,70,"X angle: " + str$(camera angle x(1))
text 10,90,"Y angle: " + str$(camera angle y(1))
text 10,110,"Z angle: " + str$(camera angle z(1))
rotate#=rotate#+0.1
x#=dx#-d2x#
y#=dy#-d2y#
x2#=d2x#-dx#
y2#=d2y#-dy#
x3#=d3x#-d2x#
y3#=d3y#-d2y#
x4#=d2x#-d3x#
y4#=d2y#-d3y#
x5#=dx#-d3x#
y5#=dy#-d3y#
x6#=d3x#-dx#
y6#=d3y#-dy#
ax#=constant#*((-4000*abs(x#))/(x#*((x#*x#)+(y#*y#))*(SQRT(1+((y#*y#)/(x#*x#)))))+(-60*abs(x5#))/(x5#*((x5#*x5#)+(y5#*y5#))*(SQRT(1+((y5#*y5#)/(x5#*x5#))))))
ay#=constant#*((-4000*abs(y#))/(y#*((x#*x#)+(y#*y#))*(SQRT(1+((x#*x#)/(y#*y#)))))+(-60*abs(y5#))/(y5#*((x5#*x5#)+(y5#*y5#))*(SQRT(1+((x5#*x5#)/(y5#*y5#))))))
a3x#=constant#*((-5000*abs(x3#))/(x3#*((x3#*x3#)+(y3#*y3#))*(SQRT(1+((y3#*y3#)/(x3#*x3#)))))+(-40*abs(x6#))/(x6#*((x6#*x6#)+(y6#*y6#))*(SQRT(1+((y6#*y6#)/(x6#*x6#))))))
a3y#=constant#*((-5000*abs(y3#))/(y3#*((x3#*x3#)+(y3#*y3#))*(SQRT(1+((x3#*x3#)/(y3#*y3#)))))+(-40*abs(y6#))/(y6#*((x6#*x6#)+(y6#*y6#))*(SQRT(1+((x6#*x6#)/(y6#*y6#))))))
a2x#=constant#*((-2*abs(x2#))/(x2#*((x2#*x2#)+(y2#*y2#))*(SQRT(1+((y2#*y2#)/(x2#*x2#)))))+(-2*abs(x4#))/(x4#*((x4#*x4#)+(y4#*y4#))*(SQRT(1+((y4#*y4#)/(x4#*x4#))))))
a2y#=constant#*((-2*abs(y2#))/(y2#*((x2#*x2#)+(y2#*y2#))*(SQRT(1+((x2#*x2#)/(y2#*y2#)))))+(-2*abs(y4#))/(y4#*((x4#*x4#)+(y4#*y4#))*(SQRT(1+((x4#*x4#)/(y4#*y4#))))))
vx#=vx#+ax#
dx#=dx#+vx#
vy#=vy#+ay#
dy#=dy#+vy#
v2x#=v2x#+a2x#
d2x#=d2x#+v2x#
v2y#=v2y#+a2y#
d2y#=d2y#+v2y#
v3x#=v3x#+a3x#
d3x#=d3x#+v3x#
v3y#=v3y#+a3y#
d3y#=d3y#+v3y#
position object 2,dx#,dy#,0
position object 1,d2x#,d2y#,0
position object 3,d3x#,d3y#,0
position light 1,d2x#,d2y#,0
rotate object 1,rotate#,(rotate#)/2,(rotate#)*2
rotate object 2,(rotate#)/3,rotate#,rotate#
rotate object 3,rotate#,rotate#,rotate#/3
if mouseclick()=1 then cameraz#=10
if mouseclick()=2 then cameraz#=-10
if mouseclick()=0 then cameraz#=0
if keystate(32)=1 then rotatex#=1
if keystate(30)=1 then rotatex#=-1
if keystate(32)=0 and keystate(30)=0 then rotatex#=0
if rightkey()=1 then camerax#=1
if leftkey()=1 then camerax#=-1
if rightkey()=0 and leftkey()=0 then camerax#=0
if upkey()=1 then rotatey#=-1
if downkey()=1 then rotatey#=1
if upkey()=0 and downkey()=0 then rotatey#=0
rotatex#=wrapvalue(rotatex#)
rotatey#=wrapvalue(rotatey#)
move camera 1,cameraz#
turn camera right 1,camerax#
pitch camera up 1,rotatey#
roll camera right 1,rotatex#
for a=5 to 355
position object a,d2x#,d2y#,0
xrotate object a,(object angle x(a)+0.2)
move object a,980+(8*a)
next a
position object 1456,d2x#-(700*cos(3*rotate#)),d2y#+(700*sin(3*rotate#)),0
position object 1457,d2x#-(900*cos(4*rotate#+40)),d2y#+(900*sin(4*rotate#+40)),0
position object 1458,d2x#-(1060*cos(2*rotate#+160)),d2y#+(1060*sin(2*rotate#+160)),0
position object 1459,d2x#-(1300*cos(2.4*rotate#+80)),d2y#+(1300*sin(2.4*rotate#+80)),0
position object 1460,d2x#-(1510*cos(1.7*rotate#+280)),d2y#+(1510*sin(1.7*rotate#+280)),0
position object 1461,d2x#-(1730*cos(2.9*rotate#+240)),d2y#+(1730*sin(2.9*rotate#+240)),0
position object 1462,d2x#-(1840*cos(3.7*rotate#+120)),d2y#+(1840*sin(3.7*rotate#+120)),0
position object 1463,d2x#-(2050*cos(3.3*rotate#+200)),d2y#+(2050*sin(3.3*rotate#+200)),0
loop