Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Need help with a VERY simple Airplane project  (Read 3129 times)
Magnum357jhp
Community Member
*
Posts: 128


« on: September 02, 2009, 04:09:12 PM »

I made this VERY simple airplane project a while back, then abandon it for a while then decided to work on it a little again (just for curiosity), but I could never get the thing to work properly.  The problem is with the airplanes "Yaw" function, the Pitch and Roll seem to work ok, but I just could never get the Yaw function of the plane working right.  Every time I try to turn the plane left or right it would just fly around in a tight circle.  I know the Roll function is suppose to relate with the Yaw function, but I just could never figure out how it relates with the Yaw.  Here is the code I have for the project...

Code:
Option Explicit

Private TV8 As TVEngine
Private Room As TVMesh
Private Scene As TVScene
Private InputEngine As TVInputEngine
Private Atmos As TVAtmosphere
Private TextureFactory As TVTextureFactory
Private Camera As TVCamera

Private DoLoop As Boolean
Private Angle As Single
Private Distance As Single
Private Altitude As Single

Private Airplane As TVMesh
Private AirplanePosition As D3DVECTOR
Private AirplaneTurn As Single
Private Pitch As Single
Private Yaw As Single
Private PitchSpeed As Single
Private YawSpeed As Single
Private Roll As Single
Private Thrust As Single
Private Friction As Single
Private Land As TVMesh

'used to control Airplane
Private Ignition As Integer
'camera positions
Private CameraPos As D3DVECTOR
Private CameraPoint As D3DVECTOR

Const PI = 3.14



Private Sub cmdQuit_Click()
    DoLoop = False
End Sub

Private Sub Form_Load()

    Set TV8 = New TVEngine
    TV8.SetSearchDirectory App.Path
    TV8.Init3DWindowedMode Picture1.hWnd
    TV8.DisplayFPS = True
    TV8.SetDebugFile App.Path + "\deb.txt"
   
    Set InputEngine = New TVInputEngine
    Set Scene = New TVScene
    Set Camera = New TVCamera
    ' We create the atmosphere (for sky)
    Set Atmos = New TVAtmosphere
    Set TextureFactory = New TVTextureFactory
    Set Land = New TVMesh
    Set Airplane = New TVMesh
   
    Scene.LoadTexture App.Path + "..\..\..\Media\top.bmp", , , "Top"
    Scene.LoadTexture App.Path + "..\..\..\Media\bottom.bmp", , , "Bottom"
    Scene.LoadTexture App.Path + "..\..\..\Media\left.bmp", , , "Left"
    Scene.LoadTexture App.Path + "..\..\..\Media\right.bmp", , , "Right"
    Scene.LoadTexture App.Path + "..\..\..\Media\front.bmp", , , "Front"
    Scene.LoadTexture App.Path + "..\..\..\Media\back.bmp", , , "Back"
    TextureFactory.LoadTexture App.Path + "..\..\Media\bihull.bmp", "bihull", , , TV_COLORKEY_NO, True, True
    TextureFactory.LoadTexture App.Path + "..\..\Media\land.bmp", "land", , , TV_COLORKEY_NO, True, True
   
    Atmos.SkyBox_SetTexture GetTex("Front"), GetTex("Back"), GetTex("Left"), GetTex("Right"), GetTex("Top"), GetTex("Bottom")
    Atmos.SkyBox_Enable True
    Atmos.SkyBox_SetColor 1, 1, 1, 1
   
    Set Land = Scene.CreateMeshBuilder
    Land.Load3DsMesh App.Path + "..\..\Simple Movement\Land.3ds", False
    Land.SetMaterial 0
    Land.SetTexture GetTex("Land")
    Land.SetCullMode TV_FRONT_CULL
    Land.SetPosition 0, -10, 0
    Land.ScaleMesh 10000, 0, 10000
   
    Set Airplane = Scene.CreateMeshBuilder
    Airplane.Load3DsMesh App.Path + "..\..\Simple Movement\Airplane.3ds", False
    Airplane.SetMaterial 0
    Airplane.SetTexture GetTex("bihull")
    Airplane.SetCullMode TV_FRONT_CULL
    Airplane.SetPosition AirplanePosition.x, AirplanePosition.y, AirplanePosition.z
   
    Angle = 0
    Distance = -250
    Altitude = 30
   
    Form1.Show
       
    Scene.SetViewFrustum 28, 50000
   
    DoLoop = True
    Main_Loop

End Sub

Private Sub Form_Unload(Cancel As Integer)

    DoLoop = False
    Main_Quit

End Sub

Private Sub Main_Loop()
   
    Do
        DoEvents
        Check_Input
        Check_Movement
        Update_Camera
        TV8.Clear
        Atmos.Atmosphere_Render
        Scene.RenderAllMeshes
        TV8.RenderToScreen
   
    Loop Until DoLoop = False
   
    Main_Quit

End Sub

Private Sub Main_Quit()
   
    Set Land = Nothing
    Set InputEngine = Nothing
    Set TV8 = Nothing
    End

End Sub

Private Sub Check_Input()
    'pitch
    If InputEngine.IsKeyPressed(TV_KEY_UP) = True Then
        Pitch = Pitch + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_DOWN) = True Then
        Pitch = Pitch - Thrust
    End If
   
    'yaw
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Yaw = Yaw - Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Yaw = Yaw + Thrust
    End If

    'roll
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Roll = Roll + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Roll = Roll - Thrust
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_SPACE) = True Then
       
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_1) Then
        Ignition = 1
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_2) Then
        Ignition = 2
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_3) Then
        Ignition = 3
    End If
   
    Select Case Pitch
    Case Is > 0
        Pitch = Pitch - Friction
        If Pitch < 0 Then Pitch = 0
        If Pitch > 0.5 Then Pitch = 0.5
    Case Is < 0
        Pitch = Pitch + Friction
        If Pitch > 0 Then Pitch = 0
        If Pitch < -0.5 Then Pitch = -0.5
    End Select
   
    Select Case Yaw
    Case Is > 0
        Yaw = Yaw
        If Yaw > 0 Then
            Yaw = 1
            AirplaneTurn = AirplaneTurn + 2 * PI * (Thrust / Yaw)
        End If
    Case Is < 0
        Yaw = Yaw
        If Yaw < 0 Then
            Yaw = -1
            AirplaneTurn = AirplaneTurn + 2 * PI * (Thrust / Yaw)
        End If
    End Select
   
    Select Case Roll
    Case Is > 0
        Roll = Roll - Friction
        If Roll < 0 Then Roll = 0
        If Roll > 1 Then Roll = 1
    Case Is < 0
        Roll = Roll + Friction
        If Roll > 0 Then Roll = 0
        If Roll < -1 Then Roll = -1
    End Select
   
    Select Case Ignition
        Case Is = 1:
            Thrust = 0
        Case Is = 2:
            Thrust = TV8.TimeElapsed / 2000
        Case Is = 3:
            Thrust = TV8.TimeElapsed / 1000
        Case Is = 4:
        Case Is = 5:
    End Select
    Label2.Caption = Yaw
    Label4.Caption = Pitch
   
End Sub

Private Sub Check_Movement()
   
    Friction = TV8.TimeElapsed / 10000
    Airplane.MoveRelative Thrust * 1000, AirplanePosition.y - Pitch * 2, AirplanePosition.x + Yaw
    Airplane.SetRotation Pitch, AirplaneTurn, Roll * 2
   
End Sub

Private Sub Update_Camera()
   
    CameraPos.x = Airplane.GetPosition.x
    CameraPos.y = Airplane.GetPosition.y
    CameraPos.z = Airplane.GetPosition.z
    Camera.SetPosition CameraPos.x, CameraPos.y + 25, CameraPos.z - 150
   
End Sub

I hope someone can help me on this, because I wouldn't mind getting the airplane to work properly.  I forgot to mention that this was built with VB6.
« Last Edit: September 03, 2009, 03:03:26 PM by Magnum357jhp » Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
ZaPPZion
Moderator
Community Member
*****
Posts: 555


« Reply #1 on: September 03, 2009, 07:51:12 AM »

Please put the code in code [] so like this without the dot: [code.] code here [/code.]
Logged

Check out my website: www.bartkuipers.com
Magnum357jhp
Community Member
*
Posts: 128


« Reply #2 on: September 03, 2009, 03:04:19 PM »

There, its in a code box now.  Smiley  Can anyone help me with the Yaw of this project?
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
ZaPPZion
Moderator
Community Member
*****
Posts: 555


« Reply #3 on: September 03, 2009, 03:16:30 PM »

It seems like you use Yaw to move the plane instead of rotating it? Or is that just me looking in the wrong spot?
Logged

Check out my website: www.bartkuipers.com
Magnum357jhp
Community Member
*
Posts: 128


« Reply #4 on: September 03, 2009, 03:30:57 PM »

Well, this part of the code is what really moves the plane in the scene...

Code:
Private Sub Check_Movement()
   
    Friction = TV8.TimeElapsed / 10000
    Airplane.MoveRelative Thrust * 1000, AirplanePosition.y - Pitch * 2, AirplanePosition.x + Yaw
    Airplane.SetRotation Pitch, AirplaneTurn, Roll * 2
   
End Sub

The Airplane.MoveRelative (according to the TV3DWiki) is setup as Airplane.MoveRelative "Forward Movement", "Altitude", "Left/Right Movement".  Just recently, I tried changing the last part of this function to "Airplane" turn instead of just Yaw, but it still just gives me the plane flying in a tight circle and hardly any control.

Just incase this is a factor, I'm using an old verion of Truevision (version 6.2 or something) but I don't think its much different then in 6.3.
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Magnum357jhp
Community Member
*
Posts: 128


« Reply #5 on: September 05, 2009, 05:40:13 PM »

So does anyone have any suggestions to my problem about the Yaw function? 

Any info would be helpful.
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
willyg
Community Member
*
Posts: 31


« Reply #6 on: September 13, 2009, 01:55:11 PM »

Hi Magnum357jhp,

I gave it a shot and pasted your code into a vb6 project but I used the TV3d 6.2 engine that I had on one of my older computers.  I basically got the scene and the plane to stop rotating around and it seems to function ok but I noticed that the plane still rotates CCW to the left by a small amount when no left or right key is pressed.  It does this until it reaches a certain position on the screen and then it stops rotating.  I assume the position is where the Yaw angle about the y-axis has returned to zero.  Anyway, I posted your code below with some slight modifications.

You might want to look at a past forum discussion about "Rotating using Quaternions and Avoiding Roll".  In this post, about the 3rd post from the bottom, Vuli gives an excellent explanation of quaternions and also gives a sample vb6 project (Airplane Control) showing its use with an airplane.  I would recommend downloading the sample and give it a try.  It works very nice with flight/space simulation types of games.  Here is the link if you're interested...http://www.truevision3d.com/forums/empty-t11994.0.html;msg100788;topicseen#msg100788

 Smiley Hope this helps.


Code:
Option Explicit

Private TV8              As TVEngine
Private InputEngine      As TVInputEngine
Private Scene            As TVScene
Private Atmos            As TVAtmosphere
Private TextureFactory   As TVTextureFactory
Private Camera           As TVCamera
Private Room             As TVMesh
Private Airplane         As TVMesh
Private Land             As TVMesh

Private AirplanePosition As D3DVECTOR

'camera positions
Private CameraPos        As D3DVECTOR
Private CameraPoint      As D3DVECTOR
Private CamLookAt        As D3DVECTOR  'I added this

Private Angle            As Single
Private Distance         As Single
Private Altitude         As Single
Private AirplaneTurn     As Single
Private Pitch            As Single
Private Yaw              As Single
Private PitchSpeed       As Single
Private YawSpeed         As Single
Private Roll             As Single
Private Thrust           As Single
Private Friction         As Single

'used to control Airplane
Private Ignition         As Integer

Private DoLoop           As Boolean

Const PI = 3.14

Private Sub cmdQuit_Click()
    DoLoop = False
End Sub

