Welcome to NemoX engine tutorial 4
This tutorial will show you how to Draw Polygons with NemoX engine.
cNemo_Mesh class will be used since to that current tutorial. We will use it for manage world data in a 3d scene...
 
             
 

 

----TUTORIAL 4---

Drawing Polygons

You will Need The NemoX engine Get it Here

download the Visual Basic Source code here

 

 we'll use the same BaseCode as the Previous tutorial.

Summary

1. New Objects Declaration and initialization

2. Building our PolygonalMesh

3. Creation a keyboard handler

4. Game Loop

 

 

 

1. New Objects Declaration and initialization

In that tutorial we will use 3 Objects: A main Nemo Renderer class, A mathTool class and A mesh class:

The declaration follow that type:

'The Main One is The NemoX renderer
Dim Nemo As NemoX

'we're gonna use a Nemo class for rendering a mesh or polygons
'we use cNemo_Mesh class

Dim Mesh As cNemo_Mesh


'we will need a quick acces to very important and useful mathematic functions
Dim Tool As cNemo_Tools

 

Our Initialization part does not change

'we will used that sub for the engine initialization

Sub InitEngine()

 'first thing allocate memory for the main Objects
 
  Set Nemo = New NemoX
 
  Set Tool = New cNemo_Tools

'we use this method for windowed mode

  Nemo.Initialize Form1.hWnd
 
  'set the back clearcolor
  Nemo.BackBuffer_ClearCOLOR = &HFFC0C0C0
 
 
  'set some parameters
  Nemo.Set_ViewFrustum 1, 5000, 3.14 / 4
  Nemo.Set_light True
 
  'set our camera
  Nemo.Camera_set_EYE Tool.Vector(0, 15, 0)
 
 
End Sub
 

 


 

2. Building our PolygonalMesh

Now let's how to generate very easy surface with the cNemo_Mesh Class.

we use this Sub routines:

'we build our mesh here
Sub BuilGeometry()
        'allocate memory for our meshbuilder
        Set Mesh = New cNemo_Mesh
       
       
        'adding a plane surface for a simple floor$
       
        'first off very important we pass a texture to the meshbuilder
        Mesh.Add_Texture (App.Path + "\Relief_8.jpg")
        Mesh.Add_WallFloor Tool.Vector(-5000, -1, -5000), Tool.Vector(5000, -1, 5000), 10, 10, 0
       
       
        'then we build our mesh
        Mesh.BuilMesh

End Sub

Functions Explanations:

      cNemo_Mesh.Add_Texture(TextureFile as string)

    Description: Just Add a texture to the mesh Texture Pool

 

cNemo_Mesh.Add_WallFloor(VBotomLeft As D3DVECTOR, VTopRight As D3DVECTOR, [Tu As Single = 1], [TV As Single = 1], [textureID As Long])
 

    Description: Just generate a Floor Wall

 

3. Creation a keyboard handler

Now we will Use KeyboarInput sub:

'----------------------------------------
'Name: GetKey
'----------------------------------------
Sub GetKey()



   'just Rotate left and Right
If Nemo.Get_KeyPress(NEMO_KEY_LEFT) Then _
    Nemo.Camera_Turn_Left 1.5 / 50
If Nemo.Get_KeyPress(NEMO_KEY_RIGHT) Then _
    Nemo.Camera_Turn_Right 1.5 / 50
   
   
    'just move Forward and Backward
    If Nemo.Get_KeyPress(NEMO_KEY_UP) Then _
    Nemo.Camera_Move_Foward 1
    If Nemo.Get_KeyPress(NEMO_KEY_RCONTROL) Then _
    Nemo.Camera_Move_Foward 10
   If Nemo.Get_KeyPress(NEMO_KEY_DOWN) Then _
    Nemo.Camera_Move_Backward 1


   'just move uP and Down
  If Nemo.Get_KeyPress(NEMO_KEY_ADD) Then _
    Nemo.Camera_Strafe_UP 1
  If Nemo.Get_KeyPress(NEMO_KEY_SUBTRACT) Then _
    Nemo.Camera_Strafe_DOWN 1


      'to rotate UP/DOWN
     If Nemo.Get_KeyPress(NEMO_KEY_NUMPAD8) Then
        Nemo.Camera_Turn_UP 1 / 50
    End If
    If Nemo.Get_KeyPress(NEMO_KEY_NUMPAD2) Then _
        Nemo.Camera_Turn_DOWN 1 / 50
       
        'to move 0,8,-8
    If Nemo.Get_KeyPress(NEMO_KEY_SPACE) Then _
     Nemo.Camera_SetPosition Vector(0#, 8#, -8#), _
                                    Vector(0#, 8#, 500#)
   
    'to take a snapshot
    If Nemo.Get_KeyPress(NEMO_KEY_S) Then _
     Nemo.Take_SnapShot App.Path + "\Shot.bmp"



End Sub
 

4. Game Loop

Now we just add the rendering code for the Mesh:

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

            'loop untill player press 'ESCAPE'
           
    Do
           
               '=====Keyboard handler can be added here
               Call GetKey
               DoEvents
               'start the 3d renderer
               Nemo.Begin3D
                     '===============ADD game rendering mrthod here
              
               'draw our wall here
               Mesh.Render
              
              
               'show the FPS at pixel(5,10) color red (ARGB)
               Nemo.Draw_Text "FPS:" + Str(Nemo.Framesperseconde), 5, 10, &HFFFF0000
     
              
               Nemo.End3D
               'end the 3d renderer
           
            'check the player keyPressed
    Loop Until Nemo.Get_KeyPress(NEMO_KEY_ESCAPE)
           
           
    Call EndGame

End Sub

 

 

So so start the game u 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
            Nemo.Free  'free resources used by the engine
            End
   End Sub
 

 

 

 

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

 

                   The PreviousTutorial 3 :Making a 3d FullScreen application

The Next Tutorial 5 :Adding SkyBox environnment