----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:
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
Sub InitEngine()
Set Nemo = New NemoX
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
Set Mesh = New cNemo_Mesh
Set KAMERA = New cNemo_Camera
Set KEY = New cNemo_Input
Set Milk1 = New cNemo_MSD3mesh
Set Milk2 = New cNemo_MSD3mesh
Set Milk3 = New cNemo_MSD3mesh
If Not (Nemo.INIT_ShowDeviceDLG(Form1.hWnd)) Then
End
End If
Nemo.BackBuffer_ClearCOLOR = RGB(125, 125, 125)
Nemo.Set_ViewFrustum 10, 5500, 3.14 / 4, 1.01
Nemo.Set_light True
KAMERA.Set_YRotation 45
KAMERA.Set_EYE Tool.Vector(480, 50, -450)
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
Sub CheckCollision()
Dim Dest As D3DVECTOR
If Mesh.CheckCollisionSliding(KAMERA.Get_Position, Dest, 40) Then
KAMERA.Set_EYE Dest
End If
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 |