Results 1 to 4 of 4

Thread: Will gluUnProject work for this?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    13

    Will gluUnProject work for this?

    I have a 3D point (Point1) and I have a 2D screen coodinate.

    I want to take the current camera view angle as a plane normal and "push" the plane back along that normal until it touches Point1. I then want to project a line from my 2D coordinates along that normal until it intersects the plane. The resulting 3D coodinate of that last intersection is what I need.

    I really thought I could gluProject Point1 to get the screen Z. Then pluUnProject my 2D coordinates using that Z and find what I needed. I haven't had much luck getting anything useful from UnProject though.

    A short version of what my code kinda looks like:
    Code :
        gl:matrixMode(?GL_PROJECTION),
        gl:loadIdentity(),
        glu [img]http://www.opengl.org/discussion_boards/ubb/tongue.gif[/img]erspective(45.0, W/H, 0.25, 1000.0),
        gl:matrixMode(?GL_MODELVIEW),
        gl:loadIdentity(),
        gl:translatef(0.0, 0.0, -Dist),
        gl:rotatef(Elevation, 1.0, 0.0, 0.0),
        gl:rotatef(Azimuth, 0.0, -1.0, 0.0),
        ModelMatrix = gl:getDoublev(?GL_MODELVIEW_MATRIX),
        ProjMatrix = gl:getDoublev(?GL_PROJECTION_MATRIX),
       glu:unProject(ScreenX,ScreenHeight-ScreenY,Zdepth,ModelMatrix,ProjMatrix,ViewPort),
    I can post more, but I'm wondering if there is something wrong with the way I'm rotating/translating, causing the weird values I get back from UnProject.

    Thanks for any info!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: Will gluUnProject work for this?

    What value are you using for zDepth? Its supposed to be between 0 and 1 (inclusive) where 0 is the near clipping plane and 1 is the far clipping plane.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    13

    Re: Will gluUnProject work for this?

    Sorry it took me so long to reply...

    Actually, I was plotting a line from Z depth 1.0 to 0. It seemed to always run up and down on the Y axis for some reason.

    I ended creating my own "project" and "unproject" using the view frustum. This works as I would expect, and I was able to finish what I was doing. I never did get gluUnProject to work right.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: Will gluUnProject work for this?

    This is how I use gluUnProject. You can have a look and see if you were missing anything.

    Code :
    	// Assume px and py are the 2D windows co-ordinates.
    	GLdouble pz = 0;		// Set to a depth between 0 and 1 inclusive.
    	GLdouble x, y, z;		// Stores resulting 3D position of mouse.
    	GLint ViewPort[4];		// Holder for viewport.
    	GLdouble ModelViewMatrix[16], ProjectionMatrix[16];
    				// Holder for the Model View and Projection matrices.
    	glGetIntegerv(GL_VIEWPORT, ViewPort);
    				// Get current viewport.
    	glGetDoublev(GL_MODELVIEW_MATRIX, ModelViewMatrix);
    				// Get current model view matrix.
    	glGetDoublev(GL_PROJECTION_MATRIX, ProjectionMatrix);
    				// Get current projection matrix.
    	py = ViewPort[3] - py - 1;	// Calculate y coordinate in OpenGL terms. Works only
    				//  if Viewport dimensions match window dimensions.
    				//  Otherwise replace "Viewport[3]" with window's
    				//  height.
    	gluUnProject((GLdouble)px, (GLdouble)py, pz, ModelViewMatrix, ProjectionMatrix,
    		 ViewPort, &x, &y, &z);
    				// Get position of mouse in virtual world.
     
    	// Your code using result...

Similar Threads

  1. Replies: 5
    Last Post: 04-03-2015, 04:34 AM
  2. Work Group and Work Item sizes
    By howard in forum OpenCL
    Replies: 1
    Last Post: 03-08-2013, 11:08 PM
  3. Replies: 2
    Last Post: 12-14-2011, 05:47 PM
  4. Replies: 1
    Last Post: 11-18-2011, 10:05 AM
  5. How does gluUnProject work exactly?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-01-2002, 08:21 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