Private Sub Form_Load()

    Set TV8 = New TVEngine
    TV8.SetSearchDirectory App.Path
    'TV8.Init3DWindowedMode Picture1.hWnd
    'TV8.Init3DWindowedMode Form1.hWnd, True
    TV8.Init3DFullscreen 1024, 768, 32, True, False, TV_DEPTHBUFFER_32BITS, 1, Form1.hWnd
    TV8.DisplayFPS = True
    TV8.SetDebugFile "c:\Airplane\deb.txt"
   
    Set InputEngine = New TVInputEngine
    Set Scene = New TVScene
    Set Camera = New TVCamera
   
    ' We create the atmosphere (for sky)
    Set Atmos = New TVAtmosphere
    Set TextureFactory = New TVTextureFactory
    Set Land = New TVMesh
    Set Airplane = New TVMesh
   
    Scene.LoadTexture "c:\Airplane\Sky\Up.jpg", , , "Top"
    Scene.LoadTexture "c:\Airplane\Sky\Down.jpg", , , "Bottom"
    Scene.LoadTexture "c:\Airplane\Sky\Left.jpg", , , "Left"
    Scene.LoadTexture "c:\Airplane\Sky\Right.jpg", , , "Right"
    Scene.LoadTexture "c:\Airplane\Sky\Front.jpg", , , "Front"
    Scene.LoadTexture "c:\Airplane\Sky\Back.jpg", , , "Back"
    'TextureFactory.LoadTexture App.Path + "..\..\Media\bihull.bmp", "bihull", , , TV_COLORKEY_NO, True, True
    'TextureFactory.LoadTexture App.Path + "..\..\Media\land.bmp", "land", , , TV_COLORKEY_NO, True, True
   
    Atmos.SkyBox_SetTexture GetTex("Front"), GetTex("Back"), GetTex("Left"), GetTex("Right"), GetTex("Top"), GetTex("Bottom")
    Atmos.SkyBox_Enable True
    Atmos.SkyBox_SetColor 1, 1, 1, 1
   
    'Set Land = Scene.CreateMeshBuilder
    'Land.Load3DsMesh App.Path + "..\..\Simple Movement\Land.3ds", False
    'Land.SetMaterial 0
    'Land.SetTexture GetTex("Land")
    'Land.SetCullMode TV_FRONT_CULL
    'Land.SetPosition 0, -10, 0
    'Land.ScaleMesh 10000, 0, 10000
   
    'Set Airplane = Scene.CreateMeshBuilder
    'Airplane.Load3DsMesh App.Path + "..\..\Simple Movement\Airplane.3ds", False
    'Airplane.SetMaterial 0
    'Airplane.SetTexture GetTex("bihull")
    'Airplane.SetCullMode TV_FRONT_CULL
    'Airplane.SetPosition AirplanePosition.x, AirplanePosition.y, AirplanePosition.z
    Set Airplane = Scene.CreateMeshBuilder("Airplane")
    Airplane.Load3DSMesh "c:\Airplane\Model\airplane.3ds", True, True, False, True, True
    Airplane.SetPosition AirplanePosition.x, AirplanePosition.Y, AirplanePosition.Z
    'mTVMeshAirplane.SetMaterial GetMat("Standard")

    Angle = 0
    Distance = -250
    Altitude = 30
   
    Form1.Show
       
    Scene.SetViewFrustum 60, 50000   'I changed just a little
   
    DoLoop = True
    Main_Loop

End Sub

Private Sub Form_Unload(Cancel As Integer)

    DoLoop = False
    Main_Quit

End Sub

Private Sub Main_Loop()
   
    Do
        DoEvents
       
        Check_Input
        Check_Movement
        Update_Camera
        TV8.Clear
        Atmos.Atmosphere_Render
        Scene.RenderAllMeshes
        TV8.RenderToScreen
   
    Loop Until DoLoop = False
   
    Main_Quit

End Sub

Private Sub Main_Quit()
   
    Set Land = Nothing
    Set InputEngine = Nothing
    Set TV8 = Nothing
    End

End Sub

