3D object movement with mouse
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
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.
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement