Results 1 to 6 of 6

Thread: Changing the drag amount based on cam pos

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    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?
    Regards,
    Mobeen

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    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. #3
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Changing the drag amount based on cam pos

    Quote 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.
    Regards,
    Mobeen

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    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. #5
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    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?
    Regards,
    Mobeen

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    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.

Similar Threads

  1. Changing states vs Changing context
    By Yossi Koren in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 10-08-2017, 01:56 PM
  2. Drag object based on mouse selection
    By gwartney in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-15-2016, 10:15 PM
  3. Get amount of graphics memory
    By Adrenalin in forum OpenGL: Advanced Coding
    Replies: 21
    Last Post: 08-14-2009, 09:28 PM
  4. Amount of video memory.
    By imported_CRasterImage in forum OpenGL: Windows
    Replies: 2
    Last Post: 11-01-2007, 11:38 PM
  5. Get amount of tris being rendered? how!?
    By bansheeogl in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 04-26-2005, 01:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean