----TUTORIAL 11---
Loading and
Rendering
DirectX .x models You
will Need The NemoX engine Get it Here
download the Visual Basic Source code here
Summary
1.
InitEngine modification
2.
How to Load .X Models
3.
Game Loop Modification
4.
Collision Detection
Code
1. InitEngine modification
In this tutorial we will use
New Classes cNemo_XFile for managing .X files.
For objects declaration we use
vb classic class declaration for 3 Objects:
Dim Mesh_X1
As cNemo_XFile
Dim Mesh_X2
As cNemo_XFile
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 Mesh_X1 = New cNemo_XFile
Set Mesh_X2 = New cNemo_XFile
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.
Loading .x Ojects
Sub Load_Meshes()
Mesh_X1.LoadXmesh App.Path + "\data\" + _
"ghaus1.x"
Mesh_X1.Set_Position 400, -30, 200 '
Mesh_X1.Set_Scale 11, 11, 12 '
End Sub
LoadXmesh
|
3.
Game Loop Modification
Sub gameLoop()
Nemo.Set_EngineRenderState D3DRS_ZENABLE, 1
Nemo.Set_light 1
Do
Call GetKey
DoEvents
CheckCollision
Nemo.Begin3D
Mesh.Render
Mesh_X1.Render 0
Nemo.Draw_Text "FPS:" + Str(Nemo.Framesperseconde), 5, 10, &HFFFFFFFF
Nemo.End3D
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
Sub CheckCollision()
Dim Dest As D3DVECTOR
If Mesh.CheckCollisionSliding(KAMERA.Get_position, Dest, 40) Then
KAMERA.Set_EYE Dest
End If
If Mesh_X1.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 12 :Loading and Rendering Quake
2 (.md2) Models The Previous:
Tutorial 10
:Loading MilkShape3D models
Tutorial Written on April, 28 th 2003 by Polaris:
johna_pop@yahoo.fr |