TUTORIAL 8:   This tutorial explains how to use precise polygon collision detection with sliding response , several easy method are offered with the Nemo Mesh Class.


----TUTORIAL 8---

Polygons Collision Detection with Response

You will Need The NemoX engine Get it Here

download the Visual Basic Source code here




1. InitEngine modification

2. Collision Detection Code



1. InitEngine modification

In this sub we will add one Object for Drawing a SplashScreen picture during the Polygon buffering process. To Perform that we have to allocate memory for a new Class : cNemo_Screen it allows to draw over the Screen at any portion.


'we will used that sub for the engine initialization


We just Need first to declare our SplashScreen Object by this line of code:

Dim SCREEN2D As cNemo_Screen

'we will used that sub for the engine initialization

Sub InitEngine()
                    'first thing allocate memory for the main Object
                      Set Nemo = New NemoX
                      Set Tool = New cNemo_Tools
                      '====New code======
                      Set SCREEN2D = New cNemo_Screen
                       '====End New code======

                    'we use this method
                    'now we allow the user to choose options
                    '32/16 bit backbuffer
                      If Not (Nemo.INIT_ShowDeviceDLG(Form1.hwnd)) Then
                       End 'terminate here if error
                      End If
                      'Nemo.Initialize Me.hwnd
                      'set the back clearcolor
                      Nemo.BackBuffer_ClearCOLOR = RGB(125, 125, 125)
                      'set some parameters
                      Nemo.Set_ViewFrustum 10, 16500, 3.14 / 4
                      Nemo.Set_light True
                      'set our camera position
                      Nemo.Camera_set_EYE Tool.Vector(0, 15, 0)

                      '====New code======
                     'we add a texture to the class Texture pool   Index=0
                     SCREEN2D.Add_Texture App.Path + "\Splash.jpg"   

                     'Here is the code for Screen Splashing
                        SCREEN2D.DrawTextureScreenScaled 0
                       '====End New code======
End Sub



2. Collision Detection Code

In this code we're checking if a collision occurs between the player camera postion and Our world

Sub CheckCollision()
         Dim Dest As D3DVECTOR
        If Mesh.CheckCollisionSliding(Nemo.Camera_GetPosition, Dest, 20) Then
            Nemo.Camera_set_EYE Dest
       End If

End Sub

We use  this function:CheckCollisionSliding

PointVec : the point coordonates to test

RetPos:  A Point (D3DVECTOR) to receive the collision response

Radius: The radius of the Sphere to be collided with Mesh Polygons




Here is a screenshot for our tutorial project

download the Visual Basic Source code here

See you in the next Tutorial.....sincerly Polaris..Don't forget Any Bugs detected mailMe


                   The Next: Tutorial 9 :Loading 3D studio Models

The Previous: Tutorial 7 :Adding More Polygons to our Scene


Tutorial Written on December, 22 th 2002