question about 3D perspective and mouse locations

This is somewhat of a two part question. I’m drawing a simple matrix of rectangles that I want to be able to rotate about the x-axis, but such that it gives a 3D perspective.

So, I set up a frustum that has the near clipping pane at 1.0, and the far pane at 10.0. I’m really not sure what the best choices are for those values, but I’m drawing the matrix itself at z = -0.5

The next image shows it rotated about the x-axis.

Here’s the catch: I want to highlight cells of the matrix when the mouse passes over them. If I draw the matrix at the origin, then this is quite trivial. But now since I’m drawing it at z = -0.5, plus I’m also rotating it, I’m not sure the best way to compare the mouse location so as to highlight the appropriate cell.

Any suggestions?

I’m fairly confident that I’m making progress with this. I’m using gluUnProject to compute a vector that passes through the grid. I’m just not sure how to compute which cell in the grid it passes through, because each cell’s coordinates are in 3space that has been affected by a global rotation.

You could achieve this easily using selection code.
Look into glRenderMode() and push a name for each square in your grid.

On your mouse move handler collect the name of the square that was hit by the cursor and light it up.

Thanks, I’ll look into that and report how I make out.

I haven’t been able to get glRenderMode() to work properly. I’ve read here and there that it is considered deprecated by many hardware vendors. I’m coding on my MacBook Pro, so I’m not sure whether that has something to do with it. The GL_SELECT process is simple enough to understand, but I’m never getting any hits.

I’ll post some code in case someone thinks it should be working:

void mouse_event_method( int mseX, int mseY )
	int w, h;
	GetClientSize(&w, &h);

	GLuint selectBuf[64];
	GLint hits;
	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);
	glSelectBuffer(64, selectBuf);
	(void) glRenderMode(GL_SELECT);
	gluPickMatrix(mseX, viewport[3]-mseY, 5.0, 5.0, viewport);
	float aspect = (float)w / (float)h;
	glFrustum(-VIEW*aspect, VIEW*aspect, -VIEW, VIEW, 1.0, 10.0);
	hits = glRenderMode(GL_RENDER);

	if (hits > 0)
		printf("hits: %d
", (int)hits);

And the DrawGrid method…

void DrawGrid()


        // I draw the grid here ...


At this point I’m just considering the entire grid as a single object until I get this working.

Thanks for any feedback.