Mouse control on a plane

Currently I am creating an explosion on a plane and that is explode when the mouse click on the plane. But i fail to get the mouse control. Below is some part of my coding, i do not know how to get the explosion when i click on the plane. Hope can get some ideas or opinions from you guys. Thanks.


#define PLANESIZE 150
float Plane[2][PLANESIZE][PLANESIZE];


void OnKeyPress(unsigned char key,int,int) {
	switch (key)
	{
	case 27:
		exit (0);
		break;

	case 'w':	
	        //explosion happen at the middle of the plane if divide by 2
		Plane[1][PLANESIZE/2][PLANESIZE/2] = 100;
		break;
	}
	// ask glut to redraw the screen for us... 
	glutPostRedisplay();
}

Can anyone help me? If i do like this, sometimes it will break my program and that is not the position i want when i click… Can anyone let me know the reason? Thanks…


void OnMouse(int button, int state, int x, int y)
{
	if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {

		if (x>100 && x<300 && y>110 && y<600)
		{
		Plane[1][x][y] = -10;
		}
	}
}

Not sure if it is the problem but your plane is the size of [2][150][150] but your code (“x>100 && x<300 && y>110 && y<600”) is able to address far more than that range so it does and breaks it.
It breaks here at 110<y<600 and 100<x<300, you should change it to for example: 0<x<(PLANESIZE-1) and 0<y<(PLANESIZE-1)

Uh sorry i meant “0 <= x < PLANESIZE” and “0 <= y < PLANESIZE”.

I tried it before but still have the same problem, my program still will break. And that is not the position i want. Anyway, thanks for blink.
Anyone have idea or suggestion?