View Full Version : Changing the drag amount based on cam pos

mobeen

03-09-2011, 05:53 PM

I want to drag the objects in 3D consistently based on the current camera position. Currently if i setup a constant amount like this

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?

ZbuffeR

03-10-2011, 12:38 AM

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

mobeen

03-10-2011, 01:04 AM

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.

ZbuffeR

03-10-2011, 01:44 AM

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) ?

mobeen

03-10-2011, 03:09 AM

Well its for perspective view and in opengl3.3 thus i need to clacl the unProject stuff which i did already here it is

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?

ZbuffeR

03-10-2011, 04:35 AM

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.