Add basic code for 3D rotate effect

pull/88/head
James Ball 2022-06-15 22:33:12 +01:00 zatwierdzone przez James H Ball
rodzic 71d93f152e
commit 70d76aa68d
6 zmienionych plików z 81 dodań i 26 usunięć

Wyświetl plik

@ -10,5 +10,6 @@ public enum EffectType {
WOBBLE, WOBBLE,
TRACE_MIN, TRACE_MIN,
TRACE_MAX, TRACE_MAX,
SMOOTH SMOOTH,
ROTATE_3D
} }

Wyświetl plik

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

Wyświetl plik

@ -1,5 +0,0 @@
package sh.ball.gui;
enum EffectType {
VECTOR_CANCELLING
}

Wyświetl plik

@ -34,6 +34,7 @@ public class EffectsController implements Initializable, SubController {
private Map<EffectType, Slider> effectTypes; private Map<EffectType, Slider> effectTypes;
private final WobbleEffect wobbleEffect; private final WobbleEffect wobbleEffect;
private final PerspectiveEffect perspectiveEffect;
@FXML @FXML
private EffectComponentGroup vectorCancelling; private EffectComponentGroup vectorCancelling;
@ -51,9 +52,12 @@ public class EffectsController implements Initializable, SubController {
private EffectComponentGroup traceMax; private EffectComponentGroup traceMax;
@FXML @FXML
private EffectComponentGroup traceMin; private EffectComponentGroup traceMin;
@FXML
private EffectComponentGroup perspective;
public EffectsController() { public EffectsController() {
this.wobbleEffect = new WobbleEffect(DEFAULT_SAMPLE_RATE); this.wobbleEffect = new WobbleEffect(DEFAULT_SAMPLE_RATE);
this.perspectiveEffect = new PerspectiveEffect(DEFAULT_SAMPLE_RATE);
} }
private <K, V> Map<K, V> mergeEffectMaps(Function<EffectComponentGroup, Map<K, V>> map) { private <K, V> Map<K, V> mergeEffectMaps(Function<EffectComponentGroup, Map<K, V>> map) {
@ -90,6 +94,7 @@ public class EffectsController implements Initializable, SubController {
public void setAudioDevice(AudioDevice device) { public void setAudioDevice(AudioDevice device) {
wobbleEffect.setSampleRate(device.sampleRate()); wobbleEffect.setSampleRate(device.sampleRate());
perspectiveEffect.setSampleRate(device.sampleRate());
Map<ComboBox<AnimationType>, EffectAnimator> comboAnimatorMap = getComboBoxAnimatorMap(); Map<ComboBox<AnimationType>, EffectAnimator> comboAnimatorMap = getComboBoxAnimatorMap();
for (EffectAnimator animator : comboAnimatorMap.values()) { for (EffectAnimator animator : comboAnimatorMap.values()) {
animator.setSampleRate(device.sampleRate()); animator.setSampleRate(device.sampleRate());
@ -118,6 +123,7 @@ public class EffectsController implements Initializable, SubController {
initializeEffectTypes(); initializeEffectTypes();
wobble.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, wobbleEffect)); 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))); traceMin.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(audioPlayer::setTraceMin)));
traceMax.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(audioPlayer::setTraceMax))); traceMax.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(audioPlayer::setTraceMax)));
vectorCancelling.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new VectorCancellingEffect())); vectorCancelling.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new VectorCancellingEffect()));
@ -148,7 +154,7 @@ public class EffectsController implements Initializable, SubController {
} }
private List<EffectComponentGroup> effects() { private List<EffectComponentGroup> 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 @Override

Wyświetl plik

@ -54,6 +54,16 @@
-fx-background-radius: 0; -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 { .titled-pane > .title > .arrow-button .arrow {
-fx-background-color: white, white; -fx-background-color: white, white;
-fx-background-insets: 1 0 -1 0, 0; -fx-background-insets: 1 0 -1 0, 0;

Wyświetl plik

@ -1,26 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import sh.ball.gui.components.EffectComponentGroup?> <?import sh.ball.gui.components.EffectComponentGroup?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="355.0" prefWidth="606.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.EffectsController">
<children> <ScrollPane hbarPolicy="NEVER" prefHeight="381.0" prefWidth="608.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.EffectsController">
<VBox> <content>
<children> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="380.0" prefWidth="606.0">
<EffectComponentGroup fx:id="vectorCancelling" label="vectorCancelling" max="1.0" min="0.0" increment="0.005" name="Vector cancelling" type="VECTOR_CANCELLING" value="0.11111111" /> <children>
<EffectComponentGroup fx:id="bitCrush" label="bitCrush" max="1.0" min="0.0" increment="0.005" name="Bit crush" type="BIT_CRUSH" value="0.6666666" /> <VBox>
<EffectComponentGroup fx:id="verticalDistort" label="verticalDistort" max="1.0" min="0.0" increment="0.005" name="Vertical shift" type="VERTICAL_DISTORT" value="0.2" /> <children>
<EffectComponentGroup fx:id="horizontalDistort" label="horizontalDistort" max="1.0" min="0.0" increment="0.005" name="Horizontal shift" type="HORIZONTAL_DISTORT" value="0.2" /> <EffectComponentGroup fx:id="vectorCancelling" increment="0.005" label="vectorCancelling" max="1.0" min="0.0" name="Vector cancelling" type="VECTOR_CANCELLING" value="0.11111111" />
<EffectComponentGroup fx:id="wobble" label="wobble" max="1.0" min="0.0" increment="0.005" name="Wobble" type="WOBBLE" value="0.2" /> <EffectComponentGroup fx:id="bitCrush" increment="0.005" label="bitCrush" max="1.0" min="0.0" name="Bit crush" type="BIT_CRUSH" value="0.6666666" />
<EffectComponentGroup fx:id="smoothing" label="smoothing" max="1.0" min="0.0" increment="0.005" name="Smoothing" type="SMOOTH" value="0.125" /> <EffectComponentGroup fx:id="verticalDistort" increment="0.005" label="verticalDistort" max="1.0" min="0.0" name="Vertical shift" type="VERTICAL_DISTORT" value="0.2" />
<EffectComponentGroup fx:id="traceMax" label="traceMax" max="1.0" min="0.0" increment="0.005" name="Trace max" type="TRACE_MAX" value="0.5" /> <EffectComponentGroup fx:id="horizontalDistort" increment="0.005" label="horizontalDistort" max="1.0" min="0.0" name="Horizontal shift" type="HORIZONTAL_DISTORT" value="0.2" />
<EffectComponentGroup fx:id="traceMin" label="traceMin" max="1.0" min="0.0" increment="0.005" name="Trace min" type="TRACE_MIN" value="0.5" /> <EffectComponentGroup fx:id="wobble" increment="0.005" label="wobble" max="1.0" min="0.0" name="Wobble" type="WOBBLE" value="0.2" />
</children> <EffectComponentGroup fx:id="smoothing" increment="0.005" label="smoothing" max="1.0" min="0.0" name="Smoothing" type="SMOOTH" value="0.125" />
<padding> <EffectComponentGroup fx:id="traceMax" increment="0.005" label="traceMax" max="1.0" min="0.0" name="Trace max" type="TRACE_MAX" value="0.5" />
<Insets top="5.0" /> <EffectComponentGroup fx:id="traceMin" increment="0.005" label="traceMin" max="1.0" min="0.0" name="Trace min" type="TRACE_MIN" value="0.5" />
</padding> <EffectComponentGroup fx:id="perspective" increment="0.005" label="perspective" max="1.0" min="0.0" name="3D Rotation" type="ROTATE_3D" value="0.5" />
</VBox> </children>
</children> <padding>
</AnchorPane> <Insets top="5.0" />
</padding>
</VBox>
</children>
</AnchorPane>
</content>
</ScrollPane>