void pickPatches(List<Agent> agents, double[][] ray) {
if (agents == null) {
return;
}
World3D w = (World3D) world;
// detect any patches in the pick-ray ( ( Renderer.WORLD_SCALE / 2 )
// is the offset of the patches plane in the z-axis - jrn)
double scale = (1 / WORLD_SCALE);
double deltaz = Math.abs(ray[0][2] - ray[1][2]);
double deltay = Math.abs(ray[0][1] - ray[1][1]);
double deltax = Math.abs(ray[0][0] - ray[1][0]);
double xi = ray[0][0] * scale;
double yi = ray[0][1] * scale;
double zi = ray[0][2] * scale;
double xinc = 0;
double yinc = 0;
double zinc = 0;
double t = 0;
double min = 0;
double max = 0;
if (deltaz >= deltay && deltaz >= deltax) {
zinc = 1;
t = 1 / (ray[1][2] - ray[0][2]);
xinc = (ray[1][0] - ray[0][0]) * t;
yinc = (ray[1][1] - ray[0][1]) * t;
min = w.minPzcor();
max = w.maxPzcor();
zi = min;
xi -= xinc * ray[0][2] * scale - (min * xinc);
yi -= yinc * ray[0][2] * scale - (min * yinc);
} else if (deltay >= deltax) {
yinc = 1;
t = 1 / (ray[1][1] - ray[0][1]);
xinc = (ray[1][0] - ray[0][0]) * t;
zinc = (ray[1][2] - ray[0][2]) * t;
min = w.minPycor();
max = w.maxPycor();
yi = min;
xi -= xinc * ray[0][1] * scale - (min * xinc);
zi -= zinc * ray[0][1] * scale - (min * zinc);
} else {
xinc = 1;
t = -1 / (ray[0][0] - ray[1][0]);
yinc = (ray[1][1] - ray[0][1]) * t;
zinc = (ray[1][2] - ray[0][2]) * t;
min = w.minPxcor();
max = w.maxPxcor();
xi = min;
yi -= yinc * ray[0][0] * scale - (min * yinc);
zi -= zinc * ray[0][0] * scale - (min * zinc);
}
for (double c = min; c <= max; c++) {
double x = xi;
double y = yi;
double z = zi;
if ((x < world.maxPxcor() + 0.5) && (x >= world.minPxcor() - 0.5) &&
(y < world.maxPycor() + 0.5) && (y >= world.minPycor() - 0.5) &&
(z < w.maxPzcor() + 0.5) && (z >= w.minPzcor() - 0.5)) {
try {
agents.add(w.getPatchAt(wrapX(x + w.followOffsetX()),
wrapY(y + w.followOffsetY()),
wrapZ(z + w.followOffsetZ())));
} catch (AgentException e) {
org.nlogo.util.Exceptions.ignore(e);
}
}
xi += xinc;