More SDF tests

This commit is contained in:
paulevsGitch 2020-09-29 01:01:42 +03:00
parent cf8955ea4b
commit 2e632bf245
13 changed files with 111 additions and 22 deletions

View file

@ -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;
}
}

View 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;
}
}