use of org.twak.utils.geom.LinearForm3D in project chordatlas by twak.
the class Pano method castTo.
public int castTo(float[] pos, BufferedImage image, Point3d worldHit, Vector3d worldNormal) {
com.jme3.math.Vector3f worldDir = new com.jme3.math.Vector3f(pos[0], pos[1], pos[2]);
worldDir = worldDir.subtract(Jme3z.to(location));
com.jme3.math.Vector3f dir = inverseGeomRot.mult(worldDir);
double angle = ((Math.atan2(-dir.x, dir.z) + Math.PI) % (Math.PI * 2)) / (Math.PI * 2);
double elevation = (Math.atan2(-dir.y, Math.sqrt(dir.x * dir.x + dir.z * dir.z)) + Math.PI / 2) / Math.PI;
double[] rgb = new double[3];
if (image != null) {
double x = angle * image.getWidth(), y = elevation * image.getHeight(), xF = x - Math.floor(x), yF = y - Math.floor(y);
get(image, Math.floor(x), Math.floor(y), (1 - xF) * (1 - yF), rgb);
get(image, Math.ceil(x), Math.floor(y), xF * (1 - yF), rgb);
get(image, Math.ceil(x), Math.ceil(y), xF * yF, rgb);
get(image, Math.floor(x), Math.ceil(y), (1 - xF) * yF, rgb);
}
if (worldHit != null) {
worldHit.x = Double.NaN;
if (planeNameCache.get() != name) {
planeNameCache.set(name);
planeMaskCache.set(getPlanePano());
}
if (planeMaskCache.get() != null) {
double x = Mathz.clamp((1 - angle) * planeMaskCache.get().getWidth(), 0, planeMaskCache.get().getWidth() - 1), y = elevation * planeMaskCache.get().getHeight();
Color c = new Color(planeMaskCache.get().getRGB((int) x, (int) y));
int planeNo = (c.getRed() + c.getGreen() + c.getBlue()) / 3;
if (planeNo < planes.size() && planeNo != 0) {
LinearForm3D plane = new LinearForm3D(planes.get(planeNo));
{
double tmp = plane.B;
plane.B = plane.C;
plane.C = tmp;
plane.D = -plane.D;
plane.A = -plane.A;
}
Point3d pt = plane.collide(new Point3d(), Jme3z.from(dir));
{
com.jme3.math.Vector3f ptm = Jme3z.to(pt);
worldHit.set(Jme3z.from(geomRot.mult(ptm)));
worldHit.add(location);
worldNormal.set(Jme3z.from(geomRot.mult(Jme3z.to(plane.normal()))));
}
}
}
}
return Colour.asInt((int) rgb[0], (int) rgb[1], (int) rgb[2]);
}
use of org.twak.utils.geom.LinearForm3D in project chordatlas by twak.
the class Pano method buildPlanes.
private void buildPlanes(File file) {
if (!file.exists() || planes != null)
return;
planes = new ArrayList<>();
try {
for (String line : Files.readAllLines(file.toPath())) {
double[] params = Arrays.stream(line.split("[,\\s]")).mapToDouble(Double::parseDouble).toArray();
planes.add(new LinearForm3D(params[0], params[1], params[2], params[3]));
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations