// point projector at the new intersection point
projectorCamera.lookAt(planeIntersection, Vector3.UNIT_Y);
// transform points to projector space
final ReadOnlyMatrix4 modelViewProjectionMatrix = projectorCamera.getModelViewProjectionMatrix();
final Vector4 spaceTransformation = new Vector4();
for (int i = 0; i < nrPoints; i++) {
spaceTransformation.set(intersections[i].getX(), 0.0, intersections[i].getZ(), 1.0);
modelViewProjectionMatrix.applyPre(spaceTransformation, spaceTransformation);
intersections[i].set(spaceTransformation.getX(), spaceTransformation.getY(), 0);
intersections[i].divideLocal(spaceTransformation.getW());
}
// find min/max in projector space
double minX = Double.MAX_VALUE;
double maxX = -Double.MAX_VALUE;
double minY = Double.MAX_VALUE;
double maxY = -Double.MAX_VALUE;
for (int i = 0; i < nrPoints; i++) {
if (intersections[i].getX() < minX) {
minX = intersections[i].getX();
}
if (intersections[i].getX() > maxX) {
maxX = intersections[i].getX();
}
if (intersections[i].getY() < minY) {
minY = intersections[i].getY();
}
if (intersections[i].getY() > maxY) {
maxY = intersections[i].getY();
}
}
// create range matrix
rangeMatrix.setIdentity();
rangeMatrix.setM00(maxX - minX);
rangeMatrix.setM11(maxY - minY);
rangeMatrix.setM30(minX);
rangeMatrix.setM31(minY);
final ReadOnlyMatrix4 modelViewProjectionInverseMatrix = projectorCamera.getModelViewProjectionInverseMatrix();
rangeMatrix.multiplyLocal(modelViewProjectionInverseMatrix);
// convert screen coords to homogenous world coords with new range matrix
source.set(0.5, 0.5);
getWorldIntersectionHomogenous(0.0, source, rangeMatrix, intersectBottomLeft);