gfxgfxFreeBASIC Games Directory Forumgfxgfx
gfx gfx
gfx
Welcome, Guest. Please login or register. October 15, 2018, 10:14:43 AM

Login with username, password and session length
14.10.2018 - We are currently running a game dev competition with a 300 USD first prize, up until 14th of January, 2019. Check the official competition thread here: http://games.freebasic.net/forum/index.php?topic=623.0
gfx
gfx
*
gfxgfx
gfxgfx gfxgfx
gfxgfx Home Help Search Login Register   gfxgfx
gfx gfx
gfx
Pages: [1]
Print
Author Topic: can any one help me update this 3d code ?  (Read 3042 times)
neo
Novice
***
Gender: Male
Posts: 77


View Profile Email
« on: September 23, 2013, 03:39:10 PM »

Static
#INCLUDE "sdl/sdl.bi"
#INCLUDE "gl/gl.bi"
#INCLUDE "gl/glu.bi"
#INCLUDE "gl/glext.bi"
#INCLUDE "al/al.bi"
#INCLUDE "al/alut.bi"
#INCLUDE "3DTypes.bas"
#INCLUDE "3DMath.bas"


Type LightType
    Ambient(3) As Single
    Diffuse(3) As Single
    Specular(3) As Single
    Position(3) As Single
    Control As Single
End Type


Type Particles
    Position As Vector3DType
    DVector As Vector3DType
    RVector As Vector3DType
    UVector As Vector3DType
    glMatrix(15) As Single
    List_Id As Integer
    Life_Span As Integer
    AlphaVal(3) As Single
    RGBAlpha(3) As Single
    Emission(3) As Single
    Scale As Single
    i As Integer
    Z As Single
    Cull As Integer
    Active As Integer
    Explosion As Single
    Randimation As Single
End Type


Type PlayerType
    Cam As EntityType
    Radius As Single
    vVector As Vector3DType
    Gravity As Single
    ViewPoint As Vector3DType
    WalkSpd As Single
    StrafeSpd As Single
    BulletCnt As Integer
    Firing As Integer
    Shot_Delay As Integer
    Bullet(1 To 20) As Particles
    Weapon As Integer
    Health As Integer
End Type

Declare Sub LOAD_OBJ (FileName As String, Model As ModelType Ptr)
Declare Sub LoadTextures(FileName As String, Num_Txtr As GLUINT, AlphaVal As Integer)
Declare Sub CalcNormals(Model As ModelType Ptr)
Declare Sub Render_Scene(Entity As EntityType, Model As ModelType Ptr, mTextures() As Integer)  
Declare Sub Gen_Lights(Light As LightType)
Declare Sub Build_DLists(Model As ModelType Ptr, mTextures() As Integer, DList As Uinteger)
Declare Sub Build_Textures(mTextures() As GLUINT, Num_Textures As Integer)
Declare Sub Build_Sounds( Wav_Bff() As ALuint, Wav_Src() As ALuint, Num_Sounds As Uinteger)
Declare Sub BuildFont(Font_Texture() As GLUINT, FBase As GLUINT)
Declare Sub glPrint(Byval x As GLint, Byval  y As GLint, Byref xstring  As String , Byval xset As Integer, Font_Texture As GlUint, FBase As GlUint)
Declare Sub Init_Entity(Entity As EntityType)
Declare Function Check_Terrain_Collision(Cam As EntityType, vVector As Vector3DType, Gravity As Single, Radius As Single, Model As ModelType Ptr) As Integer
Declare Function Find_Angle(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single) As Integer
Declare Sub Do_Particles(Model As ModelType Ptr, mTextures() As Integer, AlphaVal() As Single)

Const SCR_WIDTH = 800, MidX = SCR_WIDTH\2
Const SCR_HEIGHT= 600, MidY = SCR_HEIGHT\2
Const BPP = 32

Dim Num_Models As Integer, _
Num_Entities As Integer, _
Num_Sounds As Integer, _
Num_Textures As Integer, _
Player_Id As Integer, _
Num_Particles As Integer

Num_Models = 4
Num_Entities = 2
Num_Sounds = 5
Num_Textures = 11
Player_Id = 1
Num_Particles = 100

