TUTORIAL 13:   This tutorial explains how To load Quake 3 MD3 characters. In this tutorial quake 3 model animation we be covered, also Model Oriented Bounding Box collision detection.


----TUTORIAL 13---

Loading and Rendering Quake 3 (.md3) Models


You will Need The NemoX engine Get it Here

download the Visual Basic Source code here




1. InitEngine modification

2. How to Load Quake 3 (.md3) Models

3. Game Loop Modification

4. Collision Detection Code



1. InitEngine modification

In this tutorial we will use New Classes cNemo_MD3  for managing Quake 3 Model..

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

'here is the class for our Quake 3 Model
Dim Q3model As cNemo_MD3




'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
   'allocate memory for our meshbuilder
    Set Mesh = New cNemo_Mesh
    '====New code======
    Set Q3model = New cNemo_MD3
    '.......MEMORY ALLOCATION....
    Set KAMERA = New cNemo_Camera
    Set KEY = New cNemo_Input

'we use this method
'now we allow the user to choose options
'32/16 bit backbuffer
  'for this demo Windowed mode is recommanded
  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(80, 80, 80) 'Gray
  'set some parameters 'near far  FOVangle,Aspect
  Nemo.Set_ViewFrustum 10, 5000, 3.14 / 4, 1.01
  Nemo.Set_light True
  'set our camera
  KAMERA.Set_YRotation 45
  KAMERA.Set_EYE Tool.Vector(200, 50, -250) 'Starting Position

End Sub


2. Loading Quake 3 (.md3) Models

'  IN THIS sub we will Load ,rescale,objects
Sub Load_Meshes()
  'load model file first
    Q3model.LoadModel App.Path + "\reaper\"

    'rescale and translate model
    Q3model.Set_Position -100, 100, 0
    Q3model.Set_Scale 4, 4, 4
    Q3model.Set_LowerAnimation LEGS_IDLE  'Set Lower Animation
    Q3model.Set_UpperAnimation TORSO_STAND 'Set Lower Animation

End Sub
In this sub we use LoadModel function to load our Quake 3 Model.
We just pass the Model long pathName where head part is.


3. Game Loop Modification


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

            'loop untill player press 'ESCAPE'
      'Nemo.Set_CullMode D3DCULL_NONE
      Nemo.Set_EngineRenderState D3DRS_ZENABLE, 1
      Nemo.Set_light 1
               '=====Keyboard handler can be added here
               Call GetKey
               'check collision here
               'start the 3d renderer
                     '===============ADD game rendering mrthod here
               'draw our ground here
               'render Quake 3 Model
               'show the FPS at pixel(5,10) color White
               Nemo.Draw_Text "FPS:" + Str(Nemo.Framesperseconde), 5, 10, &HFFFFFFFF
               'end the 3d renderer
            'check the player keyPressed
    Loop Until KEY.Get_KeyBoardKeyPressed(NEMO_KEY_ESCAPE)
    Call EndGame

End Sub




4. 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

 'check collision detection
    If Q3model.BBox.CheckCollisionSliding(KAMERA.Get_position, Dest, 40) Then
        KAMERA.Set_EYE KAMERA.Get_LastPosition
    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 detect

The Next: Tutorial 14 :Basic Particle System Effect

                                     The Previous: Tutorial 12 :Loading and Rendering Quake 2 (.md2) Models


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