Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: (Solved) Problem with Tutorial 16 - Add trees to landscape  (Read 1032 times)
Dimple
Community Member
*
Posts: 539


« on: March 09, 2010, 09:51:46 PM »

Hello,

I'm having a problem with Alpha I do believe and have tried things I've found on the forums but nothing has worked yet. Anyone able to spot whatever I've missed?



Code:
Option Strict Off
Option Explicit On
' Import the MTV3D65 library.
Imports MTV3D65



Public Class frmMain

    Inherits System.Windows.Forms.Form
    ' ________________________________________________________________________
    ' TRUEVISION 6.5                        (web: http://www.truevision3d.com)
    ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    ' Tutorial 16 : Add trees to landscape
    ' ŻŻŻŻŻŻŻŻŻŻŻ
    ' Description : In this 16th tutorial, we go back a bit. We are going to
    ' ŻŻŻŻŻŻŻŻŻŻŻ   generate a simple landscape and add trees at random
    '               positions. Those trees won't be nothing else than
    '               billboards.
    '
    ' Force explicit declarations
    '
    ' TV Variables (Objects).
    Public TV As TVEngine
    Public Land As TVLandscape

    ' New : we declare the trees. Note that we don't know yet how many
    ' trees we are going to place on the land so we will use a dynamic
    ' array that will be set at run time.
    Public TheTree() As TVMesh

    ' This will be quantity of trees
    Public intTreeQuantity As Short

    Public Globals As TVGlobals
    Public MathLib As TVMathLibrary
    Public TFactory As TVTextureFactory
    Public Scene As TVScene
    Public Inp As TVInputEngine

    ' We are going to use camera (point of view) angles, as well as the
    ' camera position and look at vectors.
    Private sngPositionX As Single
    Private sngPositionY As Single
    Private sngPositionZ As Single
    Private snglookatX As Single
    Private snglookatY As Single
    Private snglookatZ As Single
    Private sngAngleX As Single
    Private sngAngleY As Single

    ' We could have done this in many ways, but we added some smoothing to
    ' the movement se we need to declare two additional variables.
    Private sngWalk As Single
    Private sngStrafe As Single

    Public bDoLoop As Boolean

    Declare Function GetFocus Lib "user32" () As Integer


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(632, 453)
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "TV3D SDK 6.5 Tutorial 16  -  Add trees to landscape"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create the TV Interface first:
        TV = New TVEngine

        ' Set the debug file/options.
        ' Do this before the 3D init so it can log any errors found during init.
        TV.SetDebugMode(True, True)
        TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt")

        ' Set the search directory of the objects, textures, ...
        TV.SetSearchDirectory(System.IO.Path.GetDirectoryName(Application.ExecutablePath))

        ' After setting the beta-key/license its time to init the engine:
        ' If you have the beta-key/license.
        TV.Init3DWindowed(Me.Handle, True)

        'Set Antialiasing Setting to 2 Samples.
        'To smooth out any jagged edges in the scene.
        TV.SetAntialiasing(True, CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_2_SAMPLES)

        ' Something good to do is to enable the auto-resize feature:
        ' Get the default viewport and set autoresize to true for it:
        TV.GetViewport.SetAutoResize(True)

        ' Lets display the FPS:
        TV.DisplayFPS(True)

        ' Set the prefered angle system:
        TV.SetAngleSystem(MTV3D65.CONST_TV_ANGLE.TV_ANGLE_DEGREE)

        ' Now after we are done initializing the TVEngine component lets continue:
        ' Create any other components after TV init.

        Scene = New TVScene

        ' We set the scene color
        Scene.SetBackgroundColor(0.3, 0.7, 0.9)

        ' Input has an additional init method to call.
        Inp = New TVInputEngine
        ' Lets init both keyboard and mouse:
        Inp.Initialize(True, True)

        ' Now we have setup the most basic of components.
        ' Something to think about, if the component has a diffrent construct method
        ' then the Set Object = New TV<NAME>, use that one instead.

        ' For example:
        ' Dim Mesh as TVMesh;
        ' Mesh = Scene.CreateMeshBuilder "MyMesh" <- Instead of Set Mesh = new TVMesh
        ' Same goes for RenderSurface, Viewport etc.


        ' Create new TVGlobals Object
        Globals = New TVGlobals

        ' Create new TVMathLibrary Object
        MathLib = New TVMathLibrary

        ' Create the TVTextureFactory
        TFactory = New TVTextureFactory

        ' The land generation
        'Land = New TVLandscape - no longer used
        Land = Scene.CreateLandscape("Landscape")

        ' Generate the height of the land from the grayscale of the image.
        Land.GenerateTerrain("..\..\..\..\Media\Heightmaps\heightmap.jpg", CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 4, 4, 0, 0, True)
        'Land.SetScale(8, 8, 8)
        ' Then, we load the land texture.
        TFactory.LoadTexture("..\..\..\..\Media\snow.bmp", "LandTexture")

        Dim LandTexture As Integer = Globals.GetTex("LandTexture")
        ' We assign a texture to that land.
        'Land.SetTexture(Globals.GetTex("LandTexture"))

        Land.SetTexture(LandTexture)

        ' New and fun part : we add the trees to the land by using billboards.
        ' what are billboard? There are simply a 2d texture placed somewhere
        ' in a 3D world. They have a height and a width but they don't have
        ' any depth. What the use of using 2D in a 3D world? If you 5 trees,
        ' there are none : create your trees in 3D. If you have 2,500 trees,
        ' then you have a big FPS problem because the engine has to compute
        ' every polygons of each tree. This is where the billboards become
        ' handy because each billboard has only 2 polygons : 2 triangles
        ' that makes the billboard rectangle. Let's start by loading the
        ' tree texture. The texture that we will be using is in a dds format.
        ' DDS format is nothing more than 2 BMP files layered : the first one
        ' is the texture, the second one is the alpha layer. You can create
        ' your own DDS files by using the "DirectX Texture Tool" that come
        ' in the directX9 sdk.

        'Dim Mesh As TVMesh
        'Mesh = New TVMesh
        'Mesh.SetAlphaTest(True)
        'Mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA)
        'Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")
        'TextureFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK)
        'TFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK)
        TFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_USE_ALPHA_CHANNEL)



        ' We define how much trees we are going to create
        intTreeQuantity = 200

        ' We redim (set) the size of the tree array
        ReDim TheTree(intTreeQuantity)

        ' We find a random position for each tree
        Dim i As Short
        '  Declare new TVMesh Object
        TheTree(i) = New TVMesh

        Dim y, x, z As Single
        For i = 1 To intTreeQuantity


            x = (1024 * Rnd())
            z = (1024 * Rnd())
            y = Land.GetHeight(x, z)


            'x = (1440 * Rnd())
            'z = (1440 * Rnd())
            'y = Land.GetHeight(x, z)


            ' We create the iClouds object
            Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")

            ' We create the mesh in the scene and place it. Something important
            ' to remember : if you created your billboard images topdown, you
            ' will have to invert it's texture in a paint editor or by setting
            ' the billboard height negative. And because you create your tree's
            ' billboard with a negative height value, you will have to add extra
            ' height to the Y position.
            'TheTree(i) = Scene.CreateBillboard(Globals.GetTex("TreeTexture"), x, y + 64, z, 64, -64)
            TheTree(i) = Scene.CreateBillboard(TreeTexture, x + 4, y + 64, z, -64, -64)
            TheTree(i).SetBillboardType(MTV3D65.CONST_TV_BILLBOARDTYPE.TV_BILLBOARD_YAXIS)

        Next i

        ' We set the camera vectors (position and look at) and angles.
        sngPositionX = 80
        sngPositionY = 20
        sngPositionZ = 80
        snglookatX = 80
        snglookatY = 20
        snglookatZ = 90
        sngAngleX = 0
        sngAngleY = 0

        ' We set the initial values of movement
        sngWalk = 0
        sngStrafe = 0


        'Set the viewing distance
        'Scene.SetViewFrustum(90, 4000)
        Scene.SetViewFrustum(60, 4000)


        ' Lets setup the Loop:
        bDoLoop = True       

        ' Display the Form
        Me.Show()
        Me.Focus()

        Do While bDoLoop
            ' Check if the application has focus, if yes thats when we process the loop.
            If GetFocus = Me.Handle.ToInt32 Then
                ' The actual render loop:

                ' We check the input
                Check_Input()

                ' We check and update the movement
                Check_Movement()

                ' Clear the the last frame.
                TV.Clear(False)

                ' We render the landscape.
                Land.Render()
                Scene.RenderAllMeshes()
                ' Render Everything
                Scene.RenderAll(True)
                TV.RenderToScreen()

                ' Render Everything
                'Scene.RenderAll(True)

                ' Lets check if the user presses ESC key, if yes we will quit the app.
                If Inp.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE) Then bDoLoop = False
            Else
                ' So we dont call DoEvents to many times if we arent using full CPU power.
                System.Threading.Thread.Sleep(100)
            End If

            ' Process any messages Windows has for the application, do this last:
            Application.DoEvents()
        Loop

        ' Additional Info:
        '
        ' Normally you dont have to keep track of the TV component and free it on closing.
        ' When you free the TV ATL Interface on close it will automatically clean all the internal
        ' objects as well. Such as Mesh's, Textures etc.

        ' Though it might be good to know you do have the ability to destroy and nil objects
        ' for re-creation or cleanup during runtime if you want that.

        ' There are several methods for destroying and cleaning up objects.

        ' TV<NAME>.Destroy , DestroyAll exists for some objects as well, if it is a Factory of some sort.

        ' Some other good destroy methods are:
        ' TVScene.DestroyAllMeshs.
        ' TVTextureFactory.DeleteAllTextures.

        ' And others...
        'We want to quit the project, so we start by destroying

        ' the texture factory.
        TFactory = Nothing

        ' We destroy the TVGlobals Object
        Globals = Nothing

        ' We destroy the TVMathLibrary object.
        MathLib = Nothing

        ' We destroy each tree
        'Dim i As Short
        For i = 1 To intTreeQuantity
            TheTree(i) = Nothing
        Next i

        ' We destroy the land object.
        Land = Nothing

        ' Don't forget to destroy the inputengine object...
        Inp = Nothing

        ' Then, we destroy the scene object.
        Scene = Nothing

        ' Set TV to Nothing
        TV = Nothing

        ' End the application
        End

    End Sub
    Public Sub Check_Input()

        ' Check if we pressed the UP arrow key, if so, then we are
        ' walking forward.
        If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_UP) = True Then

            sngWalk = 1

            ' If we are not walking forward, maybe we are walking backward
            ' by using the DOWN arrow? If so, set walk speed to negative.
        ElseIf Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_DOWN) = True Then

            sngWalk = -1

        End If

        ' Check if we pressed the LEFT arrow key, if so, then strafe
        ' on the left.
        If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFT) = True Then

            sngStrafe = 1

            ' If we are not strafing left, maybe we want to strafe to the
            ' right, using the RIGHT arrow? If so, set strafe to negative.
        ElseIf Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_RIGHT) = True Then

            sngStrafe = -1

        End If

        ' Now, for the mouse input...
        Dim tmpMouseX, tmpMouseY As Integer
        Dim tmpMouseB2, tmpMouseB1, tmpMouseB3 As Short
        Dim tmpMouseScrollOld, tmpMouseScrollNew As Integer

        ' Actual value to old mouse scroller value.
        tmpMouseScrollOld = tmpMouseScrollNew

        ' Get the movement of the mouse.
        Inp.GetMouseState(tmpMouseX, tmpMouseY, tmpMouseB1, tmpMouseB2, tmpMouseB3, tmpMouseScrollNew)

        ' Update the camera angles.
        sngAngleX = sngAngleX - (tmpMouseY / 100)
        sngAngleY = sngAngleY - (tmpMouseX / 100)

    End Sub
    Private Sub Check_Movement()

        ' Simple check of the mouse.
        If sngAngleX > 1.3 Then sngAngleX = 1.3
        If sngAngleX < -1.3 Then sngAngleX = -1.3

        ' Okay, now for the smothing of the movement... Update
        ' the forward and backward (walk) movement.
        Select Case sngWalk
            Case Is > 0
                sngWalk = sngWalk - 0.005 * TV.TimeElapsed
                If sngWalk < 0 Then sngWalk = 0
            Case Is < 0
                sngWalk = sngWalk + 0.005 * TV.TimeElapsed
                If sngWalk > 0 Then sngWalk = 0
        End Select

        ' Now, we update the left and right (strafe) movement.
        Select Case sngStrafe
            Case Is > 0
                sngStrafe = sngStrafe - 0.005 * TV.TimeElapsed
                If sngStrafe < 0 Then sngStrafe = 0
            Case Is < 0
                sngStrafe = sngStrafe + 0.005 * TV.TimeElapsed
                If sngStrafe > 0 Then sngStrafe = 0
        End Select

        ' Update the vectors using the angles and positions.
        sngPositionX = sngPositionX + (System.Math.Cos(sngAngleY) * sngWalk / 5 * TV.TimeElapsed) + (System.Math.Cos(sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed)
        sngPositionZ = sngPositionZ + (System.Math.Sin(sngAngleY) * sngWalk / 5 * TV.TimeElapsed) + (System.Math.Sin(sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed)
        sngPositionY = Land.GetHeight(sngPositionX, sngPositionZ) + 10

        ' We update the look at position.
        snglookatX = sngPositionX + System.Math.Cos(sngAngleY)
        snglookatY = sngPositionY + System.Math.Tan(sngAngleX)
        snglookatZ = sngPositionZ + System.Math.Sin(sngAngleY)

        ' With the new values of the camera vectors (position and
        ' look at), we update the scene's camera.
        Scene.SetCamera(sngPositionX, sngPositionY, sngPositionZ, snglookatX, snglookatY, snglookatZ)

    End Sub



    Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        ' If we close the application stop the loop.
        bDoLoop = False
    End Sub
End Class
« Last Edit: March 13, 2010, 03:03:07 PM by Dimple » Logged

Using VB.NET, TV3D 6.5, VISTA
~~~~~~~~~~~~~~~~~~~~~~~

"Know how to ask. There is nothing more difficult for some people, nor for others, easier."

- Baltasar Gracian
asia
Customers
Community Member
*****
Posts: 182


« Reply #1 on: March 10, 2010, 02:51:37 AM »

You did copy this tutorial from tv6.3 set and you adapted to the tv6.5 syntax.
Well done! But you forgot that in tv6.5 the default for meshes Alphatest is false.
So you should add setalphatest to true for each tree..
Ciao
Fabio

PS
the:
Code:
Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")
should be before the for..next loop
« Last Edit: March 10, 2010, 01:21:58 PM by asia » Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
Dimple
Community Member
*
Posts: 539


« Reply #2 on: March 11, 2010, 03:51:56 PM »

 Shocked

Hmm... I seem to have lost yesterdays post so...  I'm still having problems. I've tried placing Mesh.SetAlphaTest(True) just before the for i next loop but it makes no difference (black billboard)still.  When I placed this:
' We declare TreeTexture as an integer, to be used in place of the string "TreeTexture" (New).
        Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")
Where it's at now, seems to work, but if I place it just about anywhere else I get white billboards then. Please look at the code below and see if you can figure out what I need to do to show the trees on a transparent Billboard. I'm missing whatever is needed.

Code:
Option Strict Off
Option Explicit On
' Import the MTV3D65 library.
Imports MTV3D65



Public Class frmMain

    Inherits System.Windows.Forms.Form
    ' ________________________________________________________________________
    ' TRUEVISION 6.5                        (web: http://www.truevision3d.com)
    ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    ' Tutorial 16 : Add trees to landscape
    ' ŻŻŻŻŻŻŻŻŻŻŻ
    ' Description : In this 16th tutorial, we go back a bit. We are going to
    ' ŻŻŻŻŻŻŻŻŻŻŻ   generate a simple landscape and add trees at random
    '               positions. Those trees won't be nothing else than
    '               billboards.
    '
    ' Force explicit declarations
    '
    ' TV Variables (Objects).
    Public TV As TVEngine
    Public Land As TVLandscape

    ' New : we declare the trees. Note that we don't know yet how many
    ' trees we are going to place on the land so we will use a dynamic
    ' array that will be set at run time.
    Public TheTree() As TVMesh

    ' This will be quantity of trees
    Public intTreeQuantity As Short

    Public Globals As TVGlobals
    Public MathLib As TVMathLibrary
    Public TFactory As TVTextureFactory
    Public Scene As TVScene
    Public Inp As TVInputEngine

    ' We are going to use camera (point of view) angles, as well as the
    ' camera position and look at vectors.
    Private sngPositionX As Single
    Private sngPositionY As Single
    Private sngPositionZ As Single
    Private snglookatX As Single
    Private snglookatY As Single
    Private snglookatZ As Single
    Private sngAngleX As Single
    Private sngAngleY As Single

    ' We could have done this in many ways, but we added some smoothing to
    ' the movement se we need to declare two additional variables.
    Private sngWalk As Single
    Private sngStrafe As Single

    Public bDoLoop As Boolean

    Declare Function GetFocus Lib "user32" () As Integer


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(632, 453)
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "TV3D SDK 6.5 Tutorial 16  -  Add trees to landscape"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create the TV Interface first:
        TV = New TVEngine

        ' Set the debug file/options.
        ' Do this before the 3D init so it can log any errors found during init.
        TV.SetDebugMode(True, True)
        TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt")

        ' Set the search directory of the objects, textures, ...
        TV.SetSearchDirectory(System.IO.Path.GetDirectoryName(Application.ExecutablePath))

        ' After setting the beta-key/license its time to init the engine:
        ' If you have the beta-key/license.
        TV.Init3DWindowed(Me.Handle, True)

        'Set Antialiasing Setting to 2 Samples.
        'To smooth out any jagged edges in the scene.
        TV.SetAntialiasing(True, CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_2_SAMPLES)

        ' Something good to do is to enable the auto-resize feature:
        ' Get the default viewport and set autoresize to true for it:
        TV.GetViewport.SetAutoResize(True)

        ' Lets display the FPS:
        TV.DisplayFPS(True)

        ' Set the prefered angle system:
        TV.SetAngleSystem(MTV3D65.CONST_TV_ANGLE.TV_ANGLE_DEGREE)

        ' Now after we are done initializing the TVEngine component lets continue:
        ' Create any other components after TV init.

        Scene = New TVScene

        ' We set the scene color
        Scene.SetBackgroundColor(0.3, 0.7, 0.9)

        ' Input has an additional init method to call.
        Inp = New TVInputEngine
        ' Lets init both keyboard and mouse:
        Inp.Initialize(True, True)

        ' Now we have setup the most basic of components.
        ' Something to think about, if the component has a diffrent construct method
        ' then the Set Object = New TV<NAME>, use that one instead.

        ' For example:
        ' Dim Mesh as TVMesh;
        ' Mesh = Scene.CreateMeshBuilder "MyMesh" <- Instead of Set Mesh = new TVMesh
        ' Same goes for RenderSurface, Viewport etc.


        ' Create new TVGlobals Object
        Globals = New TVGlobals

        ' Create new TVMathLibrary Object
        MathLib = New TVMathLibrary

        ' Create the TVTextureFactory
        TFactory = New TVTextureFactory

        ' The land generation
        'Land = New TVLandscape - no longer used
        Land = Scene.CreateLandscape("Landscape")

        ' Generate the height of the land from the grayscale of the image.
        Land.GenerateTerrain("..\..\..\..\Media\Heightmaps\heightmap.jpg", CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 4, 4, 0, 0, True)
        'Land.SetScale(8, 8, 8)
        ' Then, we load the land texture.
        TFactory.LoadTexture("..\..\..\..\Media\snow.bmp", "LandTexture")

        Dim LandTexture As Integer = Globals.GetTex("LandTexture")
        ' We assign a texture to that land.
        'Land.SetTexture(Globals.GetTex("LandTexture"))

        Land.SetTexture(LandTexture)

        ' New and fun part : we add the trees to the land by using billboards.
        ' what are billboard? There are simply a 2d texture placed somewhere
        ' in a 3D world. They have a height and a width but they don't have
        ' any depth. What the use of using 2D in a 3D world? If you 5 trees,
        ' there are none : create your trees in 3D. If you have 2,500 trees,
        ' then you have a big FPS problem because the engine has to compute
        ' every polygons of each tree. This is where the billboards become
        ' handy because each billboard has only 2 polygons : 2 triangles
        ' that makes the billboard rectangle. Let's start by loading the
        ' tree texture. The texture that we will be using is in a dds format.
        ' DDS format is nothing more than 2 BMP files layered : the first one
        ' is the texture, the second one is the alpha layer. You can create
        ' your own DDS files by using the "DirectX Texture Tool" that come
        ' in the directX9 sdk.

        Dim Mesh As TVMesh
        Mesh = New TVMesh
        'Mesh.SetAlphaTest(True)
        'Mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA)
        'Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")
        'TextureFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK)
        'TFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK)
        TFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", -1, -1, MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_USE_ALPHA_CHANNEL)


        ' We define how much trees we are going to create
        intTreeQuantity = 200

        ' We declare TreeTexture as an integer, to be used in place of the string "TreeTexture" (New).
        Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")

        ' We redim (set) the size of the tree array
        ReDim TheTree(intTreeQuantity)

        ' We find a random position for each tree
        Dim i As Short
        '  Declare new TVMesh Object
        TheTree(i) = New TVMesh
        Mesh.SetAlphaTest(True)
        Dim y, x, z As Single
        For i = 1 To intTreeQuantity


            x = (1024 * Rnd())
            z = (1024 * Rnd())
            y = Land.GetHeight(x, z)


            'x = (1440 * Rnd())
            'z = (1440 * Rnd())
            'y = Land.GetHeight(x, z)


            ' We create the iClouds object
            'Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")
            ' We create the mesh in the scene and place it. Something important
            ' to remember : if you created your billboard images topdown, you
            ' will have to invert it's texture in a paint editor or by setting
            ' the billboard height negative. And because you create your tree's
            ' billboard with a negative height value, you will have to add extra
            ' height to the Y position.
            'TheTree(i) = Scene.CreateBillboard(Globals.GetTex("TreeTexture"), x, y + 64, z, 64, -64)
            TheTree(i) = Scene.CreateBillboard(TreeTexture, x + 4, y + 64, z, -64, -64)
            TheTree(i).SetBillboardType(MTV3D65.CONST_TV_BILLBOARDTYPE.TV_BILLBOARD_YAXIS)

        Next i

        ' We set the camera vectors (position and look at) and angles.
        sngPositionX = 80
        sngPositionY = 20
        sngPositionZ = 80
        snglookatX = 80
        snglookatY = 20
        snglookatZ = 90
        sngAngleX = 0
        sngAngleY = 0

        ' We set the initial values of movement
        sngWalk = 0
        sngStrafe = 0


        'Set the viewing distance
        'Scene.SetViewFrustum(90, 4000)
        Scene.SetViewFrustum(60, 4000)


        ' Lets setup the Loop:
        bDoLoop = True       

        ' Display the Form
        Me.Show()
        Me.Focus()

        Do While bDoLoop
            ' Check if the application has focus, if yes thats when we process the loop.
            If GetFocus = Me.Handle.ToInt32 Then
                ' The actual render loop:

                ' We check the input
                Check_Input()

                ' We check and update the movement
                Check_Movement()

                ' Clear the the last frame.
                TV.Clear(False)

                ' We render the landscape.
                Land.Render()
                Scene.RenderAllMeshes()
                ' Render Everything
                Scene.RenderAll(True)
                TV.RenderToScreen()

                ' Render Everything
                'Scene.RenderAll(True)

                ' Lets check if the user presses ESC key, if yes we will quit the app.
                If Inp.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE) Then bDoLoop = False
            Else
                ' So we dont call DoEvents to many times if we arent using full CPU power.
                System.Threading.Thread.Sleep(100)
            End If

            ' Process any messages Windows has for the application, do this last:
            Application.DoEvents()
        Loop

        ' Additional Info:
        '
        ' Normally you dont have to keep track of the TV component and free it on closing.
        ' When you free the TV ATL Interface on close it will automatically clean all the internal
        ' objects as well. Such as Mesh's, Textures etc.

        ' Though it might be good to know you do have the ability to destroy and nil objects
        ' for re-creation or cleanup during runtime if you want that.

        ' There are several methods for destroying and cleaning up objects.

        ' TV<NAME>.Destroy , DestroyAll exists for some objects as well, if it is a Factory of some sort.

        ' Some other good destroy methods are:
        ' TVScene.DestroyAllMeshs.
        ' TVTextureFactory.DeleteAllTextures.

        ' And others...
        'We want to quit the project, so we start by destroying

        ' the texture factory.
        TFactory = Nothing

        ' We destroy the TVGlobals Object
        Globals = Nothing

        ' We destroy the TVMathLibrary object.
        MathLib = Nothing

        ' We destroy each tree
        'Dim i As Short
        For i = 1 To intTreeQuantity
            TheTree(i) = Nothing
        Next i

        ' We destroy the land object.
        Land = Nothing

        ' Don't forget to destroy the inputengine object...
        Inp = Nothing

        ' Then, we destroy the scene object.
        Scene = Nothing

        ' Set TV to Nothing
        TV = Nothing

        ' End the application
        End

    End Sub
    Public Sub Check_Input()

        ' Check if we pressed the UP arrow key, if so, then we are
        ' walking forward.
        If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_UP) = True Then

            sngWalk = 1

            ' If we are not walking forward, maybe we are walking backward
            ' by using the DOWN arrow? If so, set walk speed to negative.
        ElseIf Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_DOWN) = True Then

            sngWalk = -1

        End If

        ' Check if we pressed the LEFT arrow key, if so, then strafe
        ' on the left.
        If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFT) = True Then

            sngStrafe = 1

            ' If we are not strafing left, maybe we want to strafe to the
            ' right, using the RIGHT arrow? If so, set strafe to negative.
        ElseIf Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_RIGHT) = True Then

            sngStrafe = -1

        End If

        ' Now, for the mouse input...
        Dim tmpMouseX, tmpMouseY As Integer
        Dim tmpMouseB2, tmpMouseB1, tmpMouseB3 As Short
        Dim tmpMouseScrollOld, tmpMouseScrollNew As Integer

        ' Actual value to old mouse scroller value.
        tmpMouseScrollOld = tmpMouseScrollNew

        ' Get the movement of the mouse.
        Inp.GetMouseState(tmpMouseX, tmpMouseY, tmpMouseB1, tmpMouseB2, tmpMouseB3, tmpMouseScrollNew)

        ' Update the camera angles.
        sngAngleX = sngAngleX - (tmpMouseY / 100)
        sngAngleY = sngAngleY - (tmpMouseX / 100)

    End Sub
    Private Sub Check_Movement()

        ' Simple check of the mouse.
        If sngAngleX > 1.3 Then sngAngleX = 1.3
        If sngAngleX < -1.3 Then sngAngleX = -1.3

        ' Okay, now for the smothing of the movement... Update
        ' the forward and backward (walk) movement.
        Select Case sngWalk
            Case Is > 0
                sngWalk = sngWalk - 0.005 * TV.TimeElapsed
                If sngWalk < 0 Then sngWalk = 0
            Case Is < 0
                sngWalk = sngWalk + 0.005 * TV.TimeElapsed
                If sngWalk > 0 Then sngWalk = 0
        End Select

        ' Now, we update the left and right (strafe) movement.
        Select Case sngStrafe
            Case Is > 0
                sngStrafe = sngStrafe - 0.005 * TV.TimeElapsed
                If sngStrafe < 0 Then sngStrafe = 0
            Case Is < 0
                sngStrafe = sngStrafe + 0.005 * TV.TimeElapsed
                If sngStrafe > 0 Then sngStrafe = 0
        End Select

        ' Update the vectors using the angles and positions.
        sngPositionX = sngPositionX + (System.Math.Cos(sngAngleY) * sngWalk / 5 * TV.TimeElapsed) + (System.Math.Cos(sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed)
        sngPositionZ = sngPositionZ + (System.Math.Sin(sngAngleY) * sngWalk / 5 * TV.TimeElapsed) + (System.Math.Sin(sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed)
        sngPositionY = Land.GetHeight(sngPositionX, sngPositionZ) + 10

        ' We update the look at position.
        snglookatX = sngPositionX + System.Math.Cos(sngAngleY)
        snglookatY = sngPositionY + System.Math.Tan(sngAngleX)
        snglookatZ = sngPositionZ + System.Math.Sin(sngAngleY)

        ' With the new values of the camera vectors (position and
        ' look at), we update the scene's camera.
        Scene.SetCamera(sngPositionX, sngPositionY, sngPositionZ, snglookatX, snglookatY, snglookatZ)

    End Sub



    Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        ' If we close the application stop the loop.
        bDoLoop = False
    End Sub
End Class
Logged

Using VB.NET, TV3D 6.5, VISTA
~~~~~~~~~~~~~~~~~~~~~~~

"Know how to ask. There is nothing more difficult for some people, nor for others, easier."

- Baltasar Gracian
TripleView
Community Member
*
Posts: 32


« Reply #3 on: March 12, 2010, 01:11:01 AM »

You need to load the texture up CONST_TV_COLORKEY.TV_COLORKEY_BLACK like that
Logged
asia
Customers
Community Member
*****
Posts: 182


« Reply #4 on: March 12, 2010, 02:52:27 AM »

I do not understand the following statement:
Code:
     '  Declare new TVMesh Object
        TheTree(i) = New TVMesh
        Mesh.SetAlphaTest(True)
I do not think you need the mesh object..
Also I do not see the statement I aspected before the "next i":
Code:
TheTree(i)SetAlphaTest(True)
Ciao
Fabio
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
TripleView
Community Member
*
Posts: 32


« Reply #5 on: March 12, 2010, 04:01:45 AM »

Your problem is the Alpha on the tree correct? If so you need to set the texture up correctly..
Logged
Dimple
Community Member
*
Posts: 539


« Reply #6 on: March 12, 2010, 09:38:54 PM »

 Smiley






Okay I've got the Alpha problem sorted using TheTree(i).SetAlphaTest(True) thanks go to asia and everyone else who gave information that helped solve the initial problem. But now unfortunetley looking at the trees parts of the limbs seem to be missing. Is this a problem with the dds texture or something in the code. Which I will post below. 


Code:
Option Strict Off
Option Explicit On
' Import the MTV3D65 library.
Imports MTV3D65



Public Class frmMain

    Inherits System.Windows.Forms.Form
    ' ________________________________________________________________________
    ' TRUEVISION 6.5                        (web: http://www.truevision3d.com)
    ' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    ' Tutorial 16 : Add trees to landscape
    ' ŻŻŻŻŻŻŻŻŻŻŻ
    ' Description : In this 16th tutorial, we go back a bit. We are going to
    ' ŻŻŻŻŻŻŻŻŻŻŻ   generate a simple landscape and add trees at random
    '               positions. Those trees won't be nothing else than
    '               billboards.
    '
    ' Force explicit declarations
    '
    ' TV Variables (Objects).
    Public TV As TVEngine
    Public Land As TVLandscape

    ' New : we declare the trees. Note that we don't know yet how many
    ' trees we are going to place on the land so we will use a dynamic
    ' array that will be set at run time.
    Public TheTree() As TVMesh

    ' This will be quantity of trees
    Public intTreeQuantity As Short

    Public Globals As TVGlobals
    Public MathLib As TVMathLibrary
    Public TFactory As TVTextureFactory
    Public Scene As TVScene
    Public Inp As TVInputEngine

    ' We are going to use camera (point of view) angles, as well as the
    ' camera position and look at vectors.
    Private sngPositionX As Single
    Private sngPositionY As Single
    Private sngPositionZ As Single
    Private snglookatX As Single
    Private snglookatY As Single
    Private snglookatZ As Single
    Private sngAngleX As Single
    Private sngAngleY As Single

    ' We could have done this in many ways, but we added some smoothing to
    ' the movement se we need to declare two additional variables.
    Private sngWalk As Single
    Private sngStrafe As Single

    Public bDoLoop As Boolean

    Declare Function GetFocus Lib "user32" () As Integer


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(632, 453)
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "TV3D SDK 6.5 Tutorial 16  -  Add trees to landscape"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create the TV Interface first:
        TV = New TVEngine

        ' Set the debug file/options.
        ' Do this before the 3D init so it can log any errors found during init.
        TV.SetDebugMode(True, True)
        TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt")

        ' Set the search directory of the objects, textures, ...
        TV.SetSearchDirectory(System.IO.Path.GetDirectoryName(Application.ExecutablePath))

        ' After setting the beta-key/license its time to init the engine:
        ' If you have the beta-key/license.
        TV.Init3DWindowed(Me.Handle, True)

        'Set Antialiasing Setting to 2 Samples.
        'To smooth out any jagged edges in the scene.
        TV.SetAntialiasing(True, CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_2_SAMPLES)

        ' Something good to do is to enable the auto-resize feature:
        ' Get the default viewport and set autoresize to true for it:
        TV.GetViewport.SetAutoResize(True)

        ' Lets display the FPS:
        TV.DisplayFPS(True)

        ' Set the prefered angle system:
        TV.SetAngleSystem(MTV3D65.CONST_TV_ANGLE.TV_ANGLE_DEGREE)

        ' Now after we are done initializing the TVEngine component lets continue:
        ' Create any other components after TV init.

        Scene = New TVScene

        ' We set the scene color
        Scene.SetBackgroundColor(0.3, 0.7, 0.9)

        ' Input has an additional init method to call.
        Inp = New TVInputEngine
        ' Lets init both keyboard and mouse:
        Inp.Initialize(True, True)

        ' Now we have setup the most basic of components.
        ' Something to think about, if the component has a diffrent construct method
        ' then the Set Object = New TV<NAME>, use that one instead.

        ' For example:
        ' Dim Mesh as TVMesh;
        ' Mesh = Scene.CreateMeshBuilder "MyMesh" <- Instead of Set Mesh = new TVMesh
        ' Same goes for RenderSurface, Viewport etc.


        ' Create new TVGlobals Object
        Globals = New TVGlobals

        ' Create new TVMathLibrary Object
        MathLib = New TVMathLibrary

        ' Create the TVTextureFactory
        TFactory = New TVTextureFactory

        ' The land generation
        'Land = New TVLandscape - no longer used
        Land = Scene.CreateLandscape("Landscape")

        ' Generate the height of the land from the grayscale of the image.
        Land.GenerateTerrain("..\..\..\..\Media\Heightmaps\heightmap.jpg", CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 4, 4, 0, 0, True)

        ' Some trees were not on the land.
        Land.SetPosition(-25, -25, -25)

        Land.SetScale(2, 2, 2)

        ' Then, we load the land texture.
        TFactory.LoadTexture("..\..\..\..\Media\snow.bmp", "LandTexture")

        Dim LandTexture As Integer = Globals.GetTex("LandTexture")
        ' We assign a texture to that land.
        'Land.SetTexture(Globals.GetTex("LandTexture"))

        Land.SetTexture(LandTexture)

        ' New and fun part : we add the trees to the land by using billboards.
        ' what are billboard? There are simply a 2d texture placed somewhere
        ' in a 3D world. They have a height and a width but they don't have
        ' any depth. What the use of using 2D in a 3D world? If you 5 trees,
        ' there are none : create your trees in 3D. If you have 2,500 trees,
        ' then you have a big FPS problem because the engine has to compute
        ' every polygons of each tree. This is where the billboards become
        ' handy because each billboard has only 2 polygons : 2 triangles
        ' that makes the billboard rectangle. Let's start by loading the
        ' tree texture. The texture that we will be using is in a dds format.
        ' DDS format is nothing more than 2 BMP files layered : the first one
        ' is the texture, the second one is the alpha layer. You can create
        ' your own DDS files by using the "DirectX Texture Tool" that come
        ' in the directX9 sdk.

        'TextureFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK)
        'TFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", -1, -1, MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK, True)
        TFactory.LoadTexture("..\..\..\..\Media\Tree.dds", "TreeTexture", -1, -1, MTV3D65.CONST_TV_COLORKEY.TV_COLORKEY_USE_ALPHA_CHANNEL)

        ' We define how much trees we are going to create
        intTreeQuantity = 200

        ' We declare TreeTexture as an integer, to be used in place of the string "TreeTexture" (New).
        Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")

        ' We redim (set) the size of the tree array
        ReDim TheTree(intTreeQuantity)

        ' We find a random position for each tree
        Dim i As Short

        '  Declare new TVMesh Object
        TheTree(i) = New TVMesh
        Dim y, x, z As Single
        For i = 1 To intTreeQuantity

            x = (1024 * Rnd())
            z = (1024 * Rnd())
            y = Land.GetHeight(x, z)


            'x = (1440 * Rnd())
            'z = (1440 * Rnd())
            'y = Land.GetHeight(x, z)


            ' We create the iClouds object
            'Dim TreeTexture As Integer = Globals.GetTex("TreeTexture")
            ' We create the mesh in the scene and place it. Something important
            ' to remember : if you created your billboard images topdown, you
            ' will have to invert it's texture in a paint editor or by setting
            ' the billboard height negative. And because you create your tree's
            ' billboard with a negative height value, you will have to add extra
            ' height to the Y position.
            'TheTree(i) = Scene.CreateBillboard(Globals.GetTex("TreeTexture"), x, y + 64, z, 64, -64)
            TheTree(i) = Scene.CreateBillboard(TreeTexture, x - 6, y + 64, z, -64, -64)
            TheTree(i).SetBillboardType(MTV3D65.CONST_TV_BILLBOARDTYPE.TV_BILLBOARD_YAXIS)

            ' We use SetAlphaTest(True) for each tree in scene.
            TheTree(i).SetAlphaTest(True)

        Next i

        ' We set the camera vectors (position and look at) and angles.
        sngPositionX = 80
        sngPositionY = 20
        sngPositionZ = 80
        snglookatX = 80
        snglookatY = 20
        snglookatZ = 90
        sngAngleX = 0
        sngAngleY = 0

        ' We set the initial values of movement
        sngWalk = 0
        sngStrafe = 0


        'Set the viewing distance
        'Scene.SetViewFrustum(90, 4000)
        Scene.SetViewFrustum(60, 4000)


        ' Lets setup the Loop:
        bDoLoop = True       

        ' Display the Form
        Me.Show()
        Me.Focus()

        Do While bDoLoop
            ' Check if the application has focus, if yes thats when we process the loop.
            If GetFocus = Me.Handle.ToInt32 Then
                ' The actual render loop:

                ' We check the input
                Check_Input()

                ' We check and update the movement
                Check_Movement()

                ' Clear the the last frame.
                TV.Clear(False)

                ' We render the landscape.
                Land.Render()
                Scene.RenderAllMeshes()
                ' Render Everything
                Scene.RenderAll(True)
                TV.RenderToScreen()

                ' Render Everything
                'Scene.RenderAll(True)

                ' Lets check if the user presses ESC key, if yes we will quit the app.
                If Inp.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE) Then bDoLoop = False
            Else
                ' So we dont call DoEvents to many times if we arent using full CPU power.
                System.Threading.Thread.Sleep(100)
            End If

            ' Process any messages Windows has for the application, do this last:
            Application.DoEvents()
        Loop

        ' Additional Info:
        '
        ' Normally you dont have to keep track of the TV component and free it on closing.
        ' When you free the TV ATL Interface on close it will automatically clean all the internal
        ' objects as well. Such as Mesh's, Textures etc.

        ' Though it might be good to know you do have the ability to destroy and nil objects
        ' for re-creation or cleanup during runtime if you want that.

        ' There are several methods for destroying and cleaning up objects.

        ' TV<NAME>.Destroy , DestroyAll exists for some objects as well, if it is a Factory of some sort.

        ' Some other good destroy methods are:
        ' TVScene.DestroyAllMeshs.
        ' TVTextureFactory.DeleteAllTextures.

        ' And others...
        'We want to quit the project, so we start by destroying

        ' the texture factory.
        TFactory = Nothing

        ' We destroy the TVGlobals Object
        Globals = Nothing

        ' We destroy the TVMathLibrary object.
        MathLib = Nothing

        ' We destroy each tree
        'Dim i As Short
        For i = 1 To intTreeQuantity
            TheTree(i) = Nothing
        Next i

        ' We destroy the land object.
        Land = Nothing

        ' Don't forget to destroy the inputengine object...
        Inp = Nothing

        ' Then, we destroy the scene object.
        Scene = Nothing

        ' Set TV to Nothing
        TV = Nothing

        ' End the application
        End

    End Sub
    Public Sub Check_Input()

        ' Check if we pressed the UP arrow key, if so, then we are
        ' walking forward.
        If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_UP) = True Then

            sngWalk = 1

            ' If we are not walking forward, maybe we are walking backward
            ' by using the DOWN arrow? If so, set walk speed to negative.
        ElseIf Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_DOWN) = True Then

            sngWalk = -1

        End If

        ' Check if we pressed the LEFT arrow key, if so, then strafe
        ' on the left.
        If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFT) = True Then

            sngStrafe = 1

            ' If we are not strafing left, maybe we want to strafe to the
            ' right, using the RIGHT arrow? If so, set strafe to negative.
        ElseIf Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_RIGHT) = True Then

            sngStrafe = -1

        End If

        ' Now, for the mouse input...
        Dim tmpMouseX, tmpMouseY As Integer
        Dim tmpMouseB2, tmpMouseB1, tmpMouseB3 As Short
        Dim tmpMouseScrollOld, tmpMouseScrollNew As Integer

        ' Actual value to old mouse scroller value.
        tmpMouseScrollOld = tmpMouseScrollNew

        ' Get the movement of the mouse.
        Inp.GetMouseState(tmpMouseX, tmpMouseY, tmpMouseB1, tmpMouseB2, tmpMouseB3, tmpMouseScrollNew)

        ' Update the camera angles.
        sngAngleX = sngAngleX - (tmpMouseY / 100)
        sngAngleY = sngAngleY - (tmpMouseX / 100)

    End Sub
    Private Sub Check_Movement()

        ' Simple check of the mouse.
        If sngAngleX > 1.3 Then sngAngleX = 1.3
        If sngAngleX < -1.3 Then sngAngleX = -1.3

        ' Okay, now for the smothing of the movement... Update
        ' the forward and backward (walk) movement.
        Select Case sngWalk
            Case Is > 0
                sngWalk = sngWalk - 0.005 * TV.TimeElapsed
                If sngWalk < 0 Then sngWalk = 0
            Case Is < 0
                sngWalk = sngWalk + 0.005 * TV.TimeElapsed
                If sngWalk > 0 Then sngWalk = 0
        End Select

        ' Now, we update the left and right (strafe) movement.
        Select Case sngStrafe
            Case Is > 0
                sngStrafe = sngStrafe - 0.005 * TV.TimeElapsed
                If sngStrafe < 0 Then sngStrafe = 0
            Case Is < 0
                sngStrafe = sngStrafe + 0.005 * TV.TimeElapsed
                If sngStrafe > 0 Then sngStrafe = 0
        End Select

        ' Update the vectors using the angles and positions.
        sngPositionX = sngPositionX + (System.Math.Cos(sngAngleY) * sngWalk / 5 * TV.TimeElapsed) + (System.Math.Cos(sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed)
        sngPositionZ = sngPositionZ + (System.Math.Sin(sngAngleY) * sngWalk / 5 * TV.TimeElapsed) + (System.Math.Sin(sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV.TimeElapsed)
        sngPositionY = Land.GetHeight(sngPositionX, sngPositionZ) + 10

        ' We update the look at position.
        snglookatX = sngPositionX + System.Math.Cos(sngAngleY)
        snglookatY = sngPositionY + System.Math.Tan(sngAngleX)
        snglookatZ = sngPositionZ + System.Math.Sin(sngAngleY)

        ' With the new values of the camera vectors (position and
        ' look at), we update the scene's camera.
        Scene.SetCamera(sngPositionX, sngPositionY, sngPositionZ, snglookatX, snglookatY, snglookatZ)

    End Sub



    Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        ' If we close the application stop the loop.
        bDoLoop = False
    End Sub
End Class



Logged

Using VB.NET, TV3D 6.5, VISTA
~~~~~~~~~~~~~~~~~~~~~~~

"Know how to ask. There is nothing more difficult for some people, nor for others, easier."

- Baltasar Gracian
TripleView
Community Member
*
Posts: 32


« Reply #7 on: March 12, 2010, 11:30:53 PM »

TEXID = TexFactory.LoadTexture("TEX.dds", "IDTEX", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_BLACK, True)

It's that simple.
Logged
Pages: [1]
  Print  
 
Jump to:  

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