public static boolean intersect(BoundingBox bbox, Vector3f center, float radius) { assert Vector3f.isValidVector(center) && Vector3f.isValidVector(bbox.center); // Arvo's algorithm float distSqr = radius * radius; float minX = bbox.center.x - bbox.xExtent; float maxX = bbox.center.x + bbox.xExtent; float minY = bbox.center.y - bbox.yExtent; float maxY = bbox.center.y + bbox.yExtent; float minZ = bbox.center.z - bbox.zExtent; float maxZ = bbox.center.z + bbox.zExtent; if (center.x < minX) distSqr -= FastMath.sqr(center.x - minX); else if (center.x > maxX) distSqr -= FastMath.sqr(center.x - maxX); if (center.y < minY) distSqr -= FastMath.sqr(center.y - minY); else if (center.y > maxY) distSqr -= FastMath.sqr(center.y - maxY); if (center.z < minZ) distSqr -= FastMath.sqr(center.z - minZ); else if (center.z > maxZ) distSqr -= FastMath.sqr(center.z - maxZ); return distSqr > 0; }
protected void addLineFault(float[][] tempBuffer, Random random, float faultHeight, float range) { int x1 = random.nextInt(size); int x2 = random.nextInt(size); int y1 = random.nextInt(size); int y2 = random.nextInt(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float dist = ((x2 - x1) * (j - y1) - (y2 - y1) * (i - x1)) / (FastMath.sqrt(FastMath.sqr(x2 - x1) + FastMath.sqr(y2 - y1))); tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range); } } }
protected void addCircleFault(float[][] tempBuffer, Random random, float faultHeight, float range) { float radius = random.nextFloat() * (maxRadius - minRadius) + minRadius; int intRadius = (int) FastMath.floor(radius); // Allox circle center to be out of map if not by more than radius. // Unlucky cases will put them in the far corner, with the circle // entirely outside heightmap int x = random.nextInt(size + 2 * intRadius) - intRadius; int y = random.nextInt(size + 2 * intRadius) - intRadius; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float dist; if (i != x || j != y) { int dx = i - x; int dy = j - y; float dmag = FastMath.sqrt(FastMath.sqr(dx) + FastMath.sqr(dy)); float rx = x + dx / dmag * radius; float ry = y + dy / dmag * radius; dist = FastMath.sign(dmag - radius) * FastMath.sqrt(FastMath.sqr(i - rx) + FastMath.sqr(j - ry)); } else { dist = 0; } tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range); } } }
float otherRadiusSquared = FastMath.sqr(sphere.getRadius()); float otherRadius = sphere.getRadius();
protected void addLineFault(float[][] tempBuffer, Random random, float faultHeight, float range) { int x1 = random.nextInt(size); int x2 = random.nextInt(size); int y1 = random.nextInt(size); int y2 = random.nextInt(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float dist = ((x2 - x1) * (j - y1) - (y2 - y1) * (i - x1)) / (FastMath.sqrt(FastMath.sqr(x2 - x1) + FastMath.sqr(y2 - y1))); tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range); } } }
public static boolean intersect(BoundingBox bbox, Vector3f center, float radius) { assert Vector3f.isValidVector(center) && Vector3f.isValidVector(bbox.center); // Arvo's algorithm float distSqr = radius * radius; float minX = bbox.center.x - bbox.xExtent; float maxX = bbox.center.x + bbox.xExtent; float minY = bbox.center.y - bbox.yExtent; float maxY = bbox.center.y + bbox.yExtent; float minZ = bbox.center.z - bbox.zExtent; float maxZ = bbox.center.z + bbox.zExtent; if (center.x < minX) distSqr -= FastMath.sqr(center.x - minX); else if (center.x > maxX) distSqr -= FastMath.sqr(center.x - maxX); if (center.y < minY) distSqr -= FastMath.sqr(center.y - minY); else if (center.y > maxY) distSqr -= FastMath.sqr(center.y - maxY); if (center.z < minZ) distSqr -= FastMath.sqr(center.z - minZ); else if (center.z > maxZ) distSqr -= FastMath.sqr(center.z - maxZ); return distSqr > 0; }
protected void addCircleFault(float[][] tempBuffer, Random random, float faultHeight, float range) { float radius = random.nextFloat() * (maxRadius - minRadius) + minRadius; int intRadius = (int) FastMath.floor(radius); // Allox circle center to be out of map if not by more than radius. // Unlucky cases will put them in the far corner, with the circle // entirely outside heightmap int x = random.nextInt(size + 2 * intRadius) - intRadius; int y = random.nextInt(size + 2 * intRadius) - intRadius; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float dist; if (i != x || j != y) { int dx = i - x; int dy = j - y; float dmag = FastMath.sqrt(FastMath.sqr(dx) + FastMath.sqr(dy)); float rx = x + dx / dmag * radius; float ry = y + dy / dmag * radius; dist = FastMath.sign(dmag - radius) * FastMath.sqrt(FastMath.sqr(i - rx) + FastMath.sqr(j - ry)); } else { dist = 0; } tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range); } } }
float otherRadiusSquared = FastMath.sqr(sphere.getRadius()); float otherRadius = sphere.getRadius();