Advertisement

Selection Buffer is too short

Started by October 15, 2000 05:38 PM
5 comments, last by okapota 24 years ago
hello to u all, i have implemented the selection buffer into my app, it works, but it detecs hits only when im very close to the object im clicking on, do u know why is that? im using a very deep viewing frustum.
no body has any idea??
Advertisement
Im having a simular problem with the selection buffer.
Mine is detecting hits alittle lower than it should and
not high enough... like its shifted slightly down.
heres my click routine that gets called on LBUTTONDOWN
and the render function..

void PickObj(float mousex, float mousey)
{
GLuint selectbuffer[512];
GLint hits;
GLint viewport[4];

glGetIntegerv(GL_VIEWPORT,viewport);

glSelectBuffer(512,selectbuffer);
glRenderMode(GL_SELECT);

glInitNames();
glPushName(0);

glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble) mousex, (GLdouble) (viewpor[3] - mousey),1.0f,1.0f,viewport);
gluPerspective(45.0f,(GLfloat)800/(GLfloat) 600,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
DrawGLScene(GL_SELECT);

hits = glRenderMode(GL_RENDER);
if(hits>0)processhits(hits,selectbuffer);

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}int DrawGLScene(GLenum mode) // Here''s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

glLoadIdentity();
glTranslatef(0.0f,0.0f,-10.0f );
// glRotatef(rot,1,1,0);

if(mode == GL_SELECT)glLoadName(1);
glBegin(GL_QUADS);
glColor3f(1,0,0); glVertex3f(0,0,0);
glColor3f(1,1,0); glVertex3f(0,1,0);
glColor3f(0,1,0); glVertex3f(1,1,0);
glColor3f(1,0,1); glVertex3f(1,0,0);
glEnd();
if(mode == GL_SELECT)glPushName(2);
glBegin(GL_QUADS);
glColor3f(1,0,0); glVertex3f(-2,-2,0);
glColor3f(1,1,0); glVertex3f(-2,-1,0);
glColor3f(0,1,0); glVertex3f(-1,-1,0);
glColor3f(1,0,1); glVertex3f(-1,-2,0);
glEnd();
if(mode == GL_SELECT)glPushName(3);
glBegin(GL_QUADS);
glColor3f(1,0,0); glVertex3f(2,2,0);
glColor3f(1,1,0); glVertex3f(2,3,0);
glColor3f(0,1,0); glVertex3f(3,3,0);
glColor3f(1,0,1); glVertex3f(3,2,0);
glEnd();

rot+=0.5f;
return TRUE;
}

I added mousey+=15; before the gluPickMatrix() and now its right
on... but im still unsure why it was off..
ok, ill try that.
anyone else??
You can define the width and height of the picking region with your gluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]). Add to the width and height to get a bigger picking region.

I think that''ll help you.

Bye,
Martin
______________Martin EstevaolpSoftware
Advertisement
Why use the selection buffer?? It would seem much easier to do your own calculations...

This topic is closed to new replies.

Advertisement