• Advertisement
Sign in to follow this  

3D object movement with mouse

This topic is 1418 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

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

Share this post


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

Share this post


Link to post
Share on other sites

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  

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Edited by Plutonium

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement