Sign in to follow this  
dxFoo

[mdx] Moving through 3d scenes?

Recommended Posts

dxFoo    100
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


Link to post
Share on other sites
mike25025    494
I use something like this to control my cameras

rot = 0

if left:
rot += time
if right:
rot -= time
if 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


Link to post
Share on other sites
mike25025    494
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


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this