Dim Particle(Num_Particles) As Particles
Dim Plr As PlayerType
Dim i As Integer, i2 As Integer, F As Integer, V As Integer, S As Integer
Dim FOVy As Double, Aspect As Double, znear As Double, zfar As Double
Dim Result As Unsigned Integer, Tscreen As SDL_Surface Ptr
Dim Light As LightType
Dim Fogcolor(3) As Single
Dim SDL_flags As Integer, Event As SDL_Event
Dim Mouse_X As Integer, Mouse_Y As Integer
Dim Wav_Bff(Num_Sounds) As ALuint
Dim Wav_Src(Num_Sounds) As ALuint
Dim DLists( 1 To Num_Models ) As GLUINT
Dim Model(1 To Num_Models) As ModelType Ptr
Dim Entity(1 To Num_Entities) As EntityType
Dim mTextures(Num_Textures) As GLUINT

Dim ListenerPos(2) As ALFloat, SourcePos(2) As ALFloat, ListenerOri(5) As ALFloat


Dim Recoil As Vector3DType


Randomize Timer

SDL_flags = SDL_HWSURFACE Or _
SDL_DOUBLEBUF Or _
SDL_OPENGL Or _
SDL_OPENGLBLIT' OR _
'SDL_FULLSCREEN            
result = SDL_Init(SDL_INIT_EVERYTHING)
If result <> 0 Then End

SDL_GL_SetAttribute SDL_GL_DOUBLEBUFFER, GL_TRUE

Tscreen = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, BPP, SDL_flags)
If Tscreen = 0 Then
    SDL_Quit
    End
Else
    SDL_WM_SetCaption "FPS Camera Demo", ""
    SDL_ShowCursor False
End If

glViewport 0, 0, SCR_WIDTH, SCR_HEIGHT
Glmatrixmode GL_PROJECTION        
Glloadidentity  
FOVy = 45.0
Aspect = SCR_WIDTH / SCR_HEIGHT
znear = .1
zfar = 100
gluPerspective FOVy, aspect, znear, zfar
Glpushmatrix

glShadeModel GL_Smooth
glClearColor 0.0, 0.0, 0.0, 0.0
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL  
glEnable GL_COLOR_MATERIAL  
glenable GL_DOUBLEBUFFER  
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST  
glHint GL_LINE_SMOOTH_HINT, GL_NICEST
glenable GL_LINE_SMOOTH
glHint GL_POINT_SMOOTH_HINT, GL_NICEST
glenable GL_POINT_SMOOTH  
glPolygonMode GL_FRONT, GL_FILL
glEnable GL_CULL_FACE

FogColor(0)=0.01
FogColor(1)=0.01
FogColor(2)=0.01
FogColor(3)=1.0

glFogi(GL_FOG_MODE, GL_EXP2)
glFogfv(GL_FOG_COLOR, @fogColor(0))
glFogf(GL_FOG_DENSITY, 0.05)
glHint(GL_FOG_HINT, GL_NICEST)
glFogf(GL_FOG_START, 9.0)
glFogf(GL_FOG_END, 10.0)
glEnable(GL_FOG)


glGenTextures Num_Textures, @mTextures(0)
Dim fBase As GLUINT
fBase = glGenLists(256)
LoadTextures "Textures/Font.Bmp", mTextures(1), 255
BuildFont mTextures(), FBase

Gen_Lights Light  
Glmatrixmode GL_TEXTURE
Glloadidentity()
glrotatef 180, 0.0, 1.0, 0.0
glrotatef 180, 0.0, 0.0, 1.0    
glPrint 0, 0, "Loading, Please Wait...", 1, MTextures(1), FBase
SDL_GL_SWAPBUFFERS      

Build_Sounds Wav_Bff(), Wav_Src(), Num_Sounds

Build_Textures mTextures(), Num_Textures

For i = 1 To Num_Models
    Model(i)= Allocate(Len(ModelType))
Next


Load_Obj "Models/Level_001.obj", Model(1)
CalcNormals Model(1)
Entity(1).Model_Id = 1
Entity(1).Active=True
Init_Entity Entity(1)


Load_Obj "Models/Gun.obj", Model(2)
CalcNormals Model(2)
Entity(2).Model_Id = 2
Entity(2).Active=True
Entity(2).Position.X=0
Entity(2).Position.Y=-4.65
Entity(2).Position.Z=-27
Entity(2).Angle.Y = .1
Init_Entity Entity(2)

Load_Obj "Models/Missle.obj", Model(3)
CalcNormals Model(3)

Load_Obj "Models/Explosion_Sphere.obj", Model(4)
CalcNormals Model(4)



For i2 = 1 To Num_Models
    For S = 0 To Model(i2)->Num_Surfaces - 1
        For i= 0 To 3
            Model(i2)->Surf[S].Ambient(i)= 0.15
            Model(i2)->Surf[S].RGBAlpha(i) = 1.0
            Model(i2)->Surf[S].Specular(i)= 0.75
            Model(i2)->Surf[S].Diffuse(i)= 0.2
            Model(i2)->Surf[S].Emission(i)= 0.0        
        Next
        Model(i2)->Surf[S].Shininess = 5
        Model(i2)->Surf[S].Emission(3)= 1.0
        Model(i2)->Surf[S].TransParent = False
    Next
Next


Dim k As Ubyte Ptr, wTime As Integer, FPS As Integer, FPSTimer As Integer, FramesPerSecond As String
Dim tDist As Single
Dim Collided As Integer

For i = 1 To Num_Models
    Build_DLists Model(i), mTextures(), DLists(i)
Next



Plr.Radius = .5
Plr.Health=100
Plr.Weapon=2
Init_Entity Plr.Cam
Plr.Cam.Position.Y = 6
Plr.Cam.Position.Z = 4
Recoil.Y = 1


For i= 1 To Num_Particles
    Particle(i).Life_Span = i
    Particle(i).List_Id = 3
    For i2 = 0 To 2
        Particle(i).AlphaVal(i2) = .25
    Next
Next



Dim tLine(1 To 2) As Vector3DType, _
vTriangle(1 To 3) As Vector3DType, _
tVector As Vector3DType, _
i3 As Integer

