public float getHeightmapHeight(Vector2f xz) { // offset int halfSize = totalSize / 2; int x = Math.round((xz.x / getWorldScale().x) + halfSize); int z = Math.round((xz.y / getWorldScale().z) + halfSize); if (!isInside(x, z)) return Float.NaN; return getHeightmapHeight(x, z); }
public Vector3f getNormal(Vector2f xz) { // offset float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f); float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f); Vector3f normal = getNormal(x, z, xz); return normal; }
protected boolean needToRecalculateNormals() { if (affectedAreaBBox != null) return true; if (!lastScale.equals(getWorldScale())) { affectedAreaBBox = new BoundingBox(getWorldTranslation(), Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); lastScale = getWorldScale(); return true; } return false; }
/** * Get the interpolated height of the terrain at the specified point. * @param xz the location to get the height for * @return Float.NAN if the value does not exist, or the coordinates are outside of the terrain */ public float getHeight(Vector2f xz) { // offset float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f); float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f); if (!isInside((int)x, (int)z)) return Float.NaN; float height = getHeight((int)x, (int)z, (x%1f), (z%1f)); height *= getWorldScale().y; return height; }
protected void setHeight(List<Vector2f> xz, List<Float> height, boolean overrideHeight) { if (xz.size() != height.size()) throw new IllegalArgumentException("Both lists must be the same length!"); int halfSize = totalSize / 2; List<LocationHeight> locations = new ArrayList<LocationHeight>(); // offset for (int i=0; i<xz.size(); i++) { int x = Math.round((xz.get(i).x / getWorldScale().x) + halfSize); int z = Math.round((xz.get(i).y / getWorldScale().z) + halfSize); if (!isInside(x, z)) continue; locations.add(new LocationHeight(x,z,height.get(i))); } setHeight(locations, overrideHeight); // adjust height of the actual mesh // signal that the normals need updating for (int i=0; i<xz.size(); i++) setNormalRecalcNeeded(xz.get(i) ); }
public float getHeightmapHeight(Vector2f xz) { // offset int halfSize = totalSize / 2; int x = Math.round((xz.x / getWorldScale().x) + halfSize); int z = Math.round((xz.y / getWorldScale().z) + halfSize); if (!isInside(x, z)) return Float.NaN; return getHeightmapHeight(x, z); }
public Vector3f getNormal(Vector2f xz) { // offset float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f); float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f); Vector3f normal = getNormal(x, z, xz); return normal; }
protected boolean needToRecalculateNormals() { if (affectedAreaBBox != null) return true; if (!lastScale.equals(getWorldScale())) { affectedAreaBBox = new BoundingBox(getWorldTranslation(), Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); lastScale = getWorldScale(); return true; } return false; }
/** * Get the interpolated height of the terrain at the specified point. * @param xz the location to get the height for * @return Float.NAN if the value does not exist, or the coordinates are outside of the terrain */ public float getHeight(Vector2f xz) { // offset float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f); float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f); if (!isInside((int)x, (int)z)) return Float.NaN; float height = getHeight((int)x, (int)z, (x%1f), (z%1f)); height *= getWorldScale().y; return height; }
protected void setHeight(List<Vector2f> xz, List<Float> height, boolean overrideHeight) { if (xz.size() != height.size()) throw new IllegalArgumentException("Both lists must be the same length!"); int halfSize = totalSize / 2; List<LocationHeight> locations = new ArrayList<LocationHeight>(); // offset for (int i=0; i<xz.size(); i++) { int x = Math.round((xz.get(i).x / getWorldScale().x) + halfSize); int z = Math.round((xz.get(i).y / getWorldScale().z) + halfSize); if (!isInside(x, z)) continue; locations.add(new LocationHeight(x,z,height.get(i))); } setHeight(locations, overrideHeight); // adjust height of the actual mesh // signal that the normals need updating for (int i=0; i<xz.size(); i++) setNormalRecalcNeeded(xz.get(i) ); }