dragging in right direction from different views

hi all,

I have a object in the 3-D world and I am dragging it using mouse. I am able to drag the object but problem is that I am dragging it in the world coordinate system based on the mouse motion on the screen. For example, if I move the mouse in X-direction by +10 pixels, I change the world coordinates ob the object by 2.0 units in X-direction. Similar approach to other axes too. The problem is that if I change my view in 3-D world and then try to drag the object, it moves in opposite direction sometimes depending on the view. I understand that this is because the motion I am asking it to do is hard-coded in my program.

How can I make it move in the direction I want ? One solution that seems likely is to use the world-coordinate positions of the object to drag it by unprojecting and projecting back the mouse location.


You need to figure out how a 2D mouse move projects into your 3D world for your view. One way is to raycast from the mouse position out through the frustum (that converts it to a 3D vector), and intersect the ray generated with either a ground plane or other 3D scenery. Do this for the initial position and on each mousemove and you’ll be in good shape.

This is not an advanced question. You’ll have better luck in the beginners section unless you have a very advanced question.