View Full Version : Can glUnProject ignore some objects?

sreagvle

03-25-2009, 04:28 PM

Hey,

I have written an application in which I can click on a table top and get the x, y and z coordinates of where I click. I now want to draw objects upon the table but if I click on an object I still want the coordinates of the table behind it, not the coordinates of the surface of the object. Can I use glUnProject to achieve this and if so how?

Thanks

scratt

03-25-2009, 08:02 PM

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/unproject.html

gluUnProject simply maps the specified window coordinates into object coordinates using model, proj, and view. Used in a pair you can calculate a ray into the screen for 'picking'.

If you want to look at a certain subset of geometry when 'picking' then do Ray intersections on the batch you are interested in rather than using the OpenGL Namestack.

It's more efficient and will do what you require.

If you still want to 'pick' using OpenGL then AFAIK (I have not used it extensively) you can simply not add the items you wish to ignore to the name stack.

sreagvle

03-26-2009, 03:19 AM

If you want to look at a certain subset of geometry when 'picking' then do Ray intersections on the batch you are interested in rather than using the OpenGL Namestack.

I know what you're saying here but I don't know how to achieve it. My code at the minute is like this:

GLint viewport[4];

GLdouble modwlview[16];

GLdoubel projection[16];

GLfloat winX, winY, winZ;

GLdouble posX, posY, posZ;

glGetDoublev( GL_MODELVIEW_MATRIX, modelview );

glGetDoublev( GL_PROJECTION_MATIRX, projection );

glGetIntegerv( GL_VIEWPORT, viewport );

winX = x;

winY = viewport[3] - y;

glReadPixels(x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);

gluUnproject(winX, winY, winZ, modelview, projection, viewport, &posX, &posy, &posZ);

It will always be the same object I want to do ray intersection on, the table top, but I don't know how to specify this to gluUnProject

scratt

03-26-2009, 04:02 AM

http://www.opengl.org/resources/faq/technical/selection.htm

Once you have your pick ray you can use a fairly simple ray to plane, ray to xxx intersection algorithm. You will be able to find many examples if you Google.

gluUnProject is only giving you the tools you need to do the 'picking', you need to do some work yourself afterwards..

For your case (as it's only one object you are testing) you might want to consider this.. http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/project.html

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.