Hi Dirk,
Dirk Reiners wrote:
> Johannes Brunen wrote:
>> Is there something
>> like a polytope intersector in OpenSG?
> Not a general Polytope, but if you really just want to do picking the
> Frustum should be enough.
Yes!
>> Is it possible to use the standard OpenGL picking mechanism?
> In theory yes, but implementing that is probably going to be a bit
> tricky.
Could you elaborate a little why it is tricky?
Below you can find what we are currently doing with our none OpenSG GL
app.
I would like to see something along that line for OpenSG. However,
currently I can't really
estimate all of the implications in the OpenSG context.
> I assume you have geometries that are just lines that you want
> to pick. I'd create a frustum from the 4 rays through the corners of
the
> pixel (or pixels, to allow some imprecision) and just iterate the
lines
> and do an intersection with the frustum. Not trivial, but not
difficult
> either
Two concerns with that: At first, performance. The pick box we are using
might
be quite big. Secondly, the line ray has infinitesimal small radius but
a pixel does
represent an area of the screen. This might result in loosing objects if
they are
sufficiently small in size.
>From our current OpenGL implementation:
const int buffer_size = 512;
int picker(int x1, int y1, int x2, int y2, bool flagDetail) // pick box
{
int buffer_static[buffer_size];
int* buffer = NULL;
int mul = 1;
int hits = 0;
int result;
do {
int num = buffer_size * mul;
if (mul >1)
buffer = new int[num];
else
buffer = buffer_static;
glPushAttrib(GL_ALL_ATTRIB_BITS):
glDisable(clipplane); // pseudo code; foreach clipplane
glDisable(LIGHTING);
glDisable(GL_NORMALIZE);
glShadeModel(GL_FLAT);
GLint viewport[4];
glGetInteger(GL_VIEWPORT, viewport);
glSelectBuffer(num, buffer);
glRenderMode(GL_SELECT);
glInitNames();
glPushNames((GLuint)-1);
GLdouble mat[16];
glMatrixMode(GL_PROJECTION);
glGetDoublev(GL_PROJECTION_MATRIX, mat);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble)(x1+x2)*0.5,
(GLdouble)(viewport[3] - (y1+y2)*0.5),
(GLdouble)(x2-x1),
(GLdouble)(y2-y1));
glMultMatrixd(mat);
// pseudo code
foreach object (objects) { // object might be some complicated
stuff
glLoadName(object_name); // integer id
draw(object);
}
hits = glRenderMode();
if (hits > 0) {
GLuint names;
GLuint* ptr;
ptr = buffer;
float zMin = std::numeric_limits<float>::max();
float zMax = std::numeric_limits<float>::min();
for (int i = 0; i < hits; ++i) {
names = *ptr++;
float z1 = (float)*ptr/0x7fffffff; ptr++;
float z2 = (float)*ptr/0x7fffffff; ptr++;
for (j = 0; j < names; ++j) {
GLuint name = *ptr++;
if (flagDetail) {
if (z1 > zMax) {
zMax = z1;
result = k;
}
} else {
if (z1 < zMin) {
zMin = z1;
result = k;
}
}
}
}
}
glPopMatrix();
glPopAttrib();
if (mul > 1)
delete[] buffer;
mul *= 2;
} while (hits < 0);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users