Jump to content
  • Advertisement
Sign in to follow this  
alimarandi

Selection doesn't work in my project!!

This topic is 4964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Everybody, Whatever I do, I can not make selection work in my project. Following are my selection routines. Whatever I do it always returns zero in “hits” !! Does any body have any thoughts on this? What did I do wrong? I really appreciate any help. Thank you! On the mouse left button click I do the following code:
    startPicking(point.x, point.y);
    renderInSelectionMode(point.x, point.y);
    stopPicking();
Here are the rest of routines:
void startPicking(int cursorX, int cursorY) 
{

	GLint viewport[4];
	

	glSelectBuffer(BUFSIZE,selectBuf);
	glRenderMode(GL_SELECT);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glGetIntegerv(GL_VIEWPORT,viewport);
	gluPickMatrix(cursorX,viewport[3]-cursorY,
			10,10,viewport);
	glFrustum(FrustumLeft, FrustumRight, FrustumBottom, FrustumTop, ZNear, ZFar);
	gluLookAt(ViewVector[0], ViewVector[1], ViewVector[2],
                  CenterVector[0], CenterVector[1], CenterVector[2]
                  , UpVector[0], UpVector[1], UpVector[2]);
	glMatrixMode(GL_MODELVIEW);
}

void stopPicking() {

	int hits;
	
	// restoring the original projection matrix
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glFlush();
	
	// returning to normal rendering mode
	hits = glRenderMode(GL_RENDER);
	
	// if there are hits process them
	if (hits != 0){
		MessageBox(NULL, "Here we are man", "Ali", MB_OK);
		processHits(hits,selectBuf);
	}
	else  // I always end up here:((
		if (pointx>0 && pointy>0){
			char bufferman[200];
		    sprintf(bufferman, "Oh Oh!!!, pointx = %d, pointy = %d", pointx, Viewport[3] -pointy);
			MessageBox(NULL, bufferman, "Ali", MB_OK);
		}

	
}

void processHits (GLint hits, GLuint buffer[])
{
   unsigned int i, j;
   GLuint names, *ptr, minZ,*ptrNames, numberOfNames;

   //printf ("hits = %d\n", hits);
   ptr = (GLuint *) buffer;
   minZ = 0xffffffff;
   for (i = 0; i < hits; i++) {	
      names = *ptr;
	  ptr++;
	  if (*ptr < minZ) {
		  numberOfNames = names;
		  minZ = *ptr;
		  ptrNames = ptr+2;
	  }
	  
	  ptr += names+2;
   }
   char buffer22[200];
  
   ptr = ptrNames;
   for (j = 0; j < numberOfNames; j++,ptr++) {
	  sprintf (buffer22, "The closest hit names are =%d", *ptr);
      MessageBox(NULL, buffer22, "Ali", MB_OK);
   } 
   
}


void renderInSelectionMode()
{
// I only draw lines with different thickness 
   glInitNames();
   glPushName(0);
	
   if(NumberOfLines>0){
      glEnable(GL_LINE_STIPPLE);
      for(int Select_i=0; Select_i<UsedSMObjects; Select_i++)
         if (Layer[pSMObjects[Select_i].LayerNumber].Visible && pSMObjects[Select_i].IsObjectVisible){
   	    if((pSMObjects[Select_i].ObjectType==OBJECTTYPE_LINE)&&(pSMObjects[Select_i].TotalVertex3D>3)){
 	       glLoadName(Select_i+1);
	       GLfloat myColorVertex2[4], myVertexes2[3];
               glLineStipple(1, pSMObjects[Select_i].LinePattern);
	       for (long myCounter2= 0; myCounter2 < pSMObjects[Select_i].TotalVertex3D-3; myCounter2 = myCounter2 + 6){
		   if (myCounter2 >= pSMObjects[Select_i].TotalVertex3D-3)
			MessageBox(NULL, "Error occured", "Ali", MB_OK);
		   long myDColorindex2=(myCounter2/3)*4;
		   glLineWidth(pSMObjects[Select_i].LineThickness[myCounter2/6]);					
		   glBegin(GL_LINES);
		   myVertexes2[0] = pSMObjects[Select_i].pVertex3D[myCounter2];
		   myVertexes2[1] = pSMObjects[Select_i].pVertex3D[myCounter2+1];
		   myVertexes2[2] = pSMObjects[Select_i].pVertex3D[myCounter2+2];
		   glVertex3fv(myVertexes2);

		   myVertexes2[0] = pSMObjects[Select_i].pVertex3D[myCounter2+3];
		   myVertexes2[1] = pSMObjects[Select_i].pVertex3D[myCounter2+4];
		   myVertexes2[2] = pSMObjects[Select_i].pVertex3D[myCounter2+5];

		   glVertex3fv(myVertexes2); 
		   glEnd(); 
               }
            }
         }
   glDisable(GL_LINE_STIPPLE);
   }
} 

[Edited by - alimarandi on November 12, 2004 5:26:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!