The following is supposed to test if a character is over a particular square in a 2d array of planes (as created from the ExtendedPrimitives class). It doesn't work. The previous version of this method compared the centers of all planes and it worked (but looked terrible). I should note that I'm using the software renderer.
public java.awt.Point boardSpaceFromWorld(SimpleVector ws) {
for (int y = 0; y < planes[0].length; y++) {
for (int x = 0; x < planes.length; x++) {
Object3D plane = planes[x][y];
PolygonManager polyMan = plane.getPolygonManager();
SimpleVector[] vertices = new SimpleVector[6];
vertices[0] = polyMan.getTransformedVertex(0, 0);//, plane.getInverseWorldTransformation(), new SimpleVector());
vertices[1] = polyMan.getTransformedVertex(0, 1);//, plane.getInverseWorldTransformation(), new SimpleVector());
vertices[2] = polyMan.getTransformedVertex(0, 2);//, plane.getInverseWorldTransformation(), new SimpleVector());
vertices[3] = polyMan.getTransformedVertex(1, 0);//, plane.getInverseWorldTransformation(), new SimpleVector());
vertices[4] = polyMan.getTransformedVertex(1, 1);//, plane.getInverseWorldTransformation(), new SimpleVector());
vertices[5] = polyMan.getTransformedVertex(1, 2);//, plane.getInverseWorldTransformation(), new SimpleVector());
float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE, minZ = Float.MAX_VALUE, maxZ = Float.MIN_VALUE;
for (int i = 0; i < 6; i++) {
if (minX > vertices[i].x)
minX = vertices[i].x;
if (maxX < vertices[i].x)
maxX = vertices[i].x;
if (minZ > vertices[i].z)
minZ = vertices[i].z;
if (maxZ < vertices[i].z)
maxZ = vertices[i].z;
}
if (ws.x > minX && ws.x <= maxX && ws.z > minZ && ws.z <= maxZ)
return new java.awt.Point(x, y);
}
}
return new java.awt.Point();
}