Jump to content
• Advertisement

# [mdx] Moving through 3d scenes?

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I've been reading Tom Miller's book and did a few Direct3D programs in 2d. Now, I'm focusing on 3d scenes, so I'm trying to figure out how to move through 3d scenes with DirectInput. What method do I use to move around with? // Set the camera matrix device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -6.0f), new Vector3(x, y, z), new Vector3(0.0f, 1.0f, 0.0f)); I tried this so I can move wherever the camera target is. I'm guessing this is wrong because I'm getting some weird results. This is my GetInput() method.
        private void GetInput()
{
DInput.KeyboardState state = deviceInput.GetCurrentKeyboardState();

if (state[DInput.Key.W])
z += 0.1f;

if (state[DInput.Key.S])
z -= 0.1f;

if (state[DInput.Key.A])
x -= 0.1f;

if (state[DInput.Key.D])
x += 0.1f;
}


What am I doing wrong? EDIT: I'm getting better results witih this... // Set the camera matrix device.Transform.View = Matrix.LookAtLH(new Vector3(x, y, z), new Vector3(), new Vector3(0.0f, 1.0f, 0.0f));

#### Share this post

##### Share on other sites
Advertisement
I use something like this to control my cameras

rot = 0if left:	rot += timeif right:	rot -= timeif up:	eye.x += sin(rot)	eye.z += cos(rot)if down:	eye.x -= sin(rot)	eye.z -= cos(rot)target.x = eye.x+sin(rot)target.z = eye.z+cos(rot)

[Edited by - mike25025 on November 12, 2005 4:42:55 PM]

#### Share this post

##### Share on other sites
Still confused, sorry :)

#### Share this post

##### Share on other sites
rot is the direction the camera is faceing.
Pressing left or right change the direction.

Pressing up or down moves the camera forward or backward. This is done using the sin and cos functions to move in the correct direction based off of rot. If you dont understand this part you should find some tutorials on the web for basic trigonometry.

The last part sets the target to some place infront of the camera.

#### Share this post

##### Share on other sites
I'll just look for a tutorial somewhere.

#### Share this post

##### Share on other sites
Check out my tutorial on moving around here. It might help you out.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!