PDA

View Full Version : Pick Matrix Internals



Ashkan
05-25-2009, 03:19 AM
Hi there,

Given the parameters to gluPickMatrix

void gluPickMatrix( GLdouble x, GLdouble y, GLdouble delX, GLdouble delY, GLint *viewport )

does anyone know what the pick matrix actually looks like? I'm implementing a picking system using FBOs and since I don't want to allocate an offscreen buffer as big as the whole window and care for resizing issues, I need a way to manually restrict rendering to the pixel that's located under the mouse pointer.

Any help is greatly appreciated.
Cheers

Madoc
05-25-2009, 04:48 AM
Never used glu but IIRC pickmatrix will crop your projection? All you need to do is scale and offset x and y, this matrix should do the trick:

m = identity;
m[0,0] = vw / (r-l);
m[1,1] = vh / (b-t);
m[3,0] = (vw-l-r) / (r-l);
m[3,1] = (vh-b-t) / (t-b);

yooyo
05-25-2009, 05:11 AM
From MESA:


void GLAPIENTRY
gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, GLint viewport[4])
{
if (deltax <= 0 || deltay <= 0) {
return;
}

/* Translate and scale the picked region to the entire window */
glTranslatef((viewport[2] - 2 * (x - viewport[0])) / deltax,
(viewport[3] - 2 * (y - viewport[1])) / deltay, 0);
glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0);
}

Madoc
05-25-2009, 05:45 AM
Good riddance those matrix functions were! That's like turning a house rather than the lightbulb to screw it in. How long does that take? 50 ms? Do you then follow it up with a nice GetMatrix? I've always thought simple little addition and multiplication functions had no place in the api.

Apologies for the OT rant.