thanks for all your ideas and help, i still have not found the problem so im going to release all of the source for you guys to see maybe that will help... i just started so it shouldnt matter to much, the types are not finalized and many of the fields are not used
here are the functions
;A Positional Vector
Type Vector3
Field x#,y#,z#
End Type
;A Color Vector
Type Vector4
Field a,r,g,b
End Type
;The Ship Type
Type Ship
Field Acceleration#;the acceleration of our ship
Field Position.Vector3;the position of our ship
Field Velocity.Vector3;the Velocity of our ship
Field Rotation.Vector3;the Direction our ship is going
Field Model;the model our ship is using
Field Size.Vector3;the size of our ship
Field Name$
End Type
Function CreateVector3.Vector3(x#,y#,z#)
v.Vector3 = New Vector3
v\x = x#
v\y = y#
v\z = z#
Return v
End Function
Function CreateVector4.Vector4(a,r,g,b)
v.Vector4 = New Vector4
v\a = a
v\r = r
v\g = g
v\b = b
Return v
End Function
Function Initialize()
Graphics3D 640,480,32,1
SetBuffer BackBuffer()
Camera = CreateCamera()
PositionEntity Camera,0,5,-10
End Function
Function CreateShip.Ship(filename$)
;Create The object and zero all variables
this.Ship = New Ship
this\Position = CreateVector3(0.0,0.0,0.0)
this\Velocity = CreateVector3(0.0,0.0,0.0)
this\Rotation = CreateVector3(0.0,0.0,0.0)
this\Size = CreateVector3(0.0,0.0,0.0)
corrected = False
in = ReadFile(filename)
;While not the end of the file
While Not Eof(in)
inLine$ = ReadLine$(in)
If Instr(inLine$,"Ship Config 0.1")
corrected = True
EndIf
If corrected = True And Instr(inLine$,"Ship.Name")
e = Instr(inLine$,"=")
this\Name = Mid$(inLine$,e+2,Len(inLine$))
EndIf
If corrected = True And Instr(inLine$,"Ship.Model")
e = Instr(inLine$,"=")
this\Model = LoadMesh(Mid$(inLine$,e+2,Len(inLine$)))
EndIf
If corrected = True And Instr(inLine$,"Ship.Size.x")
e = Instr(inLine$,"=")
this\Size\x = Mid$(inLine$,e+2,Len(inLine$))
EndIf
If corrected = True And Instr(inLine$,"Ship.Size.y")
e = Instr(inLine$,"=")
this\Size\y = Mid$(inLine$,e+2,Len(inLine$))
EndIf
If corrected = True And Instr(inLine$,"Ship.Size.z")
e = Instr(inLine$,"=")
this\Size\z = Mid$(inLine$,e+2,Len(inLine$))
EndIf
If corrected = True And Instr(inLine$,"Ship.Acceleration")
e = Instr(inLine$,"=")
this\Acceleration = Mid$(inLine$,e+2,Len(inLine$))
EndIf
If corrected = True And Instr(inLine$,"Ship.YRotate")
e = Instr(inLine$,"=")
RotateMesh this\Model,0, Mid$(inLine$,e+2,Len(inLine$)),0
EndIf
Wend
CloseFile(in)
If this\Size\x>0 And this\Size\y>0 And this\Size\z> 0
FitMesh this\Model,(this\Size\x/2)*-1,(this\Size\y/2)*-1,(this\Size\z/2)*-1,this\Size\x,this\Size\y,this\Size\z
EndIf
Return this
End Function
Function PushCamera(this.Ship)
v.Vector3 = New Vector3
v\x = EntityX#(this\Model)
v\y = EntityY#(this\Model)
v\z = EntityZ#(this\Model)
End Function
Function PopCamera(this.Ship)
v.Vector3 = First Vector3
If v=Null Then Return
PositionEntity Camera,v\x,v\y,v\z
PointEntity Camera,this\Model
Delete v
End Function
Function Distance#(this.Ship)
Return Sqr#((EntityX#(this\Model)-EntityX#(Camera))*(EntityX#(this\Model)-EntityX#(Camera))+(EntityY#(this\Model)-EntityY#(Camera))*(EntityY#(this\Model)-EntityY#(Camera))+(EntityZ#(this\Model)-EntityZ#(Camera))*(EntityZ#(this\Model)-EntityZ#(Camera)))
End Function
Function UpdateShip(this.Ship)
TranslateEntity this\Model,this\Velocity\x,this\Velocity\y,this\Velocity\z
If this\Velocity\y<1 Then this\Velocity\y = this\Velocity\y-0.001
this\Velocity\z=this\Velocity\z-this\Velocity\z/30
this\Velocity\y=this\Velocity\y-this\Velocity\y/30
this\Velocity\x=this\Velocity\x-this\Velocity\x/30
this\Rotation\x=this\Rotation\x-this\Rotation\x/5
this\Rotation\z=this\Rotation\z-this\Rotation\z/10
PushCamera(this)
End Function
main code
Include "def.bb"
Global Camera
Initialize()
PositionEntity Camera, 0,10,-10
player.Ship = CreateShip("Ships\test.ship")
PositionMesh player\Model,0,MeshHeight#(player\Model)/2,0
ground = CreatePlane()
PositionEntity ground,0,-10,0
For i = 0 To 20
c=CreateCube()
ScaleEntity c,30,100,30
t = LoadTexture("Textures\SkyScraper0"+Rand(1,7)+".jpg")
EntityTexture c,t
PositionEntity c,Rand(1000)-500,50,Rand(1000)-500
Next
While Not KeyDown(1)
PointEntity Camera,player\Model
If KeyDown(200) And player\Rotation\x<10 Then player\Rotation\x = player\Rotation\x+0.5
If KeyDown(208) And player\Rotation\x>-10 Then player\Rotation\x = player\Rotation\x-0.5
If KeyDown(203) And player\Rotation\z<10 Then player\Rotation\z= player\Rotation\z+0.5
If KeyDown(205) And player\Rotation\z>-10 Then player\Rotation\z=player\Rotation\z-0.5
If KeyDown(57) And Sqr#(player\Velocity\x*player\Velocity\x+player\Velocity\y*player\Velocity\y+player\Velocity\z*player\Velocity\z)<7
player\Velocity\x = player\Velocity\x - Sin#(EntityYaw#(player\Model))*player\Acceleration
player\Velocity\y = player\Velocity\y - Sin#(EntityPitch#(player\Model))*player\Acceleration
player\Velocity\z = player\Velocity\z + Cos#(EntityYaw#(player\Model))*player\Acceleration
EndIf
If Distance#(player)>20
PopCamera(player)
EndIf
TurnEntity player\Model,player\Rotation\x,0,player\Rotation\z
UpdateShip(player)
RenderWorld()
Flip()
Wend