Jump to content
  • Advertisement
Sign in to follow this  
BlackJoker

Objects dragging issue

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

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?

Share this post


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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Issue solved. 

 

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

Edited by BlackJoker

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!