#ifndef USE_COLORPICKING
SimpleObject * 
SimpleModel::SelectObjectAtPoint(int frame, int x, int y, int w, int h,
					float scaling, float rotx, float roty, float rotz )
{
#define BUFSIZE 512
	GLuint	selectBuf[BUFSIZE];
	GLint	hits;
	GLint	viewport[4];
	float   foo[4];
	
	glGetIntegerv ( GL_VIEWPORT, viewport );
	glSelectBuffer ( BUFSIZE, selectBuf );
	glRenderMode ( GL_SELECT );
	glInitNames();
	glPushName(0);
	glMatrixMode ( GL_PROJECTION );
	glPushMatrix();
	glLoadIdentity();

	GLdouble xx = x;
	GLdouble yy = (viewport[3] - y);
	gluPickMatrix ( xx, yy, 1.0, 1.0, viewport );
	gluPerspective ( 90.0, (GLfloat) w / (GLfloat) h, 1.0, 1000.0 );
	glMatrixMode ( GL_MODELVIEW );
	
	glPushMatrix ();
  	glLoadIdentity();
  	// viewing transformation
  	gluLookAt ( 0.0, 0.0, 10.0,    0.0, 0.0, 0.0,   0.0, 1.0, 0.0 );
  	glScalef ( scaling, scaling, scaling );
  	glRotatef ( roty, 0.0, 1.0, 0.0 );
  	glRotatef ( rotx, 1.0, 0.0, 0.0 );
  	glRotatef ( rotz, 0.0, 0.0, 1.0 );
	DrawAt ( frame, true, foo );
	glPopMatrix();
	
	glMatrixMode ( GL_PROJECTION );
	glPopMatrix ();
	glFlush();
	glMatrixMode ( GL_MODELVIEW );
	hits = glRenderMode ( GL_RENDER );
	// process hits....
	if ( hits ) {
		return objects[selectBuf[3]-1];
	} else {
		return NULL;
	}
}
#else
SimpleObject * 
SimpleModel::SelectObjectAtPoint(int frame, int x, int y, int w, int h,
						float scaling, float rotx, float roty, float rotz )
{
	glPushAttrib ( GL_ALL_ATTRIB_BITS );
	glShadeModel(GL_FLAT);
	glDisable(GL_LIGHTING);
	glDisable(GL_DITHER);
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	glPushMatrix ();
  	glLoadIdentity();
  	// viewing transformation
  	gluLookAt ( 0.0, 0.0, 10.0,    0.0, 0.0, 0.0,   0.0, 1.0, 0.0 );
  	glScalef ( scaling, scaling, scaling );
  	glRotatef ( roty, 0.0, 1.0, 0.0 );
  	glRotatef ( rotx, 1.0, 0.0, 0.0 );
  	glRotatef ( rotz, 0.0, 0.0, 1.0 );

	float f[3];
	f[1] = f[2] = 255;
	for (int i=0;i<objects.size();i++) {
		f[0] = (255-i)/255.0;
		objects[i]->DrawAt(frame, true, f);
	};
	glPopMatrix();
	
	glReadBuffer(GL_BACK);
	unsigned char pixel[256];
	glReadPixels(x,h-y,1,1,GL_RGB,GL_UNSIGNED_BYTE,pixel);
	int objNum = pixel[0];
	objNum = 255-objNum;
	glPopAttrib();
	
	if ( objNum != 255 )
		return objects[objNum];
	else
		return NULL;
};
#endif
/////////////////////////////////////////////
