# Converting 2D mouse movements to 3D coords?

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

## Recommended Posts

Hi, maybe an easy question for 3D wizards, but I couldn't find anything with google: Suppose I used my mouse to select a ball in a 3D game. I would now like to move this ball in 3D space with my mouse. So, I figure I have to translate the x/y deltas (new mouse position minus old mouse position) to 3D-Space deltas... Question is: How do I do that?? I vaguely recall a lesson in school on projection of vectors, but that's sooooooooo many years ago... Could you give me any hints (or direct me to some information), please? Thanks!!! Beren

##### Share on other sites
Projection is from a higher space to a lower-or-equal space. Means you cannot project from 2D coordinates to 3D ones.

There is several methods to solve this dilema. I suggest using the mouse coordinates to move along a certain 3D plane, then using another input (maybe mouse wheel?) to move along the axis perpendicular to the plane.

Good luck!

##### Share on other sites
Look at this http://www.toymaker.info/Games/html/picking.html

Kev

##### Share on other sites
Hmmm... Okay, thanks.
Good thing is (and I forgot to mention, sorry!) I only have to move the ball in 2 dimensions: x and z. So my first approach was like this:

deltaX = oldMouseX - newMouseX
deltaZ = oldMouseY - newMouseY

newBallX = oldBallX + deltaX * factor
newBallZ = oldBallZ + deltaZ * factor

--- this works, iff you look at the universe (in fact: a playing board) from above (i.e. no rotation around... x or y or z axis).

But what do I have to do, if I actually rotate the playing board?

##### Share on other sites
Search for quaternions (possible keyword additions: trackball arcball)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

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

• Total Topics
634083
• Total Posts
3015402
×