Jump to content

  • Log In with Google      Sign In   
  • Create Account


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.

  • You cannot reply to this topic
5 replies to this topic

#1 Plutonium   Members   -  Reputation: 349

Like
0Likes
Like

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


Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 6749

Like
0Likes
Like

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.



#3 Stainless   Members   -  Reputation: 711

Like
3Likes
Like

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  



#4 Stainless   Members   -  Reputation: 711

Like
0Likes
Like

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.



#5 Plutonium   Members   -  Reputation: 349

Like
0Likes
Like

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 smile.png


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


#6 Stainless   Members   -  Reputation: 711

Like
0Likes
Like

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.



PARTNERS