1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
Node *PickNode(int X, int Y)
{
GLuint SelectBuffer[512];
GLint SelectHits;
GLint Viewport[4];
glGetIntegerv(GL_VIEWPORT, Viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(GLdouble(X), GLdouble(Viewport[3] - Y), 3, 3, Viewport);
gluPerspective(60.f, GLfloat(Viewport[2]) / GLfloat(Viewport[3]), 1.f, 1000.f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.f, 0.f, Zoom);
glRotatef(Xrot, 1.f, 0.f, 0.f);
glRotatef(Yrot, 0.f, 1.f, 0.f);
glRotatef(Zrot, 0.f, 0.f, 1.f);
glSelectBuffer(512, SelectBuffer);
(void)glRenderMode(GL_SELECT);
glInitNames();
glPushName(-1);
RenderGameBoard(GL_SELECT);
glFlush();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
SelectHits = glRenderMode(GL_RENDER);
int i;
GLuint *HitData = SelectBuffer;
GLuint NumNames;
// GLfloat Zmin, Zmax;
Node *N = 0;
for(i = 0; i < SelectHits; i++)
{
NumNames = *HitData++;
// Zmin = *HitData++ / 0x7FFFFFFF;
// Zmax = *HitData++ / 0x7FFFFFFF;
HitData += NumNames + 2 - 1;
N = GameBoard + *HitData++;
}
return(N);
} |
Partager