SDL_WarpMouse(MidX, MidY)
Do  
    
    wTime = SDL_GetTicks() + 20
    
    Glclear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
    SDL_PumpEvents
    k = SDL_GetKeyState(0)
    Result = Peek(K + SDLK_ESCAPE)
    
    
    Do While SDL_Pollevent(@Event)
        Select Case Event.Type        
        Case SDL_MouseMotion
            Mouse_X = Event.Motion.X
            Mouse_Y = Event.Motion.Y
        Case SDL_MouseButtonDown
            Plr.Firing = Event.Button.Button
        Case SDL_MouseButtonUp
            Plr.Firing = False
        End Select
    Loop
    
    Plr.Cam.Angle.X = ( MidY - Mouse_Y )/750
    Plr.Cam.Angle.Y = ( MidX - Mouse_X )/750
    Plr.Cam.Angle.Z= 0
    If Plr.Firing=1 Then Recoil.X=0
    
    SDL_WarpMouse(MidX, MidY)
    
    If Plr.Cam.RVector.Y<>0 Then
        Plr.Cam.Angle.Z = -Plr.Cam.RVector.Y*.5
    End If
    
    Plr.WalkSpd*=.95
    If Abs(Plr.WalkSpd)<1 Then Plr.WalkSpd=0
    Plr.StrafeSpd*=.95
    If Abs(Plr.StrafeSpd)<1 Then Plr.StrafeSpd=0
    
    If Peek(K + SDLK_W) Then
        Plr.vVector.X+= Plr.Cam.DVector.X*.02
        Plr.vVector.Z+= Plr.Cam.DVector.Z*.02
    End If
    
    If Peek(K + SDLK_S) Then
        Plr.vVector.X-= Plr.Cam.DVector.X*.02
        Plr.vVector.Z-= Plr.Cam.DVector.Z*.02
    End If
    
    If Peek(K + SDLK_D) Then
        Plr.vVector.X+= Plr.Cam.RVector.X*.02
        Plr.vVector.Z+= Plr.Cam.RVector.Z*.02
    End If
    
    If Peek(K + SDLK_A) Then
        Plr.vVector.X-= Plr.Cam.RVector.X*.02
        Plr.vVector.Z-= Plr.Cam.RVector.Z*.02
    End If
    
    If Peek(K + SDLK_SPACE) Then
        If Collided Then
            Plr.Gravity=.4
            alSourcefv Wav_Src(5), AL_POSITION, @ListenerPos(0)
            alSourcePlay Wav_Src(5)
        End If
    End If
    
    
    Plr.vVector.X*=.9
    If Abs(Plr.vVector.X)<.001 Then Plr.vVector.X=0
    Plr.vVector.Y*=.9
    If Abs(Plr.vVector.Y)<.001 Then Plr.vVector.Y=0
    Plr.vVector.Z*=.9
    If Abs(Plr.vVector.Z)<.001 Then Plr.vVector.Z=0
    
    Plr.Cam.oPosition.X = Plr.Cam.Position.X
    Plr.Cam.oPosition.Y = Plr.Cam.Position.Y
    Plr.Cam.oPosition.Z = Plr.Cam.Position.Z
    
    Plr.Cam.Position.X += Plr.vVector.X
    Plr.Cam.Position.Z += Plr.vVector.Z
    
    Plr.Gravity -=.03
    If Plr.Gravity<-1 Then Plr.Gravity=-1
    Plr.Cam.Position.Y += Plr.vVector.Y +Plr.Gravity
    
    Rot_X Plr.Cam, Plr.Cam.Angle.X
    Rot_Y Plr.Cam, Plr.Cam.Angle.Y
    Rot_Z Plr.Cam, Plr.Cam.Angle.Z
    
    
    
    Collided = Check_Terrain_Collision(Plr.Cam, Plr.vVector, Plr.Gravity, Plr.Radius, Model(Entity(1).Model_Id))
    
    
    ListenerPos(0) = Plr.Cam.Position.X
    ListenerPos(1) = Plr.Cam.Position.Y
    ListenerPos(2) = Plr.Cam.Position.Z
    ListenerOri(0) = Plr.Cam.DVector.X
    ListenerOri(1) = Plr.Cam.DVector.Y
    ListenerOri(2) = Plr.Cam.DVector.Z
    ListenerOri(3) = Plr.Cam.UVector.X
    ListenerOri(4) = Plr.Cam.UVector.Y
    ListenerOri(5) = Plr.Cam.UVector.Z
    
    alListenerfv AL_POSITION, @ListenerPos(0)
    alListenerfv AL_ORIENTATION, @ListenerOri(0)
    alListener3f AL_VELOCITY, 0,0,0
    
    
    If Not Plr.Weapon Then
        If Distance(Plr.Cam.Position, Entity(2).Position)<= Plr.Radius Then
            Plr.Weapon=2
            'Entity(2).Active=False
            'Entity(2).Angle.X = 1
        End If    
    End If
    
    
    
    For i=1 To Ubound(Plr.Bullet)
        If Plr.Bullet(i).Active>0 Then
            If Plr.Bullet(i).Explosion = 0 Then
                Plr.Bullet(i).Active+=1
                If Plr.Bullet(i).Active>=500 Then Plr.Bullet(i).Active=False
                If Plr.Bullet(i).DVector.Y>-1 Then Plr.Bullet(i).DVector.Y-=.005
                tLine(2).X=Plr.Bullet(i).Position.X + Plr.Bullet(i).DVector.X*.4
                tLine(2).Y=Plr.Bullet(i).Position.Y + Plr.Bullet(i).DVector.Y*.4
                tLine(2).Z=Plr.Bullet(i).Position.Z + Plr.Bullet(i).DVector.Z*.4
                tLine(1).X=Plr.Bullet(i).Position.X
                tLine(1).Y=Plr.Bullet(i).Position.Y
                tLine(1).Z=Plr.Bullet(i).Position.Z
                
                For i3 = 0 To Model(1)->FaceCnt - 1
                    For i2 = 1 To 3
                        vTriangle(i2).X = Model(1)->Vec[Model(1)->Face[i3].P(i2)].X
                        vTriangle(i2).Y = Model(1)->Vec[Model(1)->Face[i3].P(i2)].Y
                        vTriangle(i2).Z = Model(1)->Vec[Model(1)->Face[i3].P(i2)].Z
                    Next
                    
                    If Is_Polygon_Intersected(vTriangle() , tLine(), tVector) Then
                        tLine(2).X=tVector.X
                        tLine(2).Y=tVector.Y
                        tLine(2).z=tVector.Z
                        Plr.Bullet(i).Explosion=.01
                        SourcePos(0) = Plr.Bullet(i).Position.X
                        SourcePos(1) = Plr.Bullet(i).Position.Y
                        SourcePos(2) = Plr.Bullet(i).Position.Z
                        alSourcefv Wav_Src(2), AL_POSITION, @SourcePos(0)
                        alSource3f Wav_Src(2), AL_VELOCITY, Plr.Bullet(i).DVector.X, Plr.Bullet(i).DVector.Y, Plr.Bullet(i).DVector.Z
                        alSourcePlay Wav_Src(2)
                        Plr.Bullet(i).Emission(0) = 1                    
                        Plr.Bullet(i).Emission(3) = 1
                        Plr.Bullet(i).RGBAlpha(0) = 1
                        Plr.Bullet(i).RGBAlpha(1) = .5
                        Plr.Bullet(i).RGBAlpha(2) = .05
                        Plr.Bullet(i).RGBAlpha(3) = 1
                        'Bullet(i).DVector.X+=Model(1)->Face[i3].Normal.X
                        'Bullet(i).DVector.Y+=Model(1)->Face[i3].Normal.Y
                        'Bullet(i).DVector.z+=Model(1)->Face[i3].Normal.Z
                        'Vector_Normalize Bullet(i).DVector
                    End If
                Next
                Plr.Bullet(i).Position.X = tLine(2).X
                Plr.Bullet(i).Position.Y = tLine(2).Y
                Plr.Bullet(i).Position.Z = tLine(2).Z
            End If
            
            If Plr.Bullet(i).Explosion>0 Then
                Plr.Bullet(i).Explosion+=.1
                If Plr.Bullet(i).Explosion>=1 Then
                    Plr.Bullet(i).Explosion=0
                    Plr.Bullet(i).Active=0
                End If
                
                tDist=Distance(Plr.Cam.Position, Plr.Bullet(i).Position)
                If tDist<= (Plr.Radius+Plr.Bullet(i).Explosion) Then
                    Plr.Gravity=0
                    Plr.vVector.X=((Plr.Cam.Position.X-Plr.Bullet(i).Position.X)/tDist*.4)
                    Plr.vVector.Y=((Plr.Cam.Position.Y-Plr.Bullet(i).Position.Y)/tDist*.4)
                    Plr.vVector.Z=((Plr.Cam.Position.Z-Plr.Bullet(i).Position.Z)/tDist*.4)
                    Plr.Health-=(((Plr.Radius+1+Plr.Bullet(i).Explosion)*1.5)-tDist)
                    SourcePos(0) = Plr.Cam.Position.X
                    SourcePos(1) = Plr.Cam.Position.Y
                    SourcePos(2) = Plr.Cam.Position.Z
                    alSourcefv Wav_Src(4), AL_POSITION, @SourcePos(0)
                    alSourcePlay Wav_Src(4)
                End If
            End If
        End If
    Next
    
    
    
    
    If Plr.Weapon Then
        Entity(Plr.Weapon).RVector.X = Plr.Cam.RVector.X
        Entity(Plr.Weapon).RVector.Y = Plr.Cam.RVector.Y
        Entity(Plr.Weapon).RVector.Z = Plr.Cam.RVector.Z
        
        Entity(Plr.Weapon).UVector.X = Plr.Cam.UVector.X
        Entity(Plr.Weapon).UVector.Y = Plr.Cam.UVector.Y
        Entity(Plr.Weapon).UVector.Z = Plr.Cam.UVector.Z  
        
        Entity(Plr.Weapon).DVector.X = Plr.Cam.DVector.X
        Entity(Plr.Weapon).DVector.Y = Plr.Cam.DVector.Y
        Entity(Plr.Weapon).DVector.Z = Plr.Cam.DVector.Z
        
        Entity(Plr.Weapon).Position.X = Plr.Cam.Position.X+(Plr.Cam.DVector.X*.2)+(Plr.Cam.RVector.X*.1)+(Plr.Cam.UVector.X*-.05)
        Entity(Plr.Weapon).Position.Y = Plr.Cam.Position.Y+(Plr.Cam.DVector.Y*.2)+(Plr.Cam.RVector.Y*.1)+(Plr.Cam.UVector.Y*-.05)
        Entity(Plr.Weapon).Position.Z = Plr.Cam.Position.Z+(Plr.Cam.DVector.Z*.2)+(Plr.Cam.RVector.Z*.1)+(Plr.Cam.UVector.Z*-.05)
        
        Rot_X Entity(Plr.Weapon), Recoil.X/10
    End If
    
    Entity(Plr.Weapon).Angle.X *= .95
    Recoil.X *= .95
    If Plr.Firing =1 And Plr.Weapon Then
        Plr.BulletCnt+=1        
        If Plr.BulletCnt>=Ubound(Plr.Bullet) Then Plr.BulletCnt = 1
        If Plr.Bullet(Plr.BulletCnt).Active=0 Then
            If SDL_GetTicks()>=Plr.Shot_Delay Then
                Entity(2).Angle.X = .1
                Recoil.X = 0
                Plr.Shot_Delay = SDL_GetTicks() + 50
                Plr.Bullet(Plr.BulletCnt).Active=1
                Plr.Bullet(Plr.BulletCnt).Explosion=0
                Plr.Bullet(Plr.BulletCnt).Randimation = (Plr.BulletCnt Mod 2) '* 2
                Plr.Bullet(Plr.BulletCnt).Position.X=Entity(Plr.Weapon).Position.X '+ (Entity(Plr.Weapon).DVector.X)
                Plr.Bullet(Plr.BulletCnt).Position.Y=Entity(Plr.Weapon).Position.Y '+ (Entity(Plr.Weapon).DVector.Y)
                Plr.Bullet(Plr.BulletCnt).Position.Z=Entity(Plr.Weapon).Position.Z '+ (Entity(Plr.Weapon).DVector.Z)
                Plr.Bullet(Plr.BulletCnt).DVector.X=Entity(Plr.Weapon).DVector.X
                Plr.Bullet(Plr.BulletCnt).DVector.Y=Entity(Plr.Weapon).DVector.Y
                Plr.Bullet(Plr.BulletCnt).DVector.Z=Entity(Plr.Weapon).DVector.Z
                Plr.Bullet(Plr.BulletCnt).UVector.X=Entity(Plr.Weapon).UVector.X
                Plr.Bullet(Plr.BulletCnt).UVector.Y=Entity(Plr.Weapon).UVector.Y
                Plr.Bullet(Plr.BulletCnt).UVector.Z=Entity(Plr.Weapon).UVector.Z
                Plr.Bullet(Plr.BulletCnt).RVector.X=Entity(Plr.Weapon).RVector.X
                Plr.Bullet(Plr.BulletCnt).RVector.Y=Entity(Plr.Weapon).RVector.Y
                Plr.Bullet(Plr.BulletCnt).RVector.Z=Entity(Plr.Weapon).RVector.Z
                
                Plr.Bullet(Plr.Bulletcnt).RGBAlpha(0)=1
                Plr.Bullet(Plr.Bulletcnt).RGBAlpha(1)=1
                Plr.Bullet(Plr.Bulletcnt).RGBAlpha(2)=1
                Plr.Bullet(Plr.Bulletcnt).RGBAlpha(3)=1
                alSourcefv Wav_Src(1), AL_POSITION, @ListenerPos(0)
                alSourcePlay Wav_Src(1)
            End If
        End If
    End If
    
    
    
Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
neo
Novice
***
Gender: Male
Posts: 77


View Profile Email
« Reply #1 on: September 23, 2013, 03:40:14 PM »

   
    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:")
        
      
Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
neo
Novice
***
Gender: Male
Posts: 77


View Profile Email
« Reply #2 on: September 23, 2013, 03:43:09 PM »

sorry can put up all the code
Logged

IF you can make a game that's cool and fun....
in time you may have a good job in time ......

its like at the end of doom 2 what do i have to kill next lol put code in my brain and i will think mmmm css rocks
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Cerberus design by Bloc
Valid XHTML 1.0! Valid CSS!
gfx
gfxgfx gfxgfx