Let me first say I used aleofjax's example of "6 DOF in OGL" in this thread:
http://www.freebasic.net/forum/posting. ... ly&t=12588
And just modified the control slightly and expanded on it to implement a ship object which I'm adding drawing routines for in a future release. So far the model loader loaders .dxf's quite nicely. I also added a much larger star field and didn't include the custom star model I have so I also used aleofjax's method for showing stars in my first attempts. My space universe now uses a basic triangular pyramid. I am currently working on adding bullets but I am having a very hard time with them. Right now the bullet is a red cube and Left-Clicking fires it off, but the vectors for it are far from working properly, maybe someone can give me a hint. I have finally added the beginnings of a pause menu which once completed will also double as the main menu. I need to now figure out the easiest way to implement printing. I have now added spherical planets with textures. Its coming along in the direction I want to and a lot faster than I thought it would. Please give any advice of constructive criticism you can.
I put the source below of the last working version without textures. I d this for some people to easily try the code quickly. The updated version will be in the ZIP file with a binary and the source. This ZIP file is accessible through the link at the end of the post.
TO-DO:
- Pause Menu
- Bullet Vector
- Larger basic polygon for planets
- Map file for planets (stars will remain random)
- Main Menu (after pause menu)
- Printing
The controls are as follows:
W/S = Forward/Reverse Thrust
Left SHIFT + W = Boosted Thrust Forward
A/D = Strafe Left/Right
R/F = Rise/Fall
Q/E = Rotate Counter-Clockwise/Clockwise
SPACE = Movement Brake
CONTROL = Rotation Brake
Mouse X/Y = Turn camera
Mouse Left-Click = Fire Bullet
P = Pause/Unpause
ESC = Quit
3d_space_scr.bas Download ZIP file for latest, this version is last standalone version without images!!!
Code: Select all
/' Axipher 2009
W = Accelerate
S = Deccelerate
Mouse = Angel
A/D = Strafe
R/F = Up/Down
space = Brake
Insert = reset
'/
' Randomize the randim number generator based on the timer
randomize timer
' TRUE/FALSE
const FALSE = 0
const TRUE = -1
' Define
#define starcolour 1.0,0.75,0.0,1.0
' Files to include
#include once "fbgfx.bi"
#include once "gl\gl.bi"
#include once "gl\glu.bi"
#include once "gl\glfw.bi"
#include once "draw_gl_.bi"
enum object_type
star = 1
projectile = 2
ship = 4
end enum
enum state_data
normal = 0
paused = 1
mainmenu = 2
credits = 3
end enum
' Some constants
const PI = 4 * atn(1)
const RAD = PI/180
const SHIP_ACC = 0.1
const SHIP_DBL_ACC = SHIP_ACC * 2
const SHIP_STRAFE = 0.1
const SHIP_RISE = 0.1
const SHIP_ROT = 0.1
const SHIP_DEC = 0.995
const SHIP_BRAKE = 0.97
const BULLET_SPEED = 10
' A few shared variables
dim shared as integer sx,sy,sf,sx2,sy2,keypressed,cursorvis,glx1,glx2,gly1,gly2
dim as double mouse_sensitivity = 0.6,mouse_threshold = 5
dim as double nextframe = timer + 1
dim shared as integer state
type mousedata
as integer x,ox,dx,px
as double cx
as integer y,oy,dy,py
as double cy
as integer b,w,pb,pw
declare constructor()
declare sub update(vis as integer = 0)
end type
constructor mousedata()
end constructor
sub mousedata.update(vis as integer = 0)
if state = normal then
ox = x
oy = y
getmouse x,y,w,b
dx = (x - ox)
dy = (y - oy)
cx = x - sx2
cy = y - sy2
setmouse sx2,sy2,0
elseif state = paused then
getmouse px,py,pw,pb
setmouse ,,1
end if
end sub
type vect6d
u as single
v as single
w as single
x as single
y as single
z as single
end type
type vector3d
as double x,ux
as double y,uy
as double z,uz
declare constructor()
declare property x2() as double
declare property y2() as double
declare property z2() as double
end type
constructor vector3d()
end constructor
property vector3d.x2() as double
return (x + ux)
end property
property vector3d.y2() as double
return (y + uy)
end property
property vector3d.z2() as double
return (z + uz)
end property
type quaternion
w as single
x as single
y as single
z as single
declare sub normalize()
declare function conj() as quaternion
end type
sub quaternion.normalize()
dim as single mag = sqr(w*w+x*x+y*y+z*z)
w /= mag
x /= mag
y /= mag
z /= mag
end sub
function quaternion.conj() as quaternion
return type<quaternion>( w, -x, -y, -z )
end function
Operator * (lhs as quaternion, rhs as quaternion) as quaternion
return type<quaternion>( lhs.w * rhs.w - lhs.x * rhs.x - lhs.y * rhs.y - lhs.z * rhs.z, _
lhs.w * rhs.x + lhs.x * rhs.w + lhs.y * rhs.z - lhs.z * rhs.y, _
lhs.w * rhs.y - lhs.x * rhs.z + lhs.y * rhs.w + lhs.z * rhs.x, _
lhs.w * rhs.z + lhs.x * rhs.y - lhs.y * rhs.x + lhs.z * rhs.w )
end Operator
type camera
'position
x as single
y as single
z as single
'look vector
lx as single
ly as single
lz as single
'up vector
ux as single
uy as single
uz as single
'right vector
rx as single
ry as single
rz as single
FOV as single
aspect as single
nearClip as single
farClip as single
declare sub roll( a as single )
declare sub pitch( a as single )
declare sub yaw( a as single )
declare sub advance( d as single )
declare sub strafe( d as single )
declare sub rise( d as single )
end type
sub camera.advance( d as single )
dim as single xt, yt, zt
xt = (lx - x) * d
yt = (ly - y) * d
zt = (lz - z) * d
x += xt
y += yt
z += zt
ux += xt
uy += yt
uz += zt
rx += xt
ry += yt
rz += zt
lx += xt
ly += yt
lz += zt
end sub
sub camera.strafe( d as single )
dim as single xt, yt, zt
xt = (rx - x) * d
yt = (ry - y) * d
zt = (rz - z) * d
x += xt
y += yt
z += zt
ux += xt
uy += yt
uz += zt
rx += xt
ry += yt
rz += zt
lx += xt
ly += yt
lz += zt
end sub
sub camera.rise( d as single )
dim as single xt, yt, zt
xt = (ux - x) * d
yt = (uy - y) * d
zt = (uz - z) * d
x += xt
y += yt
z += zt
ux += xt
uy += yt
uz += zt
rx += xt
ry += yt
rz += zt
lx += xt
ly += yt
lz += zt
end sub
sub camera.roll( a as single )
dim as quaternion qUp = type<quaternion>(0, ux - x, uy - y, uz - z)
dim as quaternion qRight = type<quaternion>(0, rx - x, ry - y, rz - z)
dim as quaternion qRot = type<quaternion>(cos(a * rad/2), (lx - x) * sin(a * rad/2), (ly - y) * sin(a * rad/2), (lz - z) * sin(a * rad/2))
dim as quaternion W = qRot * qUp * qRot.conj()
ux = W.x + x
uy = W.y + y
uz = W.z + z
W = qRot * qRight * qRot.conj()
rx = W.x + x
ry = W.y + y
rz = W.z + z
end sub
sub camera.pitch( a as single )
dim as quaternion qUp = type<quaternion>(0, ux - x, uy - y, uz - z)
dim as quaternion qLook = type<quaternion>(0, lx - x, ly - y, lz - z)
dim as quaternion qRot = type<quaternion>(cos(a * rad/2), (rx - x) * sin(a * rad/2), (ry - y) * sin(a * rad/2), (rz - z) * sin(a * rad/2))
dim as quaternion W = qRot * qUp * qRot.conj()
ux = W.x + x
uy = W.y + y
uz = W.z + z
W = qRot * qLook * qRot.conj()
lx = W.x + x
ly = W.y + y
lz = W.z + z
end sub
sub camera.yaw( a as single )
dim as quaternion qRight = type<quaternion>(0, rx - x, ry - y, rz - z)
dim as quaternion qLook = type<quaternion>(0, lx - x, ly - y, lz - z)
dim as quaternion qRot = type<quaternion>(cos(a * rad/2), (ux - x) * sin(a * rad/2), (uy - y) * sin(a * rad/2), (uz - z) * sin(a * rad/2))
dim as quaternion W = qRot * qRight * qRot.conj()
rx = W.x + x
ry = W.y + y
rz = W.z + z
W = qRot * qLook * qRot.conj()
lx = W.x + x
ly = W.y + y
lz = W.z + z
end sub
type object
as vector3d d,l,v
as object_type ot
as double scale
as integer alive
declare constructor()
declare sub update()
declare sub draw()
end type
constructor object()
d.x = 0
d.y = 0
d.z = 0
l.x = 0
l.y = 0
l.z = 0
v.x = 0
v.y = 0
v.z = 0
ot = star
scale = 1
end constructor
sub object.update()
if alive then
d.x += v.x
d.y += v.y
d.z += v.z
end if
end sub
sub object.draw()
if alive then
select case ot
case star
draw_gl_star(d.x,d.y,d.z,scale)
case projectile
draw_gl_projectile(d.x,d.y,d.z)
case ship
draw_gl_ship
end select
end if
end sub
type button
as integer x,y,sx,sy
as double glx,gly,glsx,glsy
as string label
as double r,g,b,t
declare constructor()
declare constructor(_glx as double,_gly as double,_glsx as double,_glsy as double)
declare sub draw(m as mousedata)
end type
constructor button()
end constructor
constructor button(_glx as double,_gly as double,_glsx as double,_glsy as double)
glx = _glx
gly = _gly
glsx = _glsx
glsy = _glsy
x = sx2 + ((glx / glx2) * sx2)
y = sy2 + ((gly / gly2) * sy2)
sx = ((glsx / glx2) * sx2)
sy = ((glsy / gly2) * sy2)
r = 0
g = 1
b = 0
end constructor
sub button.draw(m as mousedata)
if m.px >= x andalso m.px <= (x + sx) andalso m.py >= y andalso m.py <= (y + sy) then
t = 0.9
else
t = 0.5
end if
glcolor4f r,g,b,t
glbegin gl_quads
glvertex3f glx,gly,1
glvertex3f glx + glsx,gly,1
glvertex3f glx + glsx,gly + glsy,1
glvertex3f glx,gly + glsy,1
glend
end sub
' Open a console window
dim as integer cns
cns = freefile
open cons for output as #cns
' Get current screen resolution
screeninfo sx,sy
sf = fb.gfx_opengl or fb.gfx_multisample or fb.gfx_fullscreen
'sf = fb.gfx_opengl or fb.gfx_multisample
'sx = 1024
'sy = 600
' Calculate mid points
sx2 = sx / 2
sy2 = sy / 2
' Calculate 2D OpenGL coords
glx1 = -1.0 * (sx2 / sy2)
glx2 = 1.0 * (sx2 / sy2)
gly1 = -1.0
gly2 = 1.0
' Initialize the screen
'screenres sx,sy,32,,fb.gfx_fullscreen or fb.gfx_opengl or fb.gfx_multisample
screenres sx,sy,32,,sf
' Variable for mouse data
dim as mousedata mouse
' Objects for ship and one projectile
dim as object t1,b1
' Variable for the camera
dim shared as camera cam,pmenu
' Store the timer in a variable
dim as double lastFrame = timer
' Variables for calculations
dim as double xv, yv, zv, p, r, y
' Initialize the camera
cam.x = 0
cam.y = 0
cam.z = 0
cam.lx = 0
cam.ly = 0
cam.lz = -1
cam.ux = 0
cam.uy = 1
cam.uz = 0
cam.rx = 1
cam.ry = 0
cam.rz = 0
cam.FOV = 45
cam.Aspect = sx/sy
cam.nearClip = .01
cam.farClip = 30000
' Set ship location to 0,0,0 and looking into the screen
t1.d.x = 0
t1.d.y = 0
t1.d.z = 0
t1.l.x = 0
t1.l.y = 0
t1.l.z = 1
t1.v.x = 0
t1.v.y = 0
t1.v.z = 0
declare sub init_3D_gl()
declare sub init_2D_gl()
init_3D_gl
' Make a list of stars
dim as integer starcount = 5000
dim as object ptr starsptr
starsptr = allocate(sizeof(object) * starcount)
for i as integer = 0 to starcount - 1
starsptr[i].d.x = (rnd * 3000) + (rnd * 2000) + (rnd * 1000) - 3000
starsptr[i].d.y = (rnd * 3000) + (rnd * 2000) + (rnd * 1000) - 3000
starsptr[i].d.z = (rnd * 3000) + (rnd * 2000) + (rnd * 1000) - 3000
starsptr[i].ot = star
starsptr[i].scale = 10
starsptr[i].alive = true
next
' make a button object
dim as button but1
but1 = button(glx1 + 0.02,gly1 + 0.02,0.5,0.2)
' Init mouse
mouse.update
' Main loop
do
' Update mouse data
mouse.update
' Frame limiter
'Sleep (1000 / 30) - ((Timer - lastFrame) / 1000), 1
'lastFrame = Timer
'sleep 1,1
while timer < nextframe
sleep 1,1
wend
nextframe = timer + (1 / 60)
' Reset keypressed
if multikey(fb.sc_p) = 0 then keypressed = false
if state = paused then
' Pause game
if multikey(fb.sc_p) and keypressed = false then
state = normal
cursorvis = false
keypressed = true
setmouse sx2,sy2,0
end if
end if
if state = normal then
' Pause game
if multikey(fb.sc_p) and keypressed = false then
state = paused
cursorvis = true
keypressed = true
end if
windowtitle "Normal"
' A/D strafe left and right based on current direction
if multikey(fb.sc_a) and multikey(fb.sc_d) = 0 then
xv += (cam.rx - cam.x) * SHIP_STRAFE
yv += (cam.ry - cam.y) * SHIP_STRAFE
zv += (cam.rz - cam.z) * SHIP_STRAFE
end if
if multikey(fb.sc_d) and multikey(fb.sc_a) = 0 then
xv -= (cam.rx - cam.x) * SHIP_STRAFE
yv -= (cam.ry - cam.y) * SHIP_STRAFE
zv -= (cam.rz - cam.z) * SHIP_STRAFE
end if
' R/F move up and down based on current direction
if multikey(fb.sc_r) and multikey(fb.sc_f) = 0 then
xv -= (cam.ux - cam.x) * SHIP_RISE
yv -= (cam.uy - cam.y) * SHIP_RISE
zv -= (cam.uz - cam.z) * SHIP_RISE
end if
if multikey(fb.sc_f) and multikey(fb.sc_r) = 0 then
xv += (cam.ux - cam.x) * SHIP_RISE
yv += (cam.uy - cam.y) * SHIP_RISE
zv += (cam.uz - cam.z) * SHIP_RISE
end if
' W/S move forward or back depending on current direction
if multikey(fb.sc_w) and multikey(fb.sc_s) = 0 then
if multikey(fb.sc_lshift) then
xv += (cam.lx - cam.x) * SHIP_DBL_ACC
yv += (cam.ly - cam.y) * SHIP_DBL_ACC
zv += (cam.lz - cam.z) * SHIP_DBL_ACC
else
xv += (cam.lx - cam.x) * SHIP_ACC
yv += (cam.ly - cam.y) * SHIP_ACC
zv += (cam.lz - cam.z) * SHIP_ACC
end if
end if
if multikey(fb.sc_s) and multikey(fb.sc_w) = 0 then
xv -= (cam.lx - cam.x) * SHIP_ACC
yv -= (cam.ly - cam.y) * SHIP_ACC
zv -= (cam.lz - cam.z) * SHIP_ACC
end if
' Q/E to roll
if multikey(fb.sc_q) and multikey(fb.sc_e) = 0 then
r -= 2 * SHIP_ROT
end if
if multikey(fb.sc_e) and multikey(fb.sc_q) = 0 then
r += 2 * SHIP_ROT
end if
if multikey(fb.sc_q) = 0 and multikey(fb.sc_e) = 0 then
r *= 0.9
end if
' Braking
if multikey(fb.sc_space) then
xv *= ship_brake
yv *= ship_brake
zv *= ship_brake
end if
' Slow down rotation
if multikey(fb.sc_CONTROL) then
r *= ship_brake
p *= ship_brake
y *= ship_brake
end if
' Mouse determines direction of acceleration to be affected by thrust
' Allowed to rotate fully without thrusting
if abs(mouse.cx ) > mouse_threshold or abs(mouse.cy) > mouse_threshold then
p += (mouse.cy * mouse_sensitivity) / 8 * SHIP_ROT
y += (mouse.cx * mouse_sensitivity) / 8 * SHIP_ROT
else
p *= 0.9
y *= 0.9
end if
' Debug reset
if multikey(fb.sc_insert) then
xv = 0
yv = 0
zv = 0
r = 0
p = 0
y = 0
cam.x = 0
cam.y = 0
cam.z = 0
cam.lx = 0
cam.ly = 0
cam.lz = -1
cam.ux = 0
cam.uy = 1
cam.uz = 0
cam.rx = 1
cam.ry = 0
cam.rz = 0
cam.roll(r)
cam.pitch(p)
cam.yaw(y)
t1.d.x = 0
t1.d.y = 0
t1.d.z = 0
t1.l.x = 0
t1.l.y = 0
t1.l.z = -1
t1.v.x = 0
t1.v.y = 0
t1.v.z = 0
end if
' Natural decellearation
xv *= ship_dec
yv *= ship_dec
zv *= ship_dec
r *= ship_dec
p *= ship_dec
y *= ship_dec
' Adjust Camera
cam.x += xv
cam.y += yv
cam.z += zv
cam.lx += xv
cam.ly += yv
cam.lz += zv
cam.rx += xv
cam.ry += yv
cam.rz += zv
cam.ux += xv
cam.uy += yv
cam.uz += zv
cam.roll(r)
cam.pitch(p)
cam.yaw(y)
' Clamp ship to camera
t1.d.x = cam.x
t1.d.y = cam.y
t1.d.z = cam.z
t1.l.x = cam.lx
t1.l.y = cam.ly
t1.l.z = cam.lz
t1.v.x = cam.lx
t1.v.y = cam.ly
t1.v.z = cam.lz
' Fire projectile
if mouse.b and 1 then
b1 = object()
b1.ot = projectile
b1.d.x = cam.x
b1.d.y = cam.y
b1.d.z = cam.z
b1.v.x = (cam.lx - cam.x) * BULLET_SPEED
b1.v.y = (cam.ly - cam.y) * BULLET_SPEED
b1.v.z = (cam.lz - cam.z) * BULLET_SPEED
b1.alive = true
b1.update
else
b1.update
end if
end if
' Reset OpenGL buffers
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
glLoadIdentity
' Apply camera settings
gluLookAt cam.x, cam.y, cam.z, cam.lx, cam.ly, cam.lz, cam.x - cam.ux, cam.y - cam.uy, cam.z - cam.uz
'stars(i).x, stars(i).y + 0.5, stars(i).z + 0.5
'stars(i).x - 0.5, stars(i).y - 0.5, stars(i).z - 0.5
'stars(i).x + 0.5, stars(i).y - 0.5, stars(i).z - 0.5
'stars(i).x, stars(i).y - 0.5, stars(i).z + 0.5
' Draw stars
for i as integer = 0 to starcount - 1
starsptr[i].draw
next
' Draw bullet
b1.draw
' Draw a 3D cartesian grid
' glcolor3f 1,0,0
' glbegin gl_lines
' glvertex3f -1000,0,0
' glvertex3f 1000,0,0
' glEnd
' glcolor3f 0,1,0
' glbegin gl_lines
' glvertex3f 0,-1000,0
' glvertex3f 0,1000,0
' glEnd
' glcolor3f 0,0,1
' glbegin gl_lines
' glvertex3f 0,0,-1000
' glvertex3f 0,0,1000
' glEnd
if state = paused then
windowtitle "Paused"
init_2D_gl
glcolor4f 0,0,0,0.5
glbegin gl_quads
glvertex3f glx1,gly1,1
glvertex3f glx2,gly1,1
glvertex3f glx2,gly2,1
glvertex3f glx1,gly2,1
glend
glcolor4f 0.0, 1.0, 0.0, 0.9
glbegin gl_line_strip
glvertex3f glx1 + 0.01,gly1 + 0.01,1
glvertex3f glx2 - 0.01,gly1 + 0.01,1
glvertex3f glx2 - 0.01,gly2 - 0.01,1
glvertex3f glx1 + 0.01,gly2 - 0.01,1
glvertex3f glx1 + 0.01,gly1 + 0.01,1
glend
but1.draw(mouse)
init_3D_gl
end if
' Copy OpenGL buffer to screen
flip
loop until multikey(fb.sc_escape)
deallocate(starsptr)
sub init_2D_gl()
glViewport 0,0,sx,sy
glMatrixMode GL_PROJECTION
glLoadIdentity
glOrtho glx1, glx2, gly2, gly1, -5.0, 5.0
glMatrixMode GL_MODELVIEW
glLoadIdentity
glShadeModel GL_SMOOTH
glClearColor 0.0, 0.0, 0.0, 1.0
glClearDepth 1.0
glClearAccum 0.0, 0.0, 0.0, 1.0
glClear GL_ACCUM_BUFFER_BIT
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
glLineWidth 2.0
end sub
sub init_3D_gl()
' Initialize OpenGL
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective cam.fov, cam.aspect, cam.nearClip, cam.farClip
glMatrixMode GL_MODELVIEW
glLoadIdentity
glTexEnvf GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
glShadeModel GL_SMOOTH
glClearColor 0.0, 0.0, 0.0, 1.0
glPointSize 5
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glLineWidth(5)
glEnable(GL_LINE_SMOOTH)
end sub
Code: Select all
' draw_gl_... primitivessub draw_gl_cube(sidelength as double = 1,r as double = 1,g as double = 1,b as double = 1)
sub draw_gl_cube(sidelength as double = 1,r as double = 1,g as double = 1,b as double = 1)
glBegin GL_QUADS
glColor3f r, g, b
glNormal3f 0.0, 0.0, 1.0
glVertex3f sideLength / -2.0, sideLength / 2.0, sideLength / 2.0
glVertex3f sideLength / -2.0, sideLength / -2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / -2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / 2.0, sideLength / 2.0
glNormal3f 1.0, 0.0, 0.0
glVertex3f sideLength / 2.0, sideLength / 2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / -2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / -2.0, sideLength / -2.0
glVertex3f sideLength / 2.0, sideLength / 2.0, sideLength / -2.0
glNormal3f 0.0, 0.0, -1.0
glVertex3f sideLength / 2.0, sideLength / 2.0, sideLength / -2.0
glVertex3f sideLength / 2.0, sideLength / -2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / -2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / 2.0, sideLength / -2.0
glNormal3f -1.0, 0.0, 0.0
glVertex3f sideLength / -2.0, sideLength / 2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / -2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / -2.0, sideLength / 2.0
glVertex3f sideLength / -2.0, sideLength / 2.0, sideLength / 2.0
glNormal3f 0.0, 1.0, 0.0
glVertex3f sideLength / -2.0, sideLength / 2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / 2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / 2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / 2.0, sideLength / -2.0
glNormal3f 0.0, -1.0, 0.0
glVertex3f sideLength / 2.0, sideLength / -2.0, sideLength / 2.0
glVertex3f sideLength / 2.0, sideLength / -2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / -2.0, sideLength / -2.0
glVertex3f sideLength / -2.0, sideLength / -2.0, sideLength / 2.0
glEnd
end sub
sub draw_gl_star(x as double,y as double,z as double,s as double)
glbegin GL_TRIANGLES
glcolor4f starcolour
glVertex3f x, y + (0.5 * s), z
glVertex3f x - (0.5 * s), y - (0.5 * s), z - (0.5 * s)
glVertex3f x + (0.5 * s), y - (0.5 * s), z - (0.5 * s)
glVertex3f x, y + (0.5 * s), z
glVertex3f x - (0.5 * s), y - (0.5 * s), z - (0.5 * s)
glVertex3f x, y - (0.5 * s), z + (0.5 * s)
glVertex3f x, y + (0.5 * s), z
glVertex3f x + (0.5 * s), y - (0.5 * s), z - (0.5 * s)
glVertex3f x, y - (0.5 * s), z + (0.5 * s)
glVertex3f x - (0.5 * s), y - (0.5 * s), z - (0.5 * s)
glVertex3f x + (0.5 * s), y - (0.5 * s), z - (0.5 * s)
glVertex3f x, y - (0.5 * s), z + (0.5 * s)
glend
end sub
sub draw_gl_projectile(x as double,y as double,z as double)
glTranslatef x,y,z
draw_gl_cube(.25,1,0,0)
glTranslatef -x,-y,-z
end sub
sub draw_gl_ship
end sub