Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > DirectX > Movement in any direction


Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2008, 07:13 AM
iifuzz iifuzz is offline
Newcomer
 
Join Date: Jun 2007
Posts: 1
Default Movement in any direction


Hey guys, i need some help with the matrix math here please.
Iv been at this for a week now.


What im trying to make is a 3d viewer for a bunch of points.
I have all the code for displaying finished.
However, the code for moving around is extremely confusing.

I looked thru various examples and websites but they only show rotating left and right and walking in that direction like a normal FPS game....

i need the kind of movement of a flight simulator, where you are moving in the direction you are looking at.

The code for the matrix translations and rotations would go in the UpdateViewport function..
Quote:
Private Sub UpdateViewport()

If bRunning = False Then Exit Sub






Call Render

DoEvents
End Sub



Private Sub viewport_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 37 Then Player.Rotation = Player.Rotation + 2 'Left
If KeyCode = 39 Then Player.Rotation = Player.Rotation - 2 'Right

If Player.Rotation < 0 Then Player.Rotation = 360
If Player.Rotation > 360 Then Player.Rotation = 0


If KeyCode = 38 Then 'UP
Player.Pos.z = Player.Pos.z + 0.01
End If

If KeyCode = 40 Then 'DOWN
Player.Pos.z = Player.Pos.z - 0.01
End If

If KeyCode = 33 Then 'Page Up
Player.RotationY = Player.RotationY + 2
End If

If KeyCode = 34 Then 'Page Down
Player.RotationY = Player.RotationY - 2
End If

UpdateViewport
End Sub
I only need the viewport to update whenever movement changes so i do not use an infinite loop.

any help would be great please!
Reply With Quote
  #2  
Old 08-13-2008, 06:27 AM
AdrianDeAngelis's Avatar
AdrianDeAngelis AdrianDeAngelis is offline
Contributor
 
Join Date: May 2005
Location: Australia
Posts: 549
Default

Hi iifuzz, this is reasonably complicated and something that I preferred to actually write my own routine for making a view matrix rather than using directX

Some things in general:
i. we are using a left handed co-ordinate system where, once everything is all view transformed we are looking down the z axis in a positive direction, +x is to the right and +Y is up
ii. Camera Focus = Camera position for a first person view
iii. vRel is the relative vector between focus and pos = (0,0,0)
iv. Rot is the rotation of your camera X = pitch, Y = yaw, Z = roll all camera rotation directions should be the opposite of the direction that the plane has moved in
v. Think of look as the player turning their head inside the plane to look outside a window etc...

The process is basically an affine transformation where we do
1) a compensatory translation (to offset the effects of focus/pos being non-zero... especially if one does not want a first person effect)
2) Rotations in the correct order... Y,X,Z,Look First we rotate the plane, then we tilt the nose then we roll about the long axis of the plane then we look out the window
3) a translation back to the correct world position.


none of this will actually work if you copy and paste it since you don't have all the supporting functions but the general gist of it is there
Code:
'***************************************************** ' Purpose: creates a modified camera matrix '***************************************************** Public Function D3DViewMatrix(Focus As D3DVECTOR, Pos As D3DVECTOR, Rot As D3DVECTOR, _ vRel As D3DVECTOR, Look as single) As D3DMATRIX Dim M As D3DMATRIX 'translate camera position relative to focus to origin M = D3DTranslateMatrix(-(Pos.X - Focus.X) - Focus.X, _ -(Pos.Y - Focus.Y) - Focus.Y, _ -(Pos.Z - Focus.Z) - Focus.Z) 'rotate world around camera so looking down Z-axis in positive direction If Rot.Y <> 0 Then M = D3DMatrixRotateY(M, Rot.Y) If Rot.X <> 0 Then M = D3DMatrixRotateX(M, Rot.X) 'roll camera around z-axis If Rot.Z <> 0 Then M = D3DMatrixRotateZ(M, Rot.Z) 'rotate to look direction If Look <> 0 Then M = D3DMatrixRotateY(M, Look) 'position observer relative to camera M.rc41 = M.rc41 - vRel.X M.rc42 = M.rc42 - vRel.Y M.rc43 = M.rc43 - vRel.Z 'return camera matrix D3DViewMatrix = M End Function
__________________
Automation error... What do you mean automation error you %#@*&!$ thing!

Star Admiral: 3D tactical space sim *** New Version 0.38 10/01/09 ***
Damage, shields and special weapons systems
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->