Private Sub Check_Input()
   
    Friction = TV8.AccurateTimeElapsed / 10000
   
    If InputEngine.IsKeyPressed(TV_KEY_1) Then
        Ignition = 1
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_2) Then
        Ignition = 2
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_3) Then
        Ignition = 3
    End If
   
    Select Case Ignition
        Case Is = 1:
            Thrust = 0
        Case Is = 2:
            Thrust = TV8.AccurateTimeElapsed / 2000
        Case Is = 3:
            Thrust = TV8.AccurateTimeElapsed / 1000
        '''Case Is = 4:
        '''Case Is = 5:
    End Select
   
    'pitch
    If InputEngine.IsKeyPressed(TV_KEY_UP) = True Then
        Pitch = Pitch + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_DOWN) = True Then
        Pitch = Pitch - Thrust
    End If
   
    'yaw
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Yaw = Yaw - Thrust
        Roll = Roll + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Yaw = Yaw + Thrust
        Roll = Roll - Thrust
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) And InputEngine.IsKeyPressed(TV_KEY_LEFT) = False Then
        Yaw = 0
        Roll = 0
    End If
   
    'roll
    'If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        'Roll = Roll + Thrust
    'ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        'Roll = Roll - Thrust
    'End If
   
    Select Case Pitch
    Case Is > 0
        Pitch = Pitch - Friction
        If Pitch < 0 Then Pitch = 0
        If Pitch > 0.5 Then Pitch = 0.5
    Case Is < 0
        Pitch = Pitch + Friction
        If Pitch > 0 Then Pitch = 0
        If Pitch < -0.5 Then Pitch = -0.5
    End Select
   
    Select Case Yaw
    Case Is > 0
        'Yaw = Yaw
        Yaw = Yaw - Friction  'added the friction part here
        'If Yaw > 0 Then
        'Yaw = 1
        If Yaw < 0 Then Yaw = 0.03
        'AirplaneTurn = AirplaneTurn - (Thrust / Yaw)
        'AirplaneTurn = AirplaneTurn - Yaw
        'End If
    Case Is < 0
        'Yaw = Yaw
        'If Yaw < 0 Then
        'Yaw = -1
        Yaw = Yaw + Friction
        If Yaw > 0 Then Yaw = 0
        If Yaw < -0.03 Then Yaw = -0.03
        'AirplaneTurn = AirplaneTurn + (Thrust / Yaw)
        'AirplaneTurn = AirplaneTurn + Yaw
        'End If
    End Select
   
    Select Case Roll
    Case Is > 0
        Roll = Roll - Friction
        If Roll < 0 Then Roll = 0
        '''If Roll > 0.5 Then Roll = 0.5
        If Roll > 1 Then Roll = 1
    Case Is < 0
        Roll = Roll + Friction
        If Roll > 0 Then Roll = 0
        '''If Roll < -0.5 Then Roll = -0.5
        If Roll < -1 Then Roll = -1
    End Select
   
    '''Label2.Caption = Yaw
    '''Label4.Caption = Pitch
   
   
    If InputEngine.IsKeyPressed(TV_KEY_SPACE) = True Then
        'Had to add some code here
        DoLoop = False
        Main_Quit
       
    End If
   
End Sub

Private Sub Check_Movement()
   
    'Friction = TV8.TimeElapsed / 10000
    'Airplane.MoveRelative Thrust * 1000, AirplanePosition.Y - Pitch * 2, AirplanePosition.x + Yaw
    'Airplane.MoveRelative 1 * Thrust, 0, 0
    Airplane.MoveRelative Thrust * 1000, 0, 0
    'Airplane.SetRotation Pitch, AirplaneTurn, Roll * 2
    Airplane.SetRotation Pitch, Yaw, Roll
    '''Airplane.MoveRelative 1 * Thrust, AirplanePosition.Y - Pitch * 2, AirplanePosition.x + Yaw
   
End Sub

Private Sub Update_Camera()
   
    'CameraPos.x = Airplane.GetPosition.x
    'CameraPos.Y = Airplane.GetPosition.Y
    'CameraPos.Z = Airplane.GetPosition.Z
    'CameraPos.x = 0
    'CameraPos.Y = 50
    'CameraPos.Z = Airplane.GetPosition.Z - 2000
     
    'Camera.SetPosition CameraPos.x, CameraPos.Y + 25, CameraPos.Z - 750
   
    'CameraPos = Airplane.GetWorldPosition(Vector3(0, 25, -475))
    'Camera.SetPosition CameraPos.x, CameraPos.Y, CameraPos.Z
    Camera.SimpleFollowing Airplane, Vector3(0, 225, -1200)
    'CamLookAt.x = 0
    'CamLookAt.Y = 5
    'CamLookAt.Z = 50000
 
    'Camera.ChaseCamera Airplane, CameraPos, CamLookAt, 1, True, 1, False, 1
     
End Sub
Logged
willyg
Community Member
*
Posts: 31


« Reply #7 on: September 14, 2009, 08:24:52 PM »

 Shocked Ooopppsss, I just noticed that I forgot to delete or comment out a certain portion of the code that I pasted above.

You might want to delete the following:

Code:
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) And InputEngine.IsKeyPressed(TV_KEY_LEFT) = False Then
        Yaw = 0
        Roll = 0
    End If
Logged
Magnum357jhp
Community Member
*
Posts: 128


« Reply #8 on: September 16, 2009, 02:51:00 PM »

Thank you for the suggestions.  I made changes as you indicated and here is the following code that I'm using now...

Code:
Option Explicit

Private TV8 As TVEngine
Private Room As TVMesh
Private Scene As TVScene
Private InputEngine As TVInputEngine
Private Atmos As TVAtmosphere
Private TextureFactory As TVTextureFactory
Private Camera As TVCamera

Private DoLoop As Boolean
Private Angle As Single
Private Distance As Single
Private Altitude As Single

Private Airplane As TVMesh
Private AirplanePosition As D3DVECTOR
Private AirplaneTurn As Single
Private Pitch As Single
Private Yaw As Single
Private PitchSpeed As Single
Private YawSpeed As Single
Private Roll As Single
Private Thrust As Single
Private Friction As Single
Private Land As TVMesh

'used to control Airplane
Private Ignition As Integer
'camera positions
Private CameraPos As D3DVECTOR
Private CameraPoint As D3DVECTOR
Private CamLookAt As D3DVECTOR  'I added this

Const PI = 3.14



Private Sub cmdQuit_Click()
    DoLoop = False
End Sub

Private Sub Form_Load()

    Set TV8 = New TVEngine
    TV8.SetSearchDirectory App.Path
    TV8.Init3DWindowedMode Picture1.hWnd
    TV8.DisplayFPS = True
    TV8.SetDebugFile App.Path + "\deb.txt"
   
    Set InputEngine = New TVInputEngine
    Set Scene = New TVScene
    Set Camera = New TVCamera
    ' We create the atmosphere (for sky)
    Set Atmos = New TVAtmosphere
    Set TextureFactory = New TVTextureFactory
    Set Land = New TVMesh
    Set Airplane = New TVMesh
   
    Scene.LoadTexture App.Path + "..\..\..\Media\top.bmp", , , "Top"
    Scene.LoadTexture App.Path + "..\..\..\Media\bottom.bmp", , , "Bottom"
    Scene.LoadTexture App.Path + "..\..\..\Media\left.bmp", , , "Left"
    Scene.LoadTexture App.Path + "..\..\..\Media\right.bmp", , , "Right"
    Scene.LoadTexture App.Path + "..\..\..\Media\front.bmp", , , "Front"
    Scene.LoadTexture App.Path + "..\..\..\Media\back.bmp", , , "Back"
    TextureFactory.LoadTexture App.Path + "..\..\Media\bihull.bmp", "bihull", , , TV_COLORKEY_NO, True, True
    TextureFactory.LoadTexture App.Path + "..\..\Media\land.bmp", "land", , , TV_COLORKEY_NO, True, True
   
    Atmos.SkyBox_SetTexture GetTex("Front"), GetTex("Back"), GetTex("Left"), GetTex("Right"), GetTex("Top"), GetTex("Bottom")
    Atmos.SkyBox_Enable True
    Atmos.SkyBox_SetColor 1, 1, 1, 1
   
    Set Land = Scene.CreateMeshBuilder
    Land.Load3DsMesh App.Path + "..\..\Simple Movement\Land.3ds", False
    Land.SetMaterial 0
    Land.SetTexture GetTex("Land")
    Land.SetCullMode TV_FRONT_CULL
    Land.SetPosition 0, -10, 0
    Land.ScaleMesh 10000, 0, 10000
   
    Set Airplane = Scene.CreateMeshBuilder
    Airplane.Load3DsMesh App.Path + "..\..\Simple Movement\Airplane.3ds", False
    Airplane.SetMaterial 0
    Airplane.SetTexture GetTex("bihull")
    Airplane.SetCullMode TV_FRONT_CULL
    Airplane.SetPosition AirplanePosition.x, AirplanePosition.y, AirplanePosition.z
   
    Angle = 0
    Distance = -250
    Altitude = 30
   
    Form1.Show
       
    Scene.SetViewFrustum 28, 50000
   
    DoLoop = True
    Main_Loop

End Sub

Private Sub Form_Unload(Cancel As Integer)

    DoLoop = False
    Main_Quit

End Sub

Private Sub Main_Loop()
   
    Do
        DoEvents
        Check_Input
        Check_Movement
        Update_Camera
        TV8.Clear
        Atmos.Atmosphere_Render
        Scene.RenderAllMeshes
        TV8.RenderToScreen
   
    Loop Until DoLoop = False
   
    Main_Quit

End Sub

Private Sub Main_Quit()
   
    Set Land = Nothing
    Set InputEngine = Nothing
    Set TV8 = Nothing
    End

End Sub

Private Sub Check_Input()
    'pitch
    If InputEngine.IsKeyPressed(TV_KEY_UP) = True Then
        Pitch = Pitch + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_DOWN) = True Then
        Pitch = Pitch - Thrust
    End If
   
    'yaw
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Yaw = Yaw - Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Yaw = Yaw + Thrust
    End If

    'roll
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Roll = Roll + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Roll = Roll - Thrust
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_SPACE) = True Then
       
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_1) Then
        Ignition = 1
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_2) Then
        Ignition = 2
    End If
   
    If InputEngine.IsKeyPressed(TV_KEY_3) Then
        Ignition = 3
    End If
   
    Select Case Pitch
    Case Is > 0
        Pitch = Pitch - Friction
        If Pitch < 0 Then Pitch = 0
        If Pitch > 0.5 Then Pitch = 0.5
    Case Is < 0
        Pitch = Pitch + Friction
        If Pitch > 0 Then Pitch = 0
        If Pitch < -0.5 Then Pitch = -0.5
    End Select
   
    Select Case Yaw
    Case Is > 0
        Yaw = Yaw - Friction
        If Yaw < 0 Then Yaw = 0.03
    Case Is < 0
        Yaw = Yaw + Friction
        If Yaw > 0 Then Yaw = 0
        If Yaw < -0.03 Then Yaw = -0.03
    End Select
   
    Select Case Roll
    Case Is > 0
        Roll = Roll - Friction
        If Roll < 0 Then Roll = 0
        If Roll > 1 Then Roll = 1
    Case Is < 0
        Roll = Roll + Friction
        If Roll > 0 Then Roll = 0
        If Roll < -1 Then Roll = -1
    End Select
   
    Select Case Ignition
        Case Is = 1:
            Thrust = 0
        Case Is = 2:
            Thrust = TV8.TimeElapsed / 2000
        Case Is = 3:
            Thrust = TV8.TimeElapsed / 1000
        Case Is = 4:
        Case Is = 5:
    End Select
    Label2.Caption = Yaw
    Label4.Caption = Pitch
   
End Sub

Private Sub Check_Movement()
   
    Friction = TV8.TimeElapsed / 10000
    Airplane.MoveRelative Thrust * 1000, 0, 0
    Airplane.SetRotation Pitch, Yaw, Roll
   
End Sub

Private Sub Update_Camera()
   
    CameraPos.x = Airplane.GetPosition.x
    CameraPos.y = Airplane.GetPosition.y
    CameraPos.z = Airplane.GetPosition.z
    Camera.SetPosition CameraPos.x, CameraPos.y + 25, CameraPos.z - 150
       
End Sub

The airplane has a little more control then before, but when I turn the plane to the left, it still it wants to "pull" torward back to "0 yaw" instead of flying torward its new vector.  I guess the new code is an improvement, but the Yaw function is still not working properly.  Also, I tried using your new code to allow the camera to follow the plane in flight, but I got an error with the "Vector3" part of your code.  For some reason, I can't get VB to make that part of your follow camera part to work.
« Last Edit: September 16, 2009, 02:54:31 PM by Magnum357jhp » Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
willyg
Community Member
*
Posts: 31


« Reply #9 on: September 17, 2009, 08:44:32 PM »

I'll try to look at your coding some more maybe this weekend.   Huh Not sure why your camera code is not working.  In the meantime you should look at Vuli's VB6 project (which you can download).  It's an airplane flight simulator.  Look at the 2nd paragraph to my first post.  It contains the link to the thread which has the location for the download.  The link is still active.
Logged
Magnum357jhp
Community Member
*
Posts: 128


« Reply #10 on: September 18, 2009, 04:25:02 PM »

Where is this Vuli's VB6 project?  I downloaded an airplane project before, but I couldn't get it to work right, not sure if it was his.  It was rather complex to mine.  As I said, my code might be as basic as you can get for an airplane project. 

I sure hope you can look at this code, as I'm stumped on how to get the Yaw function and follow camera to work right.  Huh
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Magnum357jhp
Community Member
*
Posts: 128


« Reply #11 on: September 18, 2009, 04:32:07 PM »

One thing to keep in mind about this airplane project I'm working on is that the "camera" is not the plane, the airplane is a completely seperate unit that you control in the environment.  Most airplane projects I have seen basically has the camera AS the airplane itself.  Not sure if that is a factor with this, but it might explain why the "Airplane.MoveRelative Thrust * 1000, 0, 0" isn't working with my project. 
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
jviper
Community Member
*
Posts: 2130

Discipline in training


« Reply #12 on: September 18, 2009, 07:35:49 PM »

Code:
If InputEngine.IsKeyPressed(TV_KEY_UP) = True Then
        Pitch = Pitch + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_DOWN) = True Then
        Pitch = Pitch - Thrust
    End If
   
    'yaw
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Yaw = Yaw - Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Yaw = Yaw + Thrust
    End If

    'roll
    If InputEngine.IsKeyPressed(TV_KEY_LEFT) = True Then
        Roll = Roll + Thrust
    ElseIf InputEngine.IsKeyPressed(TV_KEY_RIGHT) = True Then
        Roll = Roll - Thrust
    End If
   

I think you are confusing thrust with torque. Keep in mind when you talk about pitch, yaw, and rool, you are dealing with angles.

Also:
Code:
Airplane.SetRotation Pitch, Yaw, Roll
This will give you wrong results. TVMesh.SetRotation use Eular Angles, which is why you are experiencing the problems you are. What you want to do it rotate the plane around it's axis (rotate about it's foward-pointing axis to roll, rotate about it's right-pointing axsis to pitch, and rotate about it's up-pointing axis to yaw). Use TVMesh.GetBasisAxis to get those 3 axis, use the TVMath.TVMatrixRotationAxis to get a matrix that will do the rotating, and multiply this rotating matrix by the mesh's rotation matrix.

So why can't you just use TVMesh.SetRotation? If you use TVMesh.SetRotation, if you do not run into the dreaded gimbal lock, you are going to run into gimbal lock artifacts. One such artifact is when you try to only do a yaw, it might roll as well, and there will be no simple way to make it only do a yaw in all situations.

On the other hand, this is a feature, to make the function consistant.
Logged

JAbstract.....Don't just imagine, make it happen!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks