There is a bunch of 2x2 "floor/tiles" in a 3D-world with JOGL, they are projected into the camera and I want to know the cursor is hovering the tile or not.
I have a camera settings like this:
glu.gluPerspective(90, 4.0/3.0, 1, 100);
glu.gluLookAt(-2f, 8f, -2f, 0f, 0f, 0f, 0f, 1f, 0f);
and there are some tiles or blocks on the y=0 pane like this
gl.glPushMatrix();
{
// Camera settings (same as above)
glu.gluPerspective(90, 4.0/3.0, 1, 100);
glu.gluLookAt(-2f, 8f, -2f, 0f, 0f, 0f, 0f, 1f, 0f);
// Draw the tiles
gl.glPushMatrix();
{
gl.glBegin(GL2.GL_POLYGON);
{
// a bunch of translated and textured
// (1,0,1) (1,0,-1) (-1,0,-1) (-1,0,1)
// rectangle here,
}
gl.glEnd();
}
gl.glPopMatrix();
}
gl.glPopMatrix();
I am new in 3D and I am only familiar with Java Graphics2D. Intersection of 2D rectangle and cursor is just a few easy comparison, but it seems to be a lot more complicated in 3D. I am looking for some Maths or library to do this.
Or if there is a method to get the 4 point of the final pixels on the screen, Maybe I would like to do java.awt.Shape contain() and check it intersects or not.
The result will be like this: