Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create glClipPlanes matching the current projection matrix?
    text
    copied!<p>I'm rendering a collection of points in space which the user has manually rotated, panned, zoomed, and finally drawn a selection rectangle over a desired section. When they do this I call <code>gluPickMatrix</code> and then <code>gluPerspective</code> to construct the projection matrix, before using the <code>GL_SELECT</code> render mode to find the points in their selected area.</p> <p>I want to only show the points in the selected area. For testing each point has a boolean <code>isSelected</code>, and I know selection works because the correct ones are getting selected. There are too many points for this to be feasible, though, so I'd like to use <code>glClipPlane</code> to construct four planes corresponding to the rectangular prism (<em>edit: I mean the frustum</em>) defined by the user's selection rectangle. How can I derive the coefficients to pass to <code>glClipPlane</code> after setting up the projection matrix?</p> <p>Right now I'm doing this, but it ends up clipping all the points:</p> <pre><code>// Set up projection matrix int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); gluPickMatrix(x, y, w, h, viewport); gluPerspective(FOV_Y, ASPECT_RATIO, NEAR_PLANE, FAR_PLANE); // Derive clip planes - this doesn't work // Based on the paper "Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix" // http://graphics.cs.ucf.edu/cap4720/fall2008/plane_extraction.pdf double t[4], r[4], b[4], l[4]; double m[16]; glGetDoublev(GL_PROJECTION_MATRIX, m); t[0] = m[3] - m[1]; t[1] = m[7] - m[5]; t[2] = m[11] - m[9]; t[3] = m[15] - m[13]; r[0] = m[3] - m[0]; r[1] = m[7] - m[4]; r[2] = m[11] - m[8]; r[3] = m[15] - m[12]; b[0] = m[3] + m[1]; b[1] = m[7] + m[5]; b[2] = m[11] + m[9]; b[3] = m[15] + m[13]; l[0] = m[3] + m[0]; l[1] = m[7] + m[4]; l[2] = m[11] + m[8]; l[3] = m[15] + m[12]; // ... Render points in GL_SELECT mode, then go back to GL_RENDER mode ... glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // ... Apply user's pan/rotate/zoom choices here ... // Apply clip planes glEnable(GL_CLIP_PLANE0); glClipPlane(GL_CLIP_PLANE0, t); glEnable(GL_CLIP_PLANE1); glClipPlane(GL_CLIP_PLANE1, r); glEnable(GL_CLIP_PLANE2); glClipPlane(GL_CLIP_PLANE2, b); glEnable(GL_CLIP_PLANE3); glClipPlane(GL_CLIP_PLANE3, l); </code></pre> <p>I also tried normalizing and/or negating the plane coordinates, which still seems to end up clipping all the points.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload