this is the mouse click code…
void mouseclick(int button, int state, int x1, int y1)
{
GLuint selectBuf[512];
GLint hits;
GLint viewport[4];
if (button != GLUT_LEFT_BUTTON | | state != GLUT_DOWN)
return;
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(512, selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// 2x2 picking region
gluPickMatrix((GLdouble) x1, (GLdouble) viewport[3]-y1, 5.0, 5.0, viewport);
gluPerspective(45,(GLfloat)800/(GLfloat)600,1,900);
gluLookAt(0,0,800,0,0,0,0,1,0);
env.DrawScene (GL_SELECT);
glPopMatrix();
glFlush();
hits=glRenderMode(GL_RENDER);
if (hits >0 )
env.Proces*hitss (hits,selectBuf);
env.MouseMove(button, state, x1, y1);
}
this is the process hits code.
environment::Proces****s (GLint hits,GLuint buffer[])
{
unsigned int i, j;
selected = NULL;
GLuint names, *ptr, ind;
brick *bptr;
ptr = (GLuint *) buffer;
names = *ptr;
bptr = start;
//selected = bptr;
ptr++;
ptr++;
ptr++;
//ptr++;
names = *ptr;
while(bptr != NULL)
{
ind = bptr->GetIndex ();
if (names != ind)
i=-1;
else
selected = bptr;
bptr = bptr->next ;
}
}
and this is the display code…
environment: :DrawScene (GLenum mode)
{
float *rgbv;
int scale,pos[3];
GLuint index;
glPushMatrix();
rgbv = start ->GetColour ();
scale = start ->GetSize ();
index = start ->GetIndex ();
start ->GetPosition (pos);
glTranslatef(pos[0]-100,pos[1],pos[2]);
glColor3fv(rgbv);
glScalef(scale, scale, scale);
if(mode == GL_SELECT)
glLoadName(1);
glCallList(index);
glPopMatrix();
current = start->next ;
glPushMatrix();
rgbv = current ->GetColour ();
scale = current ->GetSize ();
index = current ->GetIndex ();
current ->GetPosition (pos);
glTranslatef(pos[0],pos[1],pos[2]);
glColor3fv(rgbv);
glScalef(scale, scale, scale);
if(mode == GL_SELECT)
glLoadName(2);
glCallList(index );
glPopMatrix();
}
Hope you can help
[This message has been edited by David (edited 02-12-2000).]