# [DX8 VB] Movement in any direction

This topic is 3576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.. 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!

##### Share on other sites
I got it moving in the correct location using the unit circle but im still having problems making it look at the correct location. It always looks straight ahead

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

If KeyCode = 33 Then Player.RotationY = Player.RotationY + 2 'PgUp
If KeyCode = 34 Then Player.RotationY = Player.RotationY - 2 'PgDn

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

If KeyCode = 38 Then 'UP
Player.Pos.Z = Player.Pos.Z + UnitCircle(Player.Rotation).Y * 0.5
Player.Pos.X = Player.Pos.X + UnitCircle(Player.Rotation).X * 0.5
Player.Pos.Y = Player.Pos.Y + UnitCircle(Player.RotationY).Y * 0.5

Player.CamPos.Z = Player.CamPos.Z + UnitCircle(Player.Rotation).Y * 0.5
Player.CamPos.X = Player.CamPos.X + UnitCircle(Player.Rotation).X * 0.5
Player.CamPos.Y = Player.CamPos.Y + UnitCircle(Player.RotationY).Y * 0.5

End If

If KeyCode = 40 Then 'DOWN
Player.Pos.Z = Player.Pos.Z - UnitCircle(Player.Rotation).Y * 0.5
Player.Pos.X = Player.Pos.X - UnitCircle(Player.Rotation).X * 0.5
Player.Pos.Y = Player.Pos.Y - UnitCircle(Player.RotationY).Y * 0.5

Player.CamPos.Z = Player.CamPos.Z - UnitCircle(Player.Rotation).Y * 0.5
Player.CamPos.X = Player.CamPos.X - UnitCircle(Player.Rotation).X * 0.5
Player.CamPos.Y = Player.CamPos.Y - UnitCircle(Player.RotationY).Y * 0.5
End If

Private Sub UpdateViewport()

If bRunning = False Then Exit Sub

D3DXMatrixLookAtLH matView, Player.Pos, Player.CamPos, MakeVector(0, 1, 0)
D3DDevice.SetTransform D3DTS_VIEW, matView

Call Render

DoEvents
End Sub

• 10
• 17
• 9
• 14
• 41
• ### Forum Statistics

• Total Topics
631067
• Total Posts
2997734
×