GLuint selectBuff[64];
GLint hits, viewport[4];
long model_pick=-1;
// Select buffer parameters
glDisable(GL_LIGHTING);
glRenderMode(GL_SELECT);
// Enter to selection mode
glSelectBuffer(64, selectBuff);
glGetIntegerv(GL_VIEWPORT, viewport);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set-up pick matrix
gluPickMatrix(x, DispSettings.Height-y, 2, 2, viewport);
// Set our perpective transformation matrix
gluPerspective(fCameraYAngle, fXYrap, 0.5,8000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/* Set up the camera at (CameraPos.x, CameraPos.y, CameraPos.z) looking along vector (CameraLookAt.x, CameraLookAt.y, CameraLookAt.z).*/
gluLookAt (CameraPos.x, CameraPos.y, CameraPos.z, CameraPos.x+CameraLookAt.x,CameraPos.y+CameraLookAt.y, CameraPos.z+CameraLookAt.z, 0.0, 1.0, 0.0);
double dist=Dist((double)0,(double)0,(double)CameraLookAt.x,(double)CameraLookAt.z);
double sina,cosa;
double difx,difz;
long nSide;
if(dist==0)
{
sina=0;
cosa=1;
}
else
{
sina=CameraLookAt.z/dist;
cosa=CameraLookAt.x/dist;
}
// Render all scene and fill selection buffer
long i,j;
i=TotalView.m_nLists-2;
long nTrgToRender=TotalView.m_pnTrgToRender[i];
Cf3dSplitColorTrg * pTrgToRender=TotalView.m_ppTrgToRender[i];
for(j=0;j<nTrgToRender;j++)
{
glLoadName(j);
nSide=(pTrgToRender[j].p[2].z-pTrgToRender[j].p[0].z)/2;
difx=nSide*sina;
difz=nSide*cosa;
RenderBlbTriangle(&pTrgToRender[j],difx,difz,nSide);
}
// Get hits and go back to normal rendering
hits = glRenderMode(GL_RENDER);
// Get first model, in selection buffer stack
if(hits > 0)
model_pick = selectBuff[3];
if(bLighting)
glEnable(GL_LIGHTING);
//glPopMatrix ();
return model_pick;
Thanks,
Jabba
The Truth Is Not To Be Spoken In A Loud Voice
Picking :first call failed,then all the rest are working!
Why is that?Here is the actual code
You might want to try swapping the buffers before you check for hits. If you are double buffered that is.
Two things:
1) (most likely) you need to glPushName(something) to initialize the name stack. Otherwise, your name stack has size zero, and you won''t be able to read it.
2) Your selection buffer size is too small.
1) (most likely) you need to glPushName(something) to initialize the name stack. Otherwise, your name stack has size zero, and you won''t be able to read it.
2) Your selection buffer size is too small.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement