----TUTORIAL 12---
Loading and
Rendering Quake 2(.md2) 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 Quake 2(.md2) Models
3.
Game Loop Modification
4.
Collision Detection
Code
1. InitEngine modification
In this tutorial we will use
New Classes cNemo_MD2 for managing Quake 2Model..
For objects declaration we use
vb classic class declaration for 3 Objects:
Dim Q2model
As cNemo_MD2
InitEngine()
Sub InitEngine()
Set Nemo =
New NemoX
Set Tool =
New cNemo_Tools
Set Mesh =
New cNemo_Mesh
Set Q2model =
New cNemo_MD2
Set KAMERA =
New cNemo_Camera
Set KEY =
New cNemo_Input
If Not
(Nemo.INIT_ShowDeviceDLG(Form1.hWnd))
Then
End
End If
Nemo.BackBuffer_ClearCOLOR = RGB(80, 80, 80)
Nemo.Set_ViewFrustum 10, 5000, 3.14 / 4, 1.01
Nemo.Set_light True
KAMERA.Set_YRotation 45
KAMERA.Set_EYE Tool.Vector(200, 50, -250)
End
Sub
|
2.
Loading Quake 2(.md2) Models
Sub Load_Meshes()
Dim I As Long
Q2model.LoadMD2 App.Path + _
"\goblin\goblin.md2"
Q2model.load_Texture App.Path + _
"\goblin\goblin.jpg"
Q2model.LoadWeapon App.Path + _
"\goblin\goblinwpn.md2"
Q2model.LoadWeapon App.Path + _
"\goblin\goblinwpn.jpg"
Q2model.Set_Position -100, 100, 0
Q2model.Set_Scale 4, 4, 4
For I = 0 To Q2model.GetNumAnimations - 5
List1.AddItem Q2model.GetAnimationName(I)
Next I
End Sub
LoadMD2
|
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
Q2model.Render
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 Q2model.Get_Colision(KAMERA.Get_position) 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 detected mailMe
The Next:
Tutorial 13 :Loading and Rendering Quake
3 (.md3) Models The Previous:
Tutorial 11
:Loading and Rendering DirectX .x models
Tutorial Written on April, 28 th 2003 by Polaris:
johna_pop@yahoo.fr |