Objects dragging issue

Started by
4 comments, last by BlackJoker 8 years, 8 months ago

I am implementing dragging 3D objects by mouse using picking.

For now basic implementation is ready, but I faced with one issue.

I am dragging objects relative to the camera X and Y axis. If I look at the back of the object, everything ok, but when I look backward,

axis will invert and when I will move mouse to the left, object will move to the right and vice versa.

For now I move object the following way:


objectPosition += camera.ViewMatrix.Right * -moveDistance.X;
objectPosition += camera.ViewMatrix.Up* -moveDistance.Y;

How to make that object always move in the mouse direction independent from camera position or rotation?

Advertisement


For now I move object the following way:

objectPosition += camera.ViewMatrix.Right * -moveDistance.X;
objectPosition += camera.ViewMatrix.Up* -moveDistance.Y;

How to make that object always move in the mouse direction independent from camera position or rotation?

I think that you want to move your object in world space, therefor you should use the world matrix of the camera, something like this:


objectPosition += camera.WorldMatrix.Right * -moveDistance.X;
objectPosition += camera.WorldMatrix.Up* -moveDistance.Y;

I dont have World matrix for camera and I think its not needed as view matrix is invrse for world matrix.

I inverted view matrix and receive the same result.


I inverted view matrix and receive the same result.

When you invert the view matrix and get the same result, then your view matrix is the identity matrix. Is it set properly at all ?

I am pretty sure it`s not identity. I think this is not a matter of View or World matrices. The case is that I want to move object in the same side as I move my cursor, but right vector of camera when I look to the objects back or forward - this is 2 different right vectors, so, I think that is causing this issue.

Issue solved.

The problem was: I multiplied relative vector from camera to delta 2 times and that was causing all my issues.

This topic is closed to new replies.

Advertisement