interpolator resolutions

This commit is contained in:
dfsek
2021-04-13 11:07:44 -07:00
parent 111f6b05ba
commit 798f3423a5
5 changed files with 24 additions and 10 deletions

View File

@@ -5,20 +5,24 @@ package com.dfsek.terra.world.generation.math.interpolation;
*/
public class BilinearInterpolator implements Interpolator2 {
private final double v0, v1, v2, v3;
private final double width, height;
/**
* Constructs an interpolator with given values as vertices of a unit square.
*
* @param v0 - (0,0)
* @param v0 - (0,0)
* @param v1 - (1,0)
* @param v2 - (0,1)
* @param v3 - (1,1)
* @param width
* @param height
*/
public BilinearInterpolator(double v0, double v1, double v2, double v3) {
public BilinearInterpolator(double v0, double v1, double v2, double v3, double width, double height) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.width = width;
this.height = height;
}
/**
@@ -42,6 +46,8 @@ public class BilinearInterpolator implements Interpolator2 {
*/
@Override
public double interpolate(double s, double t) {
s/=width;
t/=height;
double v01 = lerp(s, v0, v1);
double v23 = lerp(s, v2, v3);
return lerp(t, v01, v23);

View File

@@ -75,7 +75,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
noiseStorage[x][z + 1][y],
noiseStorage[x + 1][z + 1][y],
noiseStorage[x][z + 1][y + 1],
noiseStorage[x + 1][z + 1][y + 1]);
noiseStorage[x + 1][z + 1][y + 1], 4, 4, 4);
}
}
}
@@ -98,10 +98,10 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
*/
@Override
public double getNoise(double x, double y, double z) {
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].interpolate((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].interpolate((x % 4), (y % 4), (z % 4));
}
public double getNoise(int x, int y, int z) {
return interpGrid[x / 4][y / 4][z / 4].interpolate((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
return interpGrid[x / 4][y / 4][z / 4].interpolate(x % 4, y % 4, z % 4);
}
}

View File

@@ -6,6 +6,7 @@ package com.dfsek.terra.world.generation.math.interpolation;
public class TrilinearInterpolator implements Interpolator3 {
private final BilinearInterpolator bottom;
private final BilinearInterpolator top;
private final double length, width, height;
/**
* Constructs an interpolator with given values as vertices of a unit cube.
@@ -21,13 +22,19 @@ public class TrilinearInterpolator implements Interpolator3 {
public TrilinearInterpolator(double _000, double _100,
double _010, double _110,
double _001, double _101,
double _011, double _111) {
this.top = new BilinearInterpolator(_000, _010, _001, _011);
this.bottom = new BilinearInterpolator(_100, _110, _101, _111);
double _011, double _111, double length, double width, double height) {
this.length = length;
this.width = width;
this.height = height;
this.top = new BilinearInterpolator(_000, _010, _001, _011, 1, 1);
this.bottom = new BilinearInterpolator(_100, _110, _101, _111, 1, 1);
}
@Override
public double interpolate(double x, double y, double z) {
x/=length;
z/=width;
y/=height;
return BilinearInterpolator.lerp(x, top.interpolate(y, z), bottom.interpolate(y, z));
}
}

View File

@@ -30,7 +30,7 @@ public class PopulationManager extends BlockPopulator {
this.main = main;
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "ResultOfMethodCallIgnored"})
public synchronized void saveBlocks(World w) throws IOException {
File f = new File(Gaea.getGaeaFolder(w), "chunks.bin");
f.createNewFile();

View File

@@ -23,6 +23,7 @@ public class FabricTree implements Tree {
}
@Override
@SuppressWarnings("try")
public boolean plant(Location l, Random r) {
try(ProfileFrame ignore = TerraFabricPlugin.getInstance().getProfiler().profile("fabric_tree:" + delegate.toString().toLowerCase(Locale.ROOT))) {
FabricWorldAccess fabricWorldAccess = ((FabricWorldAccess) l.getWorld());