public boolean calculateLod(TerrainPatch patch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
if (turnOffLod) {
// set to full detail
int prevLOD = patch.getLod();
UpdatedTerrainPatch utp = updates.get(patch.getName());
if (utp == null) {
utp = new UpdatedTerrainPatch(patch);
updates.put(utp.getName(), utp);
}
utp.setNewLod(0);
utp.setPreviousLod(prevLOD);
//utp.setReIndexNeeded(true);
return true;
}
float[] lodEntropies = patch.getLodEntropies();
float cameraConstant = getCameraConstant(cam, pixelError);
Vector3f patchPos = getCenterLocation(patch);
// vector from camera to patch
//Vector3f toPatchDir = locations.get(0).subtract(patchPos).normalizeLocal();
//float facing = cam.getDirection().dot(toPatchDir);
float distance = patchPos.distance(locations.get(0));
// go through each lod level to find the one we are in
for (int i = 0; i <= patch.getMaxLod(); i++) {
if (distance < lodEntropies[i] * cameraConstant || i == patch.getMaxLod()){
boolean reIndexNeeded = false;
if (i != patch.getLod()) {
reIndexNeeded = true;
// System.out.println("lod change: "+lod+" > "+i+" dist: "+distance);
}
int prevLOD = patch.getLod();
UpdatedTerrainPatch utp = updates.get(patch.getName());
if (utp == null) {
utp = new UpdatedTerrainPatch(patch);//save in here, do not update actual variables
updates.put(utp.getName(), utp);
}
utp.setNewLod(i);
utp.setPreviousLod(prevLOD);
//utp.setReIndexNeeded(reIndexNeeded);
return reIndexNeeded;
}
}