More SDF tests
This commit is contained in:
parent
cf8955ea4b
commit
2e632bf245
13 changed files with 111 additions and 22 deletions
|
@ -72,4 +72,8 @@ public class MHelper {
|
|||
public static float length(float x, float y, float z) {
|
||||
return (float) Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
return x1 * x2 + y1 * y2 + z1 * z2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public interface ISDF {
|
|||
run &= Math.abs(pos.getZ()) < dz;
|
||||
|
||||
if (!blocks.contains(pos) && canReplace.apply(world.getBlockState(wpos))) {
|
||||
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) <= 0) {
|
||||
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) < 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, wpos, Blocks.STONE);
|
||||
add.add(pos);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package ru.betterend.util.sdf.operator;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
|
||||
public class SDFDisplacement extends SDFUnary {
|
||||
private static final Vector3f POS = new Vector3f();
|
||||
private Function<Vector3f, Float> displace;
|
||||
|
||||
public SDFDisplacement setFunction(Function<Vector3f, Float> displace) {
|
||||
this.displace = displace;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
POS.set(x, y, z);
|
||||
return this.source.getDistance(x, y, z) + displace.apply(POS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package ru.betterend.util.sdf.operator;
|
||||
|
||||
public class SDFFlatWave extends SDFDisplacement {
|
||||
private int rayCount = 1;
|
||||
private float intensity;
|
||||
|
||||
public SDFFlatWave() {
|
||||
setFunction((pos) -> {
|
||||
return (float) Math.cos(Math.atan2(pos.getX(), pos.getZ()) * rayCount) * intensity;
|
||||
});
|
||||
}
|
||||
|
||||
public SDFFlatWave setRaysCount(int count) {
|
||||
this.rayCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SDFFlatWave setIntensity(float intensity) {
|
||||
this.intensity = intensity;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,6 @@ public class SDFCapsule implements ISDF {
|
|||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
return MHelper.length(x, MathHelper.clamp(y, -height, 0), z) - radius;
|
||||
return MHelper.length(x, y - MathHelper.clamp(y, 0, height), z) - radius;
|
||||
}
|
||||
}
|
||||
|
|
50
src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java
Normal file
50
src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package ru.betterend.util.sdf.primitive;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
import ru.betterend.util.sdf.ISDF;
|
||||
|
||||
public class SDFLine implements ISDF {
|
||||
private float radius;
|
||||
private float x1;
|
||||
private float y1;
|
||||
private float z1;
|
||||
private float x2;
|
||||
private float y2;
|
||||
private float z2;
|
||||
|
||||
public SDFLine setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SDFLine setStart(float x, float y, float z) {
|
||||
this.x1 = x;
|
||||
this.y1 = y;
|
||||
this.z1 = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SDFLine setEnd(float x, float y, float z) {
|
||||
this.x2 = x;
|
||||
this.y2 = y;
|
||||
this.z2 = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
float pax = x - x1;
|
||||
float pay = y - y1;
|
||||
float paz = z - z1;
|
||||
|
||||
float bax = x2 - x1;
|
||||
float bay = y2 - y1;
|
||||
float baz = z2 - z1;
|
||||
|
||||
float dpb = MHelper.dot(pax, pay, paz, bax, bay, baz);
|
||||
float dbb = MHelper.dot(bax, bay, baz, bax, bay, baz);
|
||||
float h = MathHelper.clamp(dpb / dbb, 0F, 1F);
|
||||
return MHelper.length(pax - bax * h, pay - bay * h, paz - baz * h) - radius;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue