View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# 3D object movement with mouse

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Plutonium  Members

Posted 07 March 2014 - 02:45 AM

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

### #2Ashaman73  Members

Posted 07 March 2014 - 03:27 AM

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.

Ashaman

### #3Stainless  Members

Posted 07 March 2014 - 04:31 AM

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

### #4Stainless  Members

Posted 07 March 2014 - 04:34 AM

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.

### #5Plutonium  Members

Posted 07 March 2014 - 06:56 AM

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

Edited by Plutonium, 07 March 2014 - 06:56 AM.

### #6Stainless  Members

Posted 07 March 2014 - 11:12 AM

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

Source code and example

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.