Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Camera Physics Sliding Collision Solved :-)  (Read 549 times)
NetLizard
Community Member
*
Posts: 172

If you know then show the code.


« on: August 20, 2011, 01:26:36 AM »

Code:
'Form Code

TV.Init3DWindowed(Me.Handle.ToInt32, True)
        TV.SetWindowTitle("Physics Sliding Collision detection and response.")
        ' TV.Init3DFullscreen(1024, 768, 32, True) ' False, TV3D65.CONST_TV_DEPTHBUFFERFORMAT.TV_DEPTHBUFFER_32BITS, 1.0)
        TV.GetViewport.SetAutoResize(True)
        ' Lets display the FPS:
        TV.DisplayFPS(True)
        ' Set the prefered angle system:
        TV.SetAngleSystem(TV3D65.CONST_TV_ANGLE.TV_ANGLE_DEGREE)
        ' Lets init both keyboard and mouse:
        inp.Initialize(True, True)
        InitScene()
        InitCamera()
        InitPhysics()
        InitLand()
        InitMeshs()
        ' Actors()
        Meshes()
        InitLights()
        initMusic()
        GameTimer.Enabled = True
        ' Lets setup the Loop:
        bDoLoop = True

        ' Display the Form
        Show()
        Focus()

        Do While bDoLoop
            ' Check if the application has focus, if yes thats when we process the loop.
            If GetFocus = Me.Handle.ToInt32 Then
                Camera.SetPosition(ball.GetPosition.x, ball.GetPosition.y, ball.GetPosition.z)
                ManageInputs()
                TV.Clear()
                sky.RotateY(0.0005F)
                ' Render Everything
                Scene.RenderAll(True)

                Physics.Simulate(5 * TV.AccurateTimeElapsed / 10000.0F) 'TV.AccurateTimeElapsed * 0.001F) '/ 1000)
           
                '  follower.SetLightPosition(lightID1, ball.GetPosition.x, ball.GetPosition.y + 100, ball.GetPosition.z)
                TV.RenderToScreen()

                ' Lets check if the user presses ESC key, if yes we will quit the app.
                If inp.IsKeyPressed(TV3D65.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.
                Sleep(100)
            End If

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




Code:


 Private Sub InitPhysics()
        Physics.Initialize()

        Dim v As TV3D65.TV_3DVECTOR
        v.x = 0
        v.y = -119.438F ' Camera.GetWorldPosition(Camera.GetPosition).y '- 19.8F
        v.z = 0
        Physics.SetGlobalGravity(v)
        Physics.SetSolverModel(TV3D65.CONST_TV_PHYSICS_SOLVER.TV_SOLVER_EXACT)
        Physics.SetFrictionModel(TV3D65.CONST_TV_PHYSICS_FRICTION.TV_FRICTION_EXACT)

    End Sub
Code:
   Private Sub InitMeshs()
        Dim lay0, lay1, lay, lay2, matts, layer2, layer3 As Integer
        ' Dim _sea As TV3D65.TV_PLANE '= TV3D65.TV_PLANE(10, 10, 10, 10)
        lay0 = Texture.LoadTexture("Tree08.bmp", "layer1", -1, -1, TV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK, True)
        lay1 = Texture.LoadTexture("stone_wall.bmp", "Layer2", -1, -1, TV3D65.CONST_TV_COLORKEY.TV_COLORKEY_NO, True)
        lay = Texture.LoadTexture("bricks.png", "brick")
        layer2 = texx.LoadTexture("bricks_inverted.PNG", "Layer2", -1, -1, TV3D65.CONST_TV_COLORKEY.TV_COLORKEY_USE_ALPHA_CHANNEL)
        layer3 = texx.LoadTexture("Normal_map_brick.BMP", "Layer3", -1, -1, TV3D65.CONST_TV_COLORKEY.TV_COLORKEY_BLACK)
        ' lay2 = texx.LoadTexture("sprite.bmp", "Balls", -1, -1, TV3D65.CONST_TV_COLORKEY.TV_COLORKEY_MAGENTA)

        matts = mat.CreateMaterialQuick(0.05F, 0.05F, 0.05F, 1.0F, "4Walls")

        brush = Scene.CreateMeshBuilder
        With brush
            '.AddWall(lay0, 4000, 4000, 4000, 0, 100, 80, 30, 1)
            '.AddWall(lay0, 500, -500, -500, -500, 100, 80, 60, 1)
            ' .AddWall(lay0, -500, -500, -500, 500, 100, 80, 60, 1)
            '.AddWall(lay0, -500, 500, 500, 500, 100, 80, 60, 1)
            '  .AddWall(lay0, 500, 500, 500, -500, 100, 80, 60, 1)
            .SetLightingMode(TV3D65.CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
            .SetPosition(0, Land.GetHeight(brush.GetPosition.x, brush.GetPosition.z) - 100, 0)
            .SetCullMode(TV3D65.CONST_TV_CULLING.TV_DOUBLESIDED)
            .SetAlphaTest(True)
            .SetMaterial(matts)
        End With
        Physics.CreateStaticMeshBody(brush)

        circ = Scene.CreateMeshBuilder
        With circ
            .CreateSphere(8, 30, 30)
            .SetPosition(200, Land.GetHeight(circ.GetPosition.x, circ.GetPosition.z) + 20, 200)
            .SetTexture(lay)
            .SetLightingMode(TV3D65.CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
            .SetMaterial(matts)
        End With
        Physics.CreateMeshBody(20, circ, TV3D65.CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_SPHERE)

        texx.LoadTexture("NightMilkyWay.jpg", "Skyyy")
        sky = Scene.CreateMeshBuilder("skyy")
        sky.LoadTVM("sphere.TVM", True, True)
        sky.SetScale(100000, 100000, 100000)
        sky.SetCullMode(TV3D65.CONST_TV_CULLING.TV_FRONT_CULL)
        sky.SetTexture(gl.GetTex("Skyyy"))



        ball = Scene.CreateMeshBuilder
        ball.CreateSphere(7)
        ball.SetLightingMode(TV3D65.CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
        ball.SetPosition(100, 5, 20)
        ball.ComputeNormals()

        wall = Scene.CreateMeshBuilder()
        wall.CreateBox(220, 30, 2)
        wall.SetPosition(100, Land.GetHeight(wall.GetPosition.x, wall.GetPosition.z) + 10, 100)
        wall.SetLightingMode(TV3D65.CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
        ' wall.SetShadowCast(True, True)
        wall.SetMaterial(matts)
        wall.SetTexture(lay)
        ' wall.SetTextureEx(0, layer2)
        '  wall.SetTextureEx(2, layer3)
        ' wall.SetTextureEx(1, lay)
        wall.ComputeNormals()

        Physics.CreateStaticMeshBody(wall)


        msh = Scene.CreateMeshBuilder
        msh.LoadTVM("old.tvm", True)
        msh.SetLightingMode(TV3D65.CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED)
        msh.SetPosition(500, Land.GetHeight(msh.GetPosition.x, msh.GetPosition.z) - 0.5, 300)
        msh.SetMaterial(matts)
        msh.RotateX(90)
        msh.RotateY(0)
        msh.RotateZ(90)
        msh.SetScale(-0.4F, 0.4F, -0.4F)
        ' msh.SetShadowCast(True, False)
        Physics.CreateStaticMeshBody(msh)


        Dim ballmat As Integer
        ballmat = Materials.CreateMaterial("MeshMat")
        Materials.SetAmbient(ballmat, 1.0F, 1.0F, 1.0F, 1.0F)
        Materials.SetDiffuse(ballmat, 0.5F, 0.5F, 0.5F, 1.0F)
        Materials.SetEmissive(ballmat, 0.0F, 0.0F, 0.0F, 0.0F)
        Materials.SetOpacity(ballmat, 1.0F)
        ball.SetMaterial(ballmat)
        ball.SetTexture(Texture.LoadTexture(My.Application.Info.DirectoryPath & "\invis.bmp", "invisable_ball", -1, -1, TV3D65.CONST_TV_COLORKEY.TV_COLORKEY_MAGENTA))
        ball.ComputeNormals()

        ballPhysicBody = Physics.CreateBody(30)
        Physics.AddMesh(ballPhysicBody, ball, TV3D65.CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_SPHERE, True)

        Physics.ComputeAccurateInertia(ballPhysicBody)
        Physics.SetMaterialInteractionFriction(Physics.GetDefaultMaterialGroup, Physics.GetDefaultMaterialGroup, 100.0F, 100.0F)

        Physics.SetMaterialInteractionBounciness(Physics.GetDefaultMaterialGroup, Physics.GetDefaultMaterialGroup, 0.0F)
        Physics.SetBodyMovable(ballPhysicBody, True)
        Physics.SetBodyContinuousCollision(ballPhysicBody, True)

        Physics.SetBodyCoriolisForces(ballPhysicBody, False)
        Physics.SetDamping(ballPhysicBody, 80, gl.Vector3(0, 0, 0))
        Physics.EnableCPUOptimizations(True)
    End Sub

Code:

Private Sub ManageInputs()

        Dim v As TV3D65.TV_3DVECTOR
       
        If inp.IsKeyPressed(TV3D65.CONST_TV_KEY.TV_KEY_W) Then
            v.x += Camera.GetDirection.x
            v.y = Land.GetHeight(Camera.GetPosition.x, Camera.GetPosition.z) + 180
            v.z += Camera.GetDirection.z
           
            Physics.AddImpulse(ballPhysicBody, gl.Vector3(v.x, Land.GetHeight(Camera.GetPosition.x, Camera.GetPosition.z), v.z))

        End If

        If inp.IsKeyPressed(TV3D65.CONST_TV_KEY.TV_KEY_S) Then
            v.x = -Camera.GetDirection.x
            v.y = Land.GetHeight(Camera.GetPosition.x, Camera.GetPosition.z) + 180
            v.z = -Camera.GetDirection.z
           
            Physics.AddImpulse(ballPhysicBody, gl.Vector3(v.x, Land.GetHeight(Camera.GetPosition.x, Camera.GetPosition.z), v.z))

        End If

        If inp.IsKeyPressed(TV3D65.CONST_TV_KEY.TV_KEY_A) Then
         
            Camera.RotateY(-TV.AccurateTimeElapsed * 0.3F, False)
        End If

        If inp.IsKeyPressed(TV3D65.CONST_TV_KEY.TV_KEY_D) Then
           
            Camera.RotateY(TV.AccurateTimeElapsed * 0.3F, False)

        End If

    End Sub

And Thats It for sliding collision.
 Till Next time.NetLizard
« Last Edit: September 02, 2011, 03:32:38 PM by NetLizard » Logged

If you know then show the code.
Pages: [1]
  Print  
 
Jump to:  

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