TUTORIAL 10:   This tutorial explains how To load World,models, meshses created with Milkshape3D modeler . NemoX provide an interface to load and render with visibility clipping polygons from Milkshape3D Models.
             
 

 

----TUTORIAL 10---

Loading MilkShape3D models

You will Need The NemoX engine Get it Here

download the Visual Basic Source code here

 

Summary

 

1. InitEngine modification

 2. Game Loop Modification

3. Collision Detection Code

 

 

1. InitEngine modification

In this tutorial we will use New Classes cNemo_MSD3mesh for managing Milkshape3D files.

For objects declaration we use vb classic class declaration  for 3 Objects:

'here is the class for our Milkshape3D objects
Dim Milk1 As cNemo_MSD3mesh
Dim Milk2 As cNemo_MSD3mesh
Dim Milk3 As cNemo_MSD3mesh

 

InitEngine()

'we will used that sub for the engine initialization

'we will used that sub for the engine initialization

Sub InitEngine()

 'first thing allocate memory for the main Object
  
  Set Nemo = New NemoX
  
  'check for the good version IMPORTANT only version 0.072 or above
 If NemoX.Get_EngineVersion < 0.072 Then
   MsgBox "NemoX version 1.072 is required as minimum" , vbInformation
   End
 End If
  
  
  Set Tool = New cNemo_Tools
  
   'allocate memory for our meshbuilder
    Set Mesh = New cNemo_Mesh
    
    '====New code======
    '
    '.......MEMORY ALLOCATION....
    Set KAMERA = New cNemo_Camera
    Set KEY = New cNemo_Input
    Set Milk1 = New cNemo_MSD3mesh
    Set Milk2 = New cNemo_MSD3mesh 'you can add your own model here
    Set Milk3 = New cNemo_MSD3mesh 'you can add your own model here

'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) 'Gray
  
  
  
  'set some parameters
  Nemo.Set_ViewFrustum 10, 5500, 3.14 / 4, 1.01
  Nemo.Set_light True
  
  'set our camera
  KAMERA.Set_YRotation 45
  KAMERA.Set_EYE Tool.Vector(480, 50, -450) 'Starting Position
End Sub

 

2. Game Loop Modification

 

'this sub is the main loop for a game or 3d apllication
SuSub gameLoop()

            'loop untill player press 'ESCAPE'
      'Nemo.Set_CullMode D3DCULL_NONE
      Nemo.Set_EngineRenderState D3DRS_ZENABLE, 1
    Do
       
               
               Call GetKey '=====Keyboard handler sub
               DoEvents
               
               CheckCollision  'Call Our Collision detection sub
               
               'start the 3d renderer
               Nemo.Begin3D
                     '===============ADD game rendering mrthod here
               
               'draw our ground here
              
               Mesh.Render
               
		'This part of code will render the meshes
		'Note that NemoX engine use built-in View Frustum Test 
		'To render object only if it's visible

               'render Milkshape 3D meshes Here
               Milk1.Render
               
               
             
               'show the FPS at pixel(5,10) color White
               Nemo.Draw_Text "FPS:" + Str(Nemo.Framesperseconde), 5, 10, &HFFFF0000
               
               Nemo.End3D
               'end the 3d renderer
            
            'check the player keyPressed
    Loop Until KEY.Get_KeyBoardKeyPressed(NEMO_KEY_ESCAPE)
            
            
    Call EndGame

En End Sub

So so start the game you add this in the form_Load code as below:

Private Sub Form_Load()
  Me.Show
  Me.Refresh

  'call the initializer sub
  Call InitEngine
    'make geometry
  Call BuilGeometry
 
  'call the main game Loop
   Call gameLoop
  
End Sub

 

To Terminate the Game we Use this:

Sub EndGame()
 'end of the demo
           Set KEY = Nothing
           Set KAMERA = Nothing
           Set Mesh_3DS = Nothing
           Set Mesh = Nothing
           
            Nemo.Free  'free resources used by the engine
           Set Nemo = Nothing
            End
End Sub

 

 

 

3. Collision Detection Code

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

 

 
'=========================================
'  IN THIS sub we will handle with collision
'  detection
'
'
'=======================================
Sub CheckCollision()
    
    Dim Dest As D3DVECTOR
    
    'if any collision with our world we slide along
    If Mesh.CheckCollisionSliding(KAMERA.Get_Position, Dest, 40) Then
       KAMERA.Set_EYE Dest
    End If

 
     'if any collision with our Milkshape3D mesh we slide along

     If Milk1.Get_ColisionSliding(KAMERA.Get_Position, Dest, 20) Then
              KAMERA.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 11 :Loading and Rendering .X files

The Previous: Tutorial 9 :Loading 3D studio Models

 

Tutorial Written on April, 11 th 2003 by Polaris: johna_pop@yahoo.fr