Sign in to follow this  
MMWizard

'cursor moves faster then object' problem...

Recommended Posts

Hi, Im building an 3D app where the user can drag objects around. Problem is: I dont know what kind of calculation i need to use, to keep the cursor at the same spot on the object while dragging. I know that it depends on the distance from the object to the camera. But currently it does not what i want... Can someone help me out please. I would have searched it at this forum but i dont know the english term for it. thanx in advance

Share this post


Link to post
Share on other sites
You could calculate an offset x,y value for the object, and then simply position the object at the cursorpos+offset.

Also, you could try to keep the clicked object in a variable and keep it there until you release the button?

pseudo code:



if (objectSelected==0)
{
objectSelected = getObjectUnderCursor();
}

objectSelected.pos = getCursorPos();



Share this post


Link to post
Share on other sites
well, hi Rasmadrak,

In my 3D viewport the user can select and drag a object during a mousedrag. therefor i have and need a speed variabele that keeps the object at the same position as the mousecursor. for now the object moves slower if the object is further away from the camera and faster if the object is closer to the camera.

Share this post


Link to post
Share on other sites
Quote:
Original post by MMWizard
well, hi Rasmadrak,

In my 3D viewport the user can select and drag a object during a mousedrag. therefor i have and need a speed variabele that keeps the object at the same position as the mousecursor. for now the object moves slower if the object is further away from the camera and faster if the object is closer to the camera.


I am going to assume for the moment that you are using OpenGL (but I am sure someone can translate this into D3D). So, during object picking, you presumably transformed the object position into screen space with gluProject() or similar. gluProject returns a 3-element vector, so the x and y elements are your screen position, and save the z element somewhere. When the user drags, form a 3-element vector from the new x and y, and the old z, and transform it back to world space with gluUnproject(), and use this as the new position for the object. This will move the object parallel to the surface of the screen, at the same speed as the cursor.

Share this post


Link to post
Share on other sites
Exactly. Don't try to move the object by some value that you calculate. Just figure out which direction the mouse pointer is pointing in, and put the object there.

Share this post


Link to post
Share on other sites
Exactly. Don't try to move the object by some value that you calculate. Just figure out which direction the mouse pointer is pointing in, and put the object there.

Share this post


Link to post
Share on other sites
hmm okay. thats to bad. Because i'm experimenting with the 3D-API from the Windows Presentation Foundation. And there is nothing like glu-project. And i thought it would'nt be a difficult calculation to perform. Maybe someone can help me where to look for the math involved for this particular translation issue.

By the way, Thanx for you're quick replys...

Share this post


Link to post
Share on other sites
Quote:
Original post by MMWizard
hmm okay. thats to bad. Because i'm experimenting with the 3D-API from the Windows Presentation Foundation. And there is nothing like glu-project. And i thought it would'nt be a difficult calculation to perform. Maybe someone can help me where to look for the math involved for this particular translation issue.

By the way, Thanx for you're quick replys...


All you need is the combined model-view-projection matrix, which you multiply by the object position to get screen space, and its inverse, which you multiply by the screen space vector to get back to world space.

Edit: That should be object space, rather than world space. If you need world space, just use the view-projection matrix and its inverse.

[Edited by - swiftcoder on November 26, 2007 10:31:34 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this