For i = 1 To Num_Entities
Rot_X Entity(i), Entity(i).Angle.X
Rot_Y Entity(i), Entity(i).Angle.Y
Rot_Z Entity(i), Entity(i).Angle.Z
glGetFloatv GL_MODELVIEW_MATRIX, @Entity(i).glMatrix(0)
Entity(i).glMatrix(0) = Entity(i).RVector.X
Entity(i).glMatrix(1) = Entity(i).RVector.Y
Entity(i).glMatrix(2) = Entity(i).RVector.Z
Entity(i).glMatrix(4) = Entity(i).UVector.X
Entity(i).glMatrix(5) = Entity(i).UVector.Y
Entity(i).glMatrix(6) = Entity(i).UVector.Z
Entity(i).glMatrix(8) = -Entity(i).DVector.X
Entity(i).glMatrix(9) = -Entity(i).DVector.Y
Entity(i).glMatrix(10) = -Entity(i).DVector.Z
Entity(i).glMatrix(12) = Entity(i).Position.X
Entity(i).glMatrix(13) = Entity(i).Position.Y
Entity(i).glMatrix(14) = Entity(i).Position.Z
Next
If Plr.WalkSpd<>0 Or Plr.StrafeSpd<>0 Then
If Plr.Firing<>1 And Collided Then
Recoil.X+=Recoil.Y
If Recoil.X>5 Then Recoil.Y=-1
If Recoil.X<-5 Then Recoil.Y=1
If Int(Recoil.X) = 0 And Collided Then
alSourcefv Wav_Src(3), AL_POSITION, @ListenerPos(0)
alSourcePlay(Wav_Src(3))
End If
End If
End If
Plr.ViewPoint.X = Plr.Cam.Position.X + Plr.Cam.DVector.X
Plr.ViewPoint.Y = Plr.Cam.Position.Y + Plr.Cam.DVector.Y
Plr.ViewPoint.Z = Plr.Cam.Position.Z + Plr.Cam.DVector.Z
Glmatrixmode GL_MODELVIEW
Glloadidentity()
Glulookat plr.cam.Position.X, plr.cam.Position.Y, plr.cam.Position.Z, _
Plr.ViewPoint.X, Plr.ViewPoint.Y, Plr.ViewPoint.Z, _
plr.cam.UVector.X, plr.cam.UVector.Y, plr.cam.UVector.Z
glEnable GL_Lighting
glLightfv (GL_LIGHT1, GL_POSITION, @Light.position(0))
GLENABLE GL_ALPHA_TEST
GLALPHAFUNC GL_Greater, 0.1
GlEnable GL_BLEND
glBlendFunc GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA
For i = 1 To Num_Entities
If Entity(i).Active Then
Glpushmatrix
glMultMatrixf @Entity(i).glMatrix(0)
glColor4F 1,1,1,1
glCallList DLists(Entity(i).Model_Id)
Glpopmatrix
End If
Next
For i= 1 To Ubound(Plr.Bullet)
glGetFloatv GL_MODELVIEW_MATRIX, @Plr.Bullet(i).glMatrix(0)
If Not Plr.Bullet(i).Explosion Then
Plr.Bullet(i).glMatrix(0) = Plr.Bullet(i).RVector.X
Plr.Bullet(i).glMatrix(1) = Plr.Bullet(i).RVector.Y
Plr.Bullet(i).glMatrix(2) = Plr.Bullet(i).RVector.Z
Plr.Bullet(i).glMatrix(4) = Plr.Bullet(i).UVector.X
Plr.Bullet(i).glMatrix(5) = Plr.Bullet(i).UVector.Y
Plr.Bullet(i).glMatrix(6) = Plr.Bullet(i).UVector.Z
Plr.Bullet(i).glMatrix(8) = -Plr.Bullet(i).DVector.X
Plr.Bullet(i).glMatrix(9) = -Plr.Bullet(i).DVector.Y
Plr.Bullet(i).glMatrix(10) = -Plr.Bullet(i).DVector.Z
Else
Plr.Bullet(i).glMatrix(0) = Plr.Cam.RVector.X
Plr.Bullet(i).glMatrix(1) = Plr.Cam.RVector.Y
Plr.Bullet(i).glMatrix(2) = Plr.Cam.RVector.Z
Plr.Bullet(i).glMatrix(4) = Plr.Cam.UVector.X
Plr.Bullet(i).glMatrix(5) = Plr.Cam.UVector.Y
Plr.Bullet(i).glMatrix(6) = Plr.Cam.UVector.Z
Plr.Bullet(i).glMatrix(8) = -Plr.Cam.DVector.X
Plr.Bullet(i).glMatrix(9) = -Plr.Cam.DVector.Y
Plr.Bullet(i).glMatrix(10) = -Plr.Cam.DVector.Z
End If
Plr.Bullet(i).glMatrix(12) = Plr.Bullet(i).Position.X
Plr.Bullet(i).glMatrix(13) = Plr.Bullet(i).Position.Y
Plr.Bullet(i).glMatrix(14) = Plr.Bullet(i).Position.Z
Glpushmatrix
glMultMatrixf @Plr.Bullet(i).glMatrix(0)
If Plr.Bullet(i).Explosion>0 Then
Plr.Bullet(i).RGBAlpha(3)-=.05
glEnable GL_POLYGON_OFFSET_FILL
glScaleF Plr.Bullet(i).Explosion, Plr.Bullet(i).Explosion, Plr.Bullet(i).Explosion
GlEnable GL_BLEND
glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA
For i3 = 0 To 1
Glpushmatrix
glRotatef Rnd*360,0,0,1
glPolygonOffset 1, -25
glColor4Fv @Plr.Bullet(i).RGBAlpha(0)
glCallList DLists(4)
Glpopmatrix
Next
glDisable GL_POLYGON_OFFSET_FILL
Else
If Plr.Bullet(i).Active Then
glBlendFunc GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA
glColor4F 1,1,1,1
glCallList DLists(3)
End If
End If
Glpopmatrix
Next
FPS+=1
If SDL_GetTicks()>= FPSTimer Then
FramesPerSecond=Str$(FPS)
FPS=0
FPSTimer = SDL_GetTicks()+1000
End If
'this is only needed if you rotate the textures somewhere else before this. ;)
'glMatrixMode GL_TEXTURE
'glLoadIdentity()
'glrotatef 180, 0.0, 1.0, 0.0
'glrotatef 180, 0.0, 0.0, 1.0
'GlPushMatrix()
glColor4f 1,.25,.25,.75
glPrint 0, 0, "Frames Per Second "+FramesPerSecond, 1, mTextures(1), FBase
If Plr.Health >=20 Then
glColor4f 0,0,1,1
Else
glColor4f 1,0,0,1
End If
'glPrint 0, 20, "Health "+Str$(Plr.Health)+"%", 1, mTextures(1), FBase
'glPrint 0, 20, "Z "+Str$((Plr.Cam.Position.Z)), 1, mTextures(1), FBase
'glPrint 0, 40, "Y "+Str$((Plr.Cam.Position.Y)), 1, mTextures(1), FBase
'glPrint 0, 60, "X "+Str$((Plr.Cam.Position.X)), 1, mTextures(1), FBase
SDL_GL_SwapBuffers
Do:Loop Until SDL_GetTicks() >= wTime
Loop While Result <> 1
Ender:
alDeleteSources(Num_Sounds+1, @Wav_Src(0))
alDeleteBuffers(Num_Sounds+1, @Wav_Bff(0))
alutExit
'gluDeleteQuadric Sphere
glDeleteLists fbase,256
For i = 1 To Num_Models
glDeleteLists DLists(i), 1
Next
glDeleteTextures Num_Textures, @mTextures(0)
SDL_Quit
For i = 1 To Num_Models
Deallocate(Model(i)->Face)
Deallocate(Model(i)->Vec)
Deallocate(Model(i)->Norm)
Deallocate(Model(i)->Surf)
Deallocate(Model(i))
Next
End
Function Find_Angle(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single) As Integer
Dim Temp_Angle As Integer
Temp_Angle = -Atan2(y2-y1, x2-x1) * 57.29577951308232
If Temp_Angle<0 Then Temp_Angle= 360 + Temp_Angle
Find_Angle = Temp_Angle
End Function
Sub Do_Particles(Model As ModelType Ptr, mTextures() As Integer, AlphaVal() As Single)
Dim CurSurf As Integer, _
i As Integer
For CurSurf = 0 To Model->Num_Surfaces - 1
glMaterialfv GL_FRONT, GL_AMBIENT, @Model->Surf[CurSurf].Ambient(0)
glMaterialfv GL_FRONT, GL_DIFFUSE, @Model->Surf[CurSurf].Diffuse(0)
glMaterialfv GL_FRONT, GL_SPECULAR, @Model->Surf[CurSurf].Specular(0)
glMaterialfv GL_FRONT, GL_EMISSION, @Model->Surf[CurSurf].Emission(0)
glMaterialfv GL_FRONT, GL_SHININESS, @Model->Surf[CurSurf].Shininess
glColor4fV @AlphaVal(0)
GlEnable GL_BLEND
glBlendFunc GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA
If Model->Surf[CurSurf].Textured Then
glEnable Gl_Texture_2D
glBindTexture GL_TEXTURE_2D, mTextures(Model->Surf[CurSurf].Texture_Id)
End If
Glbegin GL_TRIANGLES
For i = Model->Surf[CurSurf].Start_Id To Model->Surf[CurSurf].End_Id
Gltexcoord2fv @Model->Face[i].TextUVs(1).X
glNormal3fv @Model->Norm[Model->Face[i].P(1)].X
glVertex3fv @Model->Vec[Model->Face[i].P(1)].X
Gltexcoord2fv @Model->Face[i].TextUVs(2).X
glNormal3fv @Model->Norm[Model->Face[i].P(2)].X
glVertex3fv @Model->Vec[Model->Face[i].P(2)].X
Gltexcoord2fv @Model->Face[i].TextUVs(3).X
glNormal3fv @Model->Norm[Model->Face[i].P(3)].X
glVertex3fv @Model->Vec[Model->Face[i].P(3)].X
Next i
Glend
glDisable GL_TEXTURE_2D
Next
End Sub
Function Check_Terrain_Collision(Cam As EntityType, vVector As Vector3DType, Gravity As Single, Radius As Single, Model As ModelType Ptr) As Integer
Dim vTriangle(1 To 3) As Vector3DType, vOffSet As Vector3DType, vIntersection As Vector3DType, vNormal As Vector3DType
Dim Dist As Single, dNormal As Vector3DType
Dim Reposit As Integer, i As Integer, i2 As Integer
Dim Face_Collision As Integer, Edge_Collision As Integer
Dim New_Intersection As Vector3DType, tLine(1 To 2) As Vector3DType, tVector As Vector3DType
For i = 0 To Model->FaceCnt - 1
For i2 = 1 To 3
vTriangle(i2).X = Model->Vec[Model->Face[i].P(i2)].X
vTriangle(i2).Y = Model->Vec[Model->Face[i].P(i2)].Y
vTriangle(i2).Z = Model->Vec[Model->Face[i].P(i2)].Z
Next
vNormal.X = Model->Face[i].Normal.X
vNormal.Y = Model->Face[i].Normal.Y
vNormal.Z = Model->Face[i].Normal.Z
tLine(2).X=Cam.oPosition.X
tLine(2).Y=Cam.oPosition.Y
tLine(2).Z=Cam.oPosition.Z
tLine(1).X=Cam.Position.X
tLine(1).Y=Cam.Position.Y
tLine(1).Z=Cam.Position.Z
If Is_Polygon_Intersected(vTriangle() , tLine(), tVector) Then
Cam.Position.X=tVector.X+(vNormal.X*Radius)
Cam.Position.Y=tVector.Y+(vNormal.Y*Radius)
Cam.Position.Z=tVector.Z+(vNormal.Z*Radius)
End If
Dist = 0
Reposit = reposit_collision(Cam.Position, vNormal, vTriangle(1), Radius, Dist)
If Reposit = Intersect Then
vOffSet.X = (vNormal.X * Dist)
vOffSet.Y = (vNormal.Y * Dist)
vOffSet.Z = (vNormal.Z * Dist)
vInterSection.X = Cam.Position.X - vOffSet.X
vInterSection.Y = Cam.Position.Y - vOffSet.Y
vInterSection.Z = Cam.Position.Z - vOffSet.Z
Face_collision = Is_Inside_Polygon(vIntersection, vTriangle())
Edge_collision = reposit_edge_Collision(vIntersection, vTriangle(), Radius/2)
If Face_collision Or Edge_collision Then
Get_Collision_OffSet vNormal, Radius, Dist, vOffSet
Cam.Position.X += vOffSet.X
Cam.Position.Y += vOffSet.Y
Cam.Position.Z += vOffSet.Z
If vNormal.Y>=.75 Then
Gravity=-.1
Check_Terrain_Collision = True
Elseif vNormal.Y<=-.5 Then
vVector.X += vNormal.X * .05
vVector.Y += vNormal.Y * .05
vVector.Z += vNormal.Z * .05
Check_Terrain_Collision = False
End If
End If
End If
Next
End Function
Sub Build_DLists(Model As ModelType Ptr, mTextures() As Integer, DList As Uinteger)
Dim CurSurf As Integer, _
i As Integer
DList = glGenLists(1)
glNewList DList, GL_COMPILE
For CurSurf = 0 To Model->Num_Surfaces - 1
glMaterialfv GL_FRONT, GL_AMBIENT, @Model->Surf[CurSurf].Ambient(0)
glMaterialfv GL_FRONT, GL_DIFFUSE, @Model->Surf[CurSurf].Diffuse(0)
glMaterialfv GL_FRONT, GL_SPECULAR, @Model->Surf[CurSurf].Specular(0)
glMaterialfv GL_FRONT, GL_EMISSION, @Model->Surf[CurSurf].Emission(0)
glMaterialfv GL_FRONT, GL_SHININESS, @Model->Surf[CurSurf].Shininess
'glColor4fV @Model->Surf[CurSurf].RGBAlpha(0)
glEnable GL_ALPHA_TEST
glEnable GL_BLEND
If Model->Surf[CurSurf].Textured Then
glEnable Gl_Texture_2D
glBindTexture GL_TEXTURE_2D, mTextures(Model->Surf[CurSurf].Texture_Id)
End If
Glbegin GL_TRIANGLES
For i = Model->Surf[CurSurf].Start_Id To Model->Surf[CurSurf].End_Id
Gltexcoord2fv @Model->Face[i].TextUVs(1).X
glNormal3fv @Model->Norm[Model->Face[i].P(1)].X
glVertex3fv @Model->Vec[Model->Face[i].P(1)].X
Gltexcoord2fv @Model->Face[i].TextUVs(2).X
glNormal3fv @Model->Norm[Model->Face[i].P(2)].X
glVertex3fv @Model->Vec[Model->Face[i].P(2)].X
Gltexcoord2fv @Model->Face[i].TextUVs(3).X
glNormal3fv @Model->Norm[Model->Face[i].P(3)].X
glVertex3fv @Model->Vec[Model->Face[i].P(3)].X
Next i
Glend
'glDisable GL_TEXTURE_2D
'glDisable GL_ALPHA_TEST
'glDisable GL_BLEND
Next
glEndList
End Sub
Sub LOAD_OBJ(FileName As String, Model As ModelType Ptr)
Dim Rec As String, _
Count_Faces As Byte, _
Count_Vertices As Byte, _
Count_Surfaces As Byte, _
Total_Faces As Integer, _
Total_Vertices As Integer, _
Total_Surfaces As Integer, _
CurrentSurface As Integer, _
TempFaces As Integer, _
TempPoints As Integer, _
TempUVs As Integer, _
NormIn As Integer, _
Start1 As Integer, _
Start2 As Integer, _
End1 As Integer, _
End2 As Integer, _
i As Integer, _
This_Surface As String, _
Loading_Surface As String, _
Used_Surface As Byte
Open FileName For Binary As #1
Do While Not Eof(1)
Line Input #1, Rec
Count_Faces = Instr(Rec$, "Faces:")
Count_Vertices = Instr(Rec$, "Vertices:")
Count_Surfaces = Instr(Rec$, "Materials:")