CollisionResults tmpResults = new CollisionResults();
CollisionResults results = new CollisionResults();
// float d0, d1;
// CollisionResult result = null;
CollisionResult r;
// boolean dbl = false;
// float dist = Float.POSITIVE_INFINITY, tmpDist = 0;
Ray ray = new Ray();
ray.setLimit(1);
// int edgeCase = 0;
// int added = 0;
// float d0, d1;
for (Vector3f rDirection : rDirections) {
tmpResults.clear();
ray.setOrigin(voxelPos);
ray.setDirection(rDirection);
// added = refGeom.collideWith(ray, tmpResults);
if (refGeom.collideWith(ray, tmpResults) > 0) {
// d0 = tmpResults.getClosestCollision().getDistance();
ray.setOrigin(voxelPos.add(rDirection));
ray.setDirection(rDirection.negate());
refGeom.collideWith(ray, tmpResults);
// d1 = tmpResults.getFarthestCollision().getDistance();
// edgeCase = Math.abs(d0) - Math.abs(d1);
} else {
}
// if (refGeom.collideWith(ray, tmpResults) > 0) {
// ray.setOrigin(voxelPos.add(rDirection));
// ray.setDirection(rDirection.negate());
// refGeom.collideWith(ray, tmpResults);
// }
for (int i = 0; i < tmpResults.size(); i++) {
r = tmpResults.getCollision(i);
// dbl = false;
// if (results.size() > 0)
// if (r.getContactPoint()
// .equals(results.getCollision(results.size() - 1).getContactPoint())
// && r.getDistance() == results.getCollision(results.size() - 1)
// .getDistance()) {
// dbl = true;
// }
// if (r.getDistance() <= 1 && !dbl) {
results.addCollision(r);
// } else {
// // results.d
// }
}
// if (added > 0) {
//
// for (int i = 0; i < results.size(); i++) {
// tmpResult = results.getCollision(i);
//
// tmpDist = tmpResult.getTriangle(null).getCenter().distance(voxelPos);
// if (dist > tmpDist) {
// result = tmpResult;
// dist = tmpDist;
// }
// }
// }
// if (added > 0) {
//
// for (int i = 0; i < results.size(); i++) {
// tmpResult = results.getCollision(i);
//
// tmpDist = tmpResult.getTriangle(null).getCenter().distance(voxelPos);
// if (dist > tmpDist) {
// result = tmpResult;
// dist = tmpDist;
// }
// }
// d0 = result.getDistance();
//
// angle = (float) Math.toDegrees(result.getTriangle(null)
// .getNormal()
// .angleBetween(rDirection));
//
// if (angle > 90 && angle < 270) {
// d0 *= -1;
// }
//
// results.clear();
// r.setOrigin(voxelPos.add(rDirection));
// r.setDirection(rDirection.negate());
// refGeom.collideWith(r, results);
// for (int i = 0; i < results.size(); i++) {
// tmpResult = results.getCollision(i);
// // System.out.println(tmpResult.getDistance());
//
// if (Math.abs(tmpResult.getDistance()) <= 1) {
// tmpDist = tmpResult.getTriangle(null).getCenter()
// .distance(voxelPos);
// dist = Float.NEGATIVE_INFINITY;
// if (dist < tmpDist) {
// result = tmpResult;
// dist = tmpDist;
// }
// }
// }
// d1 = result.getDistance();
//
// angle = (float) Math.toDegrees(result.getTriangle(null)
// .getNormal()
// .angleBetween(rDirection.negate()));
//
// if (angle > 90 && angle < 270) {
// d1 *= -1;
// }
//
// density = d0 + Math.signum(d0) * ((1 - (d0 + d1)) / 2);
// System.out.println("density: " + density + ", d0: " + d0 + ", d1: " + d1
// + ", ");
// added = -1;
// }
// if (added == -1)
// break;
}
if (results.size() > 0) {
// System.out.println("Results for " + voxelPos);
densities0 = new float[results.size()];
densities1 = new float[results.size()];
for (int i = 0; i < results.size(); i++) {
r = results.getCollision(i);
densities0[0] = r.getDistance();
densities1[0] = r.getDistance();
// tmpDist = tmpResult.getTriangle(null).getCenter().distance(voxelPos);
// if (dist > tmpDist) {
// result = tmpResult;
// dist = tmpDist;