From 70d76aa68d0f538a62c55d2935beefd20af6f83c Mon Sep 17 00:00:00 2001 From: James Ball Date: Wed, 15 Jun 2022 22:33:12 +0100 Subject: [PATCH] Add basic code for 3D rotate effect --- .../java/sh/ball/audio/effect/EffectType.java | 3 +- .../ball/audio/effect/PerspectiveEffect.java | 36 +++++++++++++++ src/main/java/sh/ball/gui/EffectType.java | 5 --- .../gui/controller/EffectsController.java | 8 +++- src/main/resources/css/main.css | 10 +++++ src/main/resources/fxml/effects.fxml | 45 +++++++++++-------- 6 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 src/main/java/sh/ball/audio/effect/PerspectiveEffect.java delete mode 100644 src/main/java/sh/ball/gui/EffectType.java diff --git a/src/main/java/sh/ball/audio/effect/EffectType.java b/src/main/java/sh/ball/audio/effect/EffectType.java index 0259717..73b63d8 100644 --- a/src/main/java/sh/ball/audio/effect/EffectType.java +++ b/src/main/java/sh/ball/audio/effect/EffectType.java @@ -10,5 +10,6 @@ public enum EffectType { WOBBLE, TRACE_MIN, TRACE_MAX, - SMOOTH + SMOOTH, + ROTATE_3D } diff --git a/src/main/java/sh/ball/audio/effect/PerspectiveEffect.java b/src/main/java/sh/ball/audio/effect/PerspectiveEffect.java new file mode 100644 index 0000000..1794239 --- /dev/null +++ b/src/main/java/sh/ball/audio/effect/PerspectiveEffect.java @@ -0,0 +1,36 @@ +package sh.ball.audio.effect; + +import sh.ball.engine.Vector3; +import sh.ball.shapes.Vector2; + +// 3D rotation effect +public class PerspectiveEffect extends PhaseEffect implements SettableEffect { + + private double focalLength = 1.0; + private double zPos = 1.0; + + public PerspectiveEffect(int sampleRate, double speed) { + super(sampleRate, speed); + } + + public PerspectiveEffect(int sampleRate) { + this(sampleRate, 1); + } + + @Override + public Vector2 apply(int count, Vector2 vector) { + Vector3 vertex = new Vector3(vector.x, vector.y, 0.0); + double theta = nextTheta(); + vertex = vertex.rotate(new Vector3(0, theta, theta)); + + return new Vector2( + vertex.x * focalLength / (vertex.z - zPos), + vertex.y * focalLength / (vertex.z - zPos) + ); + } + + @Override + public void setValue(double value) { + zPos = 1.0 + (value - 0.5) * 3; + } +} diff --git a/src/main/java/sh/ball/gui/EffectType.java b/src/main/java/sh/ball/gui/EffectType.java deleted file mode 100644 index 0e42cee..0000000 --- a/src/main/java/sh/ball/gui/EffectType.java +++ /dev/null @@ -1,5 +0,0 @@ -package sh.ball.gui; - -enum EffectType { - VECTOR_CANCELLING -} diff --git a/src/main/java/sh/ball/gui/controller/EffectsController.java b/src/main/java/sh/ball/gui/controller/EffectsController.java index 70480b6..e591c51 100644 --- a/src/main/java/sh/ball/gui/controller/EffectsController.java +++ b/src/main/java/sh/ball/gui/controller/EffectsController.java @@ -34,6 +34,7 @@ public class EffectsController implements Initializable, SubController { private Map effectTypes; private final WobbleEffect wobbleEffect; + private final PerspectiveEffect perspectiveEffect; @FXML private EffectComponentGroup vectorCancelling; @@ -51,9 +52,12 @@ public class EffectsController implements Initializable, SubController { private EffectComponentGroup traceMax; @FXML private EffectComponentGroup traceMin; + @FXML + private EffectComponentGroup perspective; public EffectsController() { this.wobbleEffect = new WobbleEffect(DEFAULT_SAMPLE_RATE); + this.perspectiveEffect = new PerspectiveEffect(DEFAULT_SAMPLE_RATE); } private Map mergeEffectMaps(Function> map) { @@ -90,6 +94,7 @@ public class EffectsController implements Initializable, SubController { public void setAudioDevice(AudioDevice device) { wobbleEffect.setSampleRate(device.sampleRate()); + perspectiveEffect.setSampleRate(device.sampleRate()); Map, EffectAnimator> comboAnimatorMap = getComboBoxAnimatorMap(); for (EffectAnimator animator : comboAnimatorMap.values()) { animator.setSampleRate(device.sampleRate()); @@ -118,6 +123,7 @@ public class EffectsController implements Initializable, SubController { initializeEffectTypes(); wobble.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, wobbleEffect)); + perspective.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, perspectiveEffect)); traceMin.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(audioPlayer::setTraceMin))); traceMax.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(audioPlayer::setTraceMax))); vectorCancelling.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new VectorCancellingEffect())); @@ -148,7 +154,7 @@ public class EffectsController implements Initializable, SubController { } private List effects() { - return List.of(vectorCancelling, bitCrush, verticalDistort, horizontalDistort, wobble, smoothing, traceMin, traceMax); + return List.of(vectorCancelling, bitCrush, verticalDistort, horizontalDistort, wobble, smoothing, traceMin, traceMax, perspective); } @Override diff --git a/src/main/resources/css/main.css b/src/main/resources/css/main.css index 153d761..8eb9a7b 100644 --- a/src/main/resources/css/main.css +++ b/src/main/resources/css/main.css @@ -54,6 +54,16 @@ -fx-background-radius: 0; } +.scroll-pane .scroll-bar:vertical { + -fx-unit-increment: 10 ; + -fx-block-increment: 50 ; +} + +.scroll-pane .scroll-bar:horizontal { + -fx-unit-increment: 5 ; + -fx-block-increment: 20 ; +} + .titled-pane > .title > .arrow-button .arrow { -fx-background-color: white, white; -fx-background-insets: 1 0 -1 0, 0; diff --git a/src/main/resources/fxml/effects.fxml b/src/main/resources/fxml/effects.fxml index 5b09f45..37b9416 100644 --- a/src/main/resources/fxml/effects.fxml +++ b/src/main/resources/fxml/effects.fxml @@ -1,26 +1,33 @@ + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +