Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bba8a27
commit 1b3fa79
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/org/sdoaj/jimgus/util/sdf/operators/SDFDisplacement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.sdoaj.jimgus.util.sdf.operators; | ||
|
||
import org.sdoaj.jimgus.util.math.Vec3f; | ||
|
||
import java.util.function.Function; | ||
|
||
// doesn't really work with some booleans and any SDFs that aren't linear (e.g. SDFLine with no caps) | ||
public class SDFDisplacement extends SDFUnary { | ||
// negative values expand the shape, positive values shrink the shape | ||
private Function<Vec3f, Float> displacement; | ||
|
||
public SDFDisplacement setDisplacement(float displacement) { | ||
return setDisplacement(pos -> displacement); | ||
} | ||
|
||
public SDFDisplacement setDisplacement(Function<Vec3f, Float> displacement) { | ||
this.displacement = displacement; | ||
return this; | ||
} | ||
|
||
@Override | ||
public float distance(Vec3f pos) { | ||
return this.source.distance(pos) + displacement.apply(pos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters