3D object movement with mouse

Started by
4 comments, last by Stainless 10 years, 1 month ago
Hello,
I started to make 3D game. I have free camera (can move anywhere, look everywhere, but not roll), and I have objects. I want to move objects with mouse. Objects Y coordinates I changing with mouse wheel. So what I just need, that mouse X and Y screen position (or delta position) move object on X and Z axis.
If my camera would be locked, then objectPosition+=mouseDelta would work something like what I want, but problem is what I don't have locked camera. But I have angle on Y axis rotation, so maybe that could help?
I'm using XNA, if that means anything
Advertisement

Get the up, right and lookat vector of the camera and tanslate the object along these axis (you move it in camera space), eg


objectPosition += right * mouseDeltaX + up * mouseDeltaY + lookat *mouseDeltaZ

(mouseDeltaZ could be the mousewheel movement)

For rotation take a look at arc-ball rotation.

What I generally do is use the camera forward vector as a ray.

Intersect this ray with the ground plane, and move the selected object to this point.

You can see this in action here

Sorry not the camera forward vector, that's rubbish.

The vector from the eye through the mouse point, the same ray you use to pick the object.

What I generally do is use the camera forward vector as a ray.

Intersect this ray with the ground plane, and move the selected object to this point.

You can see this in action here ...

And if I want move Up or Down, I just change Plane position? Looks nice, now just need to get Plane smile.png

http://stackoverflow.com/questions/11503226/c-sharp-xna-mouse-position-projected-to-3d-plane

Source code and example

This topic is closed to new replies.

Advertisement