heres where its at now.
now that ive added the multiply the objects shoot away into the distance.
''
'' This Code Was Created By Jeff Molofee 2000
'' A HUGE Thanks To Fredric Echols For Cleaning Up
'' And Optimizing The Base Code, Making It More Flexible!
'' If You've Found This Code Useful, Please Let Me Know.
'' Visit My Site At nehe.gamedev.net
option explicit
#include once "GL/gl.bi"
#include once "GL/glu.bi"
screen 18, 16, , 2
glViewport 0, 0, 640, 480
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 45.0, 640.0/480.0, 0.1, 100.0
glMatrixMode GL_MODELVIEW
glLoadIdentity
glShadeModel GL_SMOOTH
glClearColor 0.0, 0.0, 0.0, 0.5
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
dim shared as double pirmatrix(0 to 3,0 to 3)
dim shared as double boxmatrix(0 to 3,0 to 3)
dim shared as double cam(0 to 3,0 to 3)
dim shared as double Psin(0 to 360) , Pcos(0 to 360)
dim x as integer
for x = 1 to 360
Psin( x ) = sin( x * 3.1415 / 180.0 )
Pcos( x ) = cos( x * 3.1415 / 180.0 )
next
declare sub draw_piramid( byval matrix as double ptr )
declare sub draw_box( byval matrix as double ptr )
declare sub loadentityidentity( matrix as double ptr )
declare sub positionentity( matrix as double ptr , byval xpos as double , byval ypos as double , byval zpos as double )
declare sub moveentity( matrix as double ptr , byval xpos as double , byval ypos as double , byval zpos as double )
declare sub rotateentity( matrix as double ptr , xpos as double , ypos as double , zpos as double )
declare sub copymatrix4x4( destination as double ptr , byval source as double ptr )
declare sub mulmatrix4x4( byval matrix1 as double ptr , byval matrix2 as double ptr , resultmatrix as double ptr )
declare sub transposematrix( matrix as double ptr )
loadentityidentity( @pirmatrix(0,0) )
loadentityidentity( @boxmatrix(0,0) )
loadentityidentity( @cam(0,0) )
positionentity( @pirmatrix(0,0) , -4.0 , 0 , -16.0 )
positionentity( @boxmatrix(0,0) , 1.0 , 0 , -5.0 )
do
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
glLoadIdentity
rotateentity( @cam(0,0) , 0,0,1)
transposematrix( @cam(0,0) )
glloadmatrixd( @cam(0,0) )
rotateentity( @pirmatrix(0,0) , 0.0 , 1 , 0.0 )
rotateentity( @boxmatrix(0,0) , 1 , 0 , 0 )
rotateentity( @boxmatrix(0,0) , 0 , 1 , 0 )
rotateentity( @boxmatrix(0,0) , 0 , 0 , 1 )
draw_piramid( @pirmatrix(0,0) )
draw_box( @boxmatrix(0,0) )
flip
loop while inkey$ = ""
sub loadentityidentity( matrix as double ptr )
dim as integer x
for x = 0 to 15
if x = 0 or x = 5 or x = 10 or x = 15 then
matrix[x] = 1
else
matrix[x] = 0
endif
next
end sub
sub positionentity( matrix as double ptr , byval xpos as double , byval ypos as double , byval zpos as double )
matrix[12] = xpos
matrix[13] = ypos
matrix[14] = zpos
end sub
sub moveentity( matrix as double ptr , byval xpos as double , byval ypos as double , byval zpos as double )
matrix[12] += xpos
matrix[13] += ypos
matrix[14] += zpos
end sub
sub rotateentity( matrix as double ptr , xpos as double , ypos as double , zpos as double )
dim as double Tmatrix1(0 to 3,0 to 3) , Tmatrix2(0 to 3,0 to 3)
if xpos > 360 then xpos = 0
if xpos < 0 then xpos = 360
if ypos > 360 then ypos = 0
if ypos < 0 then ypos = 360
if zpos > 360 then zpos = 0
if zpos < 0 then zpos = 360
'rotate on xaxis
if xpos then
loadentityidentity( @Tmatrix1(0,0) )
Tmatrix1(1,1) = Pcos( xpos )
Tmatrix1(2,1) = -Psin( xpos )
Tmatrix1(1,2) = Psin( xpos )
Tmatrix1(2,2) = Pcos( xpos )
mulmatrix4x4( @Tmatrix1(0,0) , matrix , @Tmatrix2(0,0) )
copymatrix4x4( matrix , @Tmatrix2(0,0) )
endif
'rotate on yaxis
if ypos then
loadentityidentity( @Tmatrix1(0,0) )
Tmatrix1(0,0) = Pcos( ypos )
Tmatrix1(2,0) = Psin( ypos )
Tmatrix1(0,2) = -Psin( ypos )
Tmatrix1(2,2) = Pcos( ypos )
mulmatrix4x4( @Tmatrix1(0,0) , matrix , @Tmatrix2(0,0) )
copymatrix4x4( matrix , @Tmatrix2(0,0) )
endif
'rotate on zaxis
if zpos then
loadentityidentity( @Tmatrix1(0,0) )
Tmatrix1(0,0) = Pcos( zpos )
Tmatrix1(1,0) = -Psin( zpos )
Tmatrix1(0,1) = Psin( zpos )
Tmatrix1(1,1) = Pcos( zpos )
mulmatrix4x4( @Tmatrix1(0,0) , matrix , @Tmatrix2(0,0) )
copymatrix4x4( matrix , @Tmatrix2(0,0) )
endif
end sub
sub copymatrix4x4( destination as double ptr , byval source as double ptr )
dim x as integer
for x=0 to 15
destination[x] = source[x]
next
end sub
sub transposematrix( matrix as double ptr )
dim as double tmp_matrix( 0 to 3 , 0 to 3 ) , tmp_matrix2( 0 to 3 , 0 to 3 )
dim as integer x,y
copymatrix4x4( @tmp_matrix(0,0) , matrix )
for y = 0 to 3
for x = 0 to 3
tmp_matrix(x,y) = matrix[y*4+x]
next
next
mulmatrix4x4( matrix , @tmp_matrix(0,0) , @tmp_matrix2(0,0) )
copymatrix4x4( matrix , @tmp_matrix2(0,0) )
end sub
sub mulmatrix4x4( byval matrix1 as double ptr , byval matrix2 as double ptr , resultmatrix as double ptr )
dim as integer a,x,y
dim as double accum
for y = 0 to 3
for x = 0 to 3
accum = 0
for a = 0 to 3
accum += matrix1[y*4+a] * matrix2[a*4+x]
next
resultmatrix[y*4+x] = accum
next
next
end sub
sub draw_piramid( byval matrix as double ptr )
glpushmatrix
glmultmatrixd( matrix )
glBegin GL_TRIANGLES
glColor3f 1.0, 0.0, 0.0
glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 1.0, 0.0
glVertex3f -1.0, -1.0, 1.0
glColor3f 0.0, 0.0, 1.0
glVertex3f 1.0, -1.0, 1.0
glColor3f 1.0, 0.0, 0.0
glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 0.0, 1.0
glVertex3f 1.0, -1.0, 1.0
glColor3f 0.0, 1.0, 0.0
glVertex3f 1.0, -1.0, -1.0
glColor3f 1.0, 0.0, 0.0
glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 1.0, 0.0
glVertex3f 1.0, -1.0, -1.0
glColor3f 0.0, 0.0, 1.0
glVertex3f -1.0, -1.0, -1.0
glColor3f 1.0, 0.0, 0.0
glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 0.0, 1.0
glVertex3f -1.0, -1.0, -1.0
glColor3f 0.0, 1.0, 0.0
glVertex3f -1.0, -1.0, 1.0
glEnd
glpopmatrix
end sub
sub draw_box( byval matrix as double ptr )
glpushmatrix
glmultmatrixd( matrix )
glBegin GL_QUADS
glColor3f 0.0, 1.0, 0.0
glVertex3f 1.0, 1.0, -1.0
glVertex3f -1.0, 1.0, -1.0
glVertex3f -1.0, 1.0, 1.0
glVertex3f 1.0, 1.0, 1.0
glColor3f 1.0, 0.5, 0.0
glVertex3f 1.0, -1.0, 1.0
glVertex3f -1.0, -1.0, 1.0
glVertex3f -1.0, -1.0, -1.0
glVertex3f 1.0, -1.0, -1.0
glColor3f 1.0, 0.0, 0.0
glVertex3f 1.0, 1.0, 1.0
glVertex3f -1.0, 1.0, 1.0
glVertex3f -1.0, -1.0, 1.0
glVertex3f 1.0, -1.0, 1.0
glColor3f 1.0, 1.0, 0.0
glVertex3f 1.0, -1.0, -1.0
glVertex3f -1.0, -1.0, -1.0
glVertex3f -1.0, 1.0, -1.0
glVertex3f 1.0, 1.0, -1.0
glColor3f 0.0, 0.0, 1.0
glVertex3f -1.0, 1.0, 1.0
glVertex3f -1.0, 1.0, -1.0
glVertex3f -1.0, -1.0, -1.0
glVertex3f -1.0, -1.0, 1.0
glColor3f 1.0, 0.0, 1.0
glVertex3f 1.0, 1.0, -1.0
glVertex3f 1.0, 1.0, 1.0
glVertex3f 1.0, -1.0, 1.0
glVertex3f 1.0, -1.0, -1.0
glEnd
glpopmatrix
end sub