Jump to content
  • Advertisement
Sign in to follow this  

Converting 2D mouse movements to 3D coords?

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

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 this post


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


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Search for quaternions (possible keyword additions: trackball arcball)

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!