# Thread: Changing the drag amount based on cam pos

1. ## Changing the drag amount based on cam pos

I want to drag the objects in 3D consistently based on the current camera position. Currently if i setup a constant amount like this
Code :
```valX = (x - oldX)/300;
valY = (oldY - y)/300;```
This works and the object follows the cursor fine. If i move the camera, the drag amount is slow/fast depnding on if I zoom in/out? Any ideas on how to make it generalized for any zoom value?

2. ## Re: Changing the drag amount based on cam pos

For that you will have to gluUnProject the mouse position in the 2D window, and intersect the resulting line with your 3D XY plane.

3. ## Re: Changing the drag amount based on cam pos

Originally Posted by ZbuffeR
For that you will have to gluUnProject the mouse position in the 2D window, and intersect the resulting line with your 3D XY plane.
Hi Zbuffer,
Thanks for ur reply. Well i have the point already calculated now i need to contol the drag amount such that on zooming in/out the drag amount stays the same.

4. ## Re: Changing the drag amount based on cam pos

If you did what I tried to explain, you would not need adjusting at all
Do you need that to work in a generic perspective view, or only 2D views (simpler) ?

5. ## Re: Changing the drag amount based on cam pos

Well its for perspective view and in opengl3.3 thus i need to clacl the unProject stuff which i did already here it is
Code :
```void UnProject(float winx, float winy, float winz, GLint* viewport, float* objXYZ) {
M3DVector4f tmp;

tmp[0] = (2.0f*((winx-viewport[0])/float(viewport[2]))) -1;
tmp[1] = (2.0f*((winy-viewport[1])/float(viewport[3]))) -1;
tmp[2] = (2.0f*winz)-1.0;
tmp[3] = 1.0;
m3dTransformVector4(objXYZ,tmp,invMVP);
objXYZ[3]=1.0/objXYZ[3];
objXYZ[0]*=objXYZ[3];
objXYZ[1]*=objXYZ[3];
objXYZ[2]*=objXYZ[3];
}```
Once i have the object space xyz i loop through all my objects and return the first object intersected with this object space xyz (simple aabb test). Are u suggesting that I cast a ray back frm the camera? But I dont understand how this will help me in obtaining the drag amount?

6. ## Re: Changing the drag amount based on cam pos

The ray is only needed if you don't have the winz value.

Form mouse positions A and B you want the world positions A' and B' right ? So UnProject both and A and B, then compute the A'B' distance for world space 'drag amount'.

Both A and B can have the same winz for a 2D move parallel to the current window.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•