Post by shaku on Nov 19, 2005 11:20:20 GMT -5
Let me know what you guys think. I tried to add in some explanations to help. The navigation is a little messed up also.
'r-sun = radius of sun, r-earth = radius-earth
const deg=40, r_sun=15, r_earth=3
'i,j used for integer iterations
'i-j-deg-s-e used for degree iterations
dim i,j,i_deg,j_deg,deg_s,x,z,deg_e,ps,pc
'makes arrays for circle 1 and 2 of sun
dim xy_sun#(deg+1)(2), xz_sun#(deg+1)(2)
'makes arrays for circle 1 and 2 of earth
dim xy_earth#(deg+1)(2), xz_earth#(deg+1)(2)
'camera position and direction
dim cX#, cY#, cZ#, cAngy#, cAngx#, cAngz#
'starts initial camera position
cZ#=175: cX#=100: cY#=75: cAngy#=35: cAngx#=-25
'for the coordinate system
'red = negative
'blue = positive
'p = pause
'w = forward
'a = left d = right
's = backward
'up key = rotate up
'left key = rotate left right key = rotate right
'down key = rotate down
' _/------\ 'used for elliptical movement
' -- b| --
' / | \
' ( -------)
' \ a /
' -- --
' \------/
const a=100, b=75
z=0
x=100
deg_e=0
while true
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity ()
glEnable(GL_Blend)
glRotatef (-cAngy#, 0, 1, 0) 'rotates cam around y-axis
glRotatef (-cAngx#, 1, 0, 0) 'x-axis
glRotatef (-cAngz#, 0, 0, 1) 'z-axis
glTranslatef (-cX#, -cY#, -cZ#) 'translates cam around x,y,z
gosub coordinate_system
glrotatef(deg_s,0,1,1) 'starts sun rotation
gosub coordpoints_sun
gosub makecircle_sun
glrotatef(deg_s,0,-1,-1) 'stops rotation so earths
'elliptical translation isn't messed up
gltranslatef(a*pc*sqrt(1 - ((z*z)/(b*b))), 0, b*ps*sqrt(1 - ((x*x)/(a*a))))
'this is the elliptical formula x^2/a^2 + z^2/b^2 = 1
'x and z are solved for in each of their spots
gosub coordpoints_earth
gosub makecircle_earth
SwapBuffers()
gosub movement
gosub pause
z=b*sind(deg_e)
x=a*cosd(deg_e)
ps=sind(deg_e) 'ps and pc causes the x and z values to change polarity
pc=cosd(deg_e) 'after 90/180 degrees
wend
coordinate_system:
glBegin(GL_LINES)
glColor3f(0,0,150)'blue = positive
glVertex3fv(vec3( 1000, 0, 0))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0, 0, 1000))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0, 1000, 0))
glVertex3fv(vec3( 0, 0, 0))
glColor3f(250,0,0) 'red = negative
glVertex3fv(vec3(-1000, 0, 0))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0, 0,-1000))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0,-1000, 0))
glVertex3fv(vec3( 0, 0, 0))
glEnd()
return
pause:
If KeyDown("P") then
deg_s = deg_s + 0 'stops the sun from rotating
deg_e = deg_e + 0 'stops earth from translating
else
deg_s = deg_s + 2 'for sun rotation
deg_e = deg_e + 1 'for earth rotation
endif
return
coordpoints_sun:
for i=0 to deg 'sets coord-values for circle in an array
for j=0 to deg
i_deg=i*9
j_deg=j*9
xy_sun#(i) = vec3(r_sun*cosd(i_deg),r_sun*sind(i_deg),0)
'creates points for circle in xy plane
xz_sun#(j) = vec3(r_sun*cosd(j_deg),0,r_sun*sind(j_deg))
'creates points for circle in xz plane
next
next
return
makecircle_sun:
glBegin (GL_LINES)
for j=0 to deg - 1
glColor3f(255,255,0)
glVertex3fv(xy_sun#(j))
glVertex3fv(xy_sun#(j+1))
glVertex3fv(xz_sun#(j))
glVertex3fv(xz_sun#(j+1))
next
glEnd ()
return
coordpoints_earth:
for i=0 to 40
for j=0 to 40
i_deg=i*9
j_deg=j*9
xy_earth#(i) = vec3(r_earth*cosd(i_deg) + x, r_earth*sind(i_deg), z)
xz_earth#(j) = vec3(r_earth*cosd(j_deg) + x, 0,r_earth*sind(j_deg) + z)
next 'the r-earth changes the amplitude of each circle
next 'r-earth=3 would give a diameter of 6
return
makecircle_earth:
glBegin (GL_LINES) '2 pts make a line
for j=0 to deg 'a bunch of lines make a circle
if (j < 40) then 'gets rid of line connecting origin t sphere
glColor3f(0,0,255) 'color3f=blue
glVertex3fv(xy_earth#(j)) 'Connect pt 1
glVertex3fv(xy_earth#(j+1)) 'to pt 2
glColor3f(0,255,0) 'color3f=green
glVertex3fv(xz_earth#(j)) 'Connect pt 1 to
glVertex3fv(xz_earth#(j+1)) 'pt 2 for other circle
endif
next
glEnd ()
return
movement: 'Used to move around in 3 dimensions
while syncTimer(100)
const f_t=5, f_r=3 'factor-translation, factor-rotation
if KeyDown ("W") then cX# = cX# - f_t*sind(cAngy#)
cZ# = cZ# - f_t*cosd(cAngy#)
cY# = cY# + f_t*sind(cAngx#)
endif
if KeyDown ("S") then cX# = cX# + f_t*sind(cAngy#)
cZ# = cZ# + f_t*cosd(cAngy#)
cY# = cY# - f_t*sind(cAngx#)
endif
if KeyDown ("D") then cX# = cX# + f_t*cosd(cAngy#)
cZ# = cZ# + f_t*sind(cAngy#)
endif
if KeyDown ("A") then cX# = cX# + f_t*sind(cAngy# - 90.0)
cZ# = cZ# + f_t*cosd(cAngy# - 90.0)
endif
if ScanKeyDown (VK_Right) then cAngy# = cAngy# - f_r: endif 'rotates left and right
if ScanKeyDown (VK_Left) then cAngy# = cAngy# + f_r: endif
if ScanKeyDown (VK_UP) then cAngx# = cAngx# + f_r: endif 'rotates up and down
if ScanKeyDown (VK_DOWN) then cAngx# = cAngx# - f_r: endif
wend
return
'r-sun = radius of sun, r-earth = radius-earth
const deg=40, r_sun=15, r_earth=3
'i,j used for integer iterations
'i-j-deg-s-e used for degree iterations
dim i,j,i_deg,j_deg,deg_s,x,z,deg_e,ps,pc
'makes arrays for circle 1 and 2 of sun
dim xy_sun#(deg+1)(2), xz_sun#(deg+1)(2)
'makes arrays for circle 1 and 2 of earth
dim xy_earth#(deg+1)(2), xz_earth#(deg+1)(2)
'camera position and direction
dim cX#, cY#, cZ#, cAngy#, cAngx#, cAngz#
'starts initial camera position
cZ#=175: cX#=100: cY#=75: cAngy#=35: cAngx#=-25
'for the coordinate system
'red = negative
'blue = positive
'p = pause
'w = forward
'a = left d = right
's = backward
'up key = rotate up
'left key = rotate left right key = rotate right
'down key = rotate down
' _/------\ 'used for elliptical movement
' -- b| --
' / | \
' ( -------)
' \ a /
' -- --
' \------/
const a=100, b=75
z=0
x=100
deg_e=0
while true
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity ()
glEnable(GL_Blend)
glRotatef (-cAngy#, 0, 1, 0) 'rotates cam around y-axis
glRotatef (-cAngx#, 1, 0, 0) 'x-axis
glRotatef (-cAngz#, 0, 0, 1) 'z-axis
glTranslatef (-cX#, -cY#, -cZ#) 'translates cam around x,y,z
gosub coordinate_system
glrotatef(deg_s,0,1,1) 'starts sun rotation
gosub coordpoints_sun
gosub makecircle_sun
glrotatef(deg_s,0,-1,-1) 'stops rotation so earths
'elliptical translation isn't messed up
gltranslatef(a*pc*sqrt(1 - ((z*z)/(b*b))), 0, b*ps*sqrt(1 - ((x*x)/(a*a))))
'this is the elliptical formula x^2/a^2 + z^2/b^2 = 1
'x and z are solved for in each of their spots
gosub coordpoints_earth
gosub makecircle_earth
SwapBuffers()
gosub movement
gosub pause
z=b*sind(deg_e)
x=a*cosd(deg_e)
ps=sind(deg_e) 'ps and pc causes the x and z values to change polarity
pc=cosd(deg_e) 'after 90/180 degrees
wend
coordinate_system:
glBegin(GL_LINES)
glColor3f(0,0,150)'blue = positive
glVertex3fv(vec3( 1000, 0, 0))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0, 0, 1000))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0, 1000, 0))
glVertex3fv(vec3( 0, 0, 0))
glColor3f(250,0,0) 'red = negative
glVertex3fv(vec3(-1000, 0, 0))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0, 0,-1000))
glVertex3fv(vec3( 0, 0, 0))
glVertex3fv(vec3( 0,-1000, 0))
glVertex3fv(vec3( 0, 0, 0))
glEnd()
return
pause:
If KeyDown("P") then
deg_s = deg_s + 0 'stops the sun from rotating
deg_e = deg_e + 0 'stops earth from translating
else
deg_s = deg_s + 2 'for sun rotation
deg_e = deg_e + 1 'for earth rotation
endif
return
coordpoints_sun:
for i=0 to deg 'sets coord-values for circle in an array
for j=0 to deg
i_deg=i*9
j_deg=j*9
xy_sun#(i) = vec3(r_sun*cosd(i_deg),r_sun*sind(i_deg),0)
'creates points for circle in xy plane
xz_sun#(j) = vec3(r_sun*cosd(j_deg),0,r_sun*sind(j_deg))
'creates points for circle in xz plane
next
next
return
makecircle_sun:
glBegin (GL_LINES)
for j=0 to deg - 1
glColor3f(255,255,0)
glVertex3fv(xy_sun#(j))
glVertex3fv(xy_sun#(j+1))
glVertex3fv(xz_sun#(j))
glVertex3fv(xz_sun#(j+1))
next
glEnd ()
return
coordpoints_earth:
for i=0 to 40
for j=0 to 40
i_deg=i*9
j_deg=j*9
xy_earth#(i) = vec3(r_earth*cosd(i_deg) + x, r_earth*sind(i_deg), z)
xz_earth#(j) = vec3(r_earth*cosd(j_deg) + x, 0,r_earth*sind(j_deg) + z)
next 'the r-earth changes the amplitude of each circle
next 'r-earth=3 would give a diameter of 6
return
makecircle_earth:
glBegin (GL_LINES) '2 pts make a line
for j=0 to deg 'a bunch of lines make a circle
if (j < 40) then 'gets rid of line connecting origin t sphere
glColor3f(0,0,255) 'color3f=blue
glVertex3fv(xy_earth#(j)) 'Connect pt 1
glVertex3fv(xy_earth#(j+1)) 'to pt 2
glColor3f(0,255,0) 'color3f=green
glVertex3fv(xz_earth#(j)) 'Connect pt 1 to
glVertex3fv(xz_earth#(j+1)) 'pt 2 for other circle
endif
next
glEnd ()
return
movement: 'Used to move around in 3 dimensions
while syncTimer(100)
const f_t=5, f_r=3 'factor-translation, factor-rotation
if KeyDown ("W") then cX# = cX# - f_t*sind(cAngy#)
cZ# = cZ# - f_t*cosd(cAngy#)
cY# = cY# + f_t*sind(cAngx#)
endif
if KeyDown ("S") then cX# = cX# + f_t*sind(cAngy#)
cZ# = cZ# + f_t*cosd(cAngy#)
cY# = cY# - f_t*sind(cAngx#)
endif
if KeyDown ("D") then cX# = cX# + f_t*cosd(cAngy#)
cZ# = cZ# + f_t*sind(cAngy#)
endif
if KeyDown ("A") then cX# = cX# + f_t*sind(cAngy# - 90.0)
cZ# = cZ# + f_t*cosd(cAngy# - 90.0)
endif
if ScanKeyDown (VK_Right) then cAngy# = cAngy# - f_r: endif 'rotates left and right
if ScanKeyDown (VK_Left) then cAngy# = cAngy# + f_r: endif
if ScanKeyDown (VK_UP) then cAngx# = cAngx# + f_r: endif 'rotates up and down
if ScanKeyDown (VK_DOWN) then cAngx# = cAngx# - f_r: endif
wend
return