Change perspective effect to have a 0 value that applies no effect, add reset rotation buttons

pull/101/head
James Ball 2022-07-10 16:07:23 +01:00 zatwierdzone przez James H Ball
rodzic 3b1eca99ec
commit be2d51c440
4 zmienionych plików z 51 dodań i 8 usunięć

Wyświetl plik

@ -12,6 +12,7 @@ public enum EffectType {
TRACE_MAX(-1),
SMOOTH(100),
DEPTH_3D(52),
Z_POS_3D(-1),
ROTATE_SPEED_3D(-1),
ROTATE_X(-1),
ROTATE_Y(-1),

Wyświetl plik

@ -8,8 +8,9 @@ public class PerspectiveEffect implements SettableEffect {
private double zPos = 1.0;
private Vector3 baseRotation = new Vector3(Math.PI, Math.PI, 0);
private Vector3 currentRotation = baseRotation;
private Vector3 currentRotation = new Vector3();
private double rotateSpeed = 0.0;
private double effectScale = 1.0;
@Override
public Vector2 apply(int count, Vector2 vector) {
@ -20,13 +21,17 @@ public class PerspectiveEffect implements SettableEffect {
double focalLength = 1.0;
return new Vector2(
vertex.x * focalLength / (vertex.z - zPos),
vertex.y * focalLength / (vertex.z - zPos)
(1 - effectScale) * vector.x + effectScale * (vertex.x * focalLength / (vertex.z - zPos)),
(1 - effectScale) * vector.y + effectScale * (vertex.y * focalLength / (vertex.z - zPos))
);
}
@Override
public void setValue(double value) {
this.effectScale = value;
}
public void setZPos(double value) {
zPos = 1.0 + (value - 0.1) * 3;
}
@ -49,4 +54,9 @@ public class PerspectiveEffect implements SettableEffect {
public void setRotationZ(double rotateZ) {
this.baseRotation = new Vector3(baseRotation.x, baseRotation.y, rotateZ * Math.PI);
}
public void resetRotation() {
baseRotation = new Vector3();
currentRotation = new Vector3();
}
}

Wyświetl plik

@ -63,6 +63,8 @@ public class EffectsController implements Initializable, SubController {
@FXML
private EffectComponentGroup rotateZ;
@FXML
private EffectComponentGroup zPos;
@FXML
private EffectComponentGroup translationScale;
@FXML
private EffectComponentGroup translationSpeed;
@ -82,6 +84,10 @@ public class EffectsController implements Initializable, SubController {
private CheckBox translateCheckBox;
@FXML
private Button resetTranslationButton;
@FXML
private Button resetRotationButton;
@FXML
private Button resetPerspectiveRotationButton;
public EffectsController() {
this.wobbleEffect = new WobbleEffect(DEFAULT_SAMPLE_RATE);
@ -119,7 +125,7 @@ public class EffectsController implements Initializable, SubController {
if (type == EffectType.DEPTH_3D) {
Platform.runLater(() ->
List.of(rotateSpeed3D, rotateX, rotateY, rotateZ).forEach(ecg -> {
List.of(rotateSpeed3D, rotateX, rotateY, rotateZ, zPos).forEach(ecg -> {
ecg.controller.slider.setDisable(!checked);
ecg.controller.spinner.setDisable(!checked);
})
@ -162,6 +168,7 @@ public class EffectsController implements Initializable, SubController {
rotateX.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect((perspectiveEffect::setRotationX))));
rotateY.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect((perspectiveEffect::setRotationY))));
rotateZ.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect((perspectiveEffect::setRotationZ))));
zPos.controller.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect((perspectiveEffect::setZPos))));
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()));
@ -213,10 +220,23 @@ public class EffectsController implements Initializable, SubController {
translateEllipseCheckBox.selectedProperty().addListener((e, old, ellipse) -> translateEffect.setEllipse(ellipse));
List.of(rotateSpeed3D, rotateX, rotateY, rotateZ).forEach(ecg -> {
List.of(rotateSpeed3D, rotateX, rotateY, rotateZ, zPos).forEach(ecg -> {
ecg.controller.slider.setDisable(true);
ecg.controller.spinner.setDisable(true);
});
resetRotationButton.setOnAction(e -> {
rotateEffect.resetTheta();
rotateSpeed.controller.slider.setValue(0);
});
resetPerspectiveRotationButton.setOnAction(e -> {
rotateX.controller.slider.setValue(0);
rotateY.controller.slider.setValue(0);
rotateZ.controller.slider.setValue(0);
rotateSpeed3D.controller.slider.setValue(0);
perspectiveEffect.resetRotation();
});
}
private List<EffectComponentGroup> effects() {
@ -230,6 +250,7 @@ public class EffectsController implements Initializable, SubController {
traceMin,
traceMax,
rotateSpeed3D,
zPos,
rotateX,
rotateY,
rotateZ,

Wyświetl plik

@ -11,9 +11,9 @@
<?import javafx.scene.layout.VBox?>
<?import sh.ball.gui.components.EffectComponentGroup?>
<ScrollPane hbarPolicy="NEVER" prefHeight="954.0" prefWidth="608.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.EffectsController">
<ScrollPane hbarPolicy="NEVER" prefHeight="1065.0" prefWidth="608.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.EffectsController">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="951.0" prefWidth="606.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="1049.0" prefWidth="606.0">
<children>
<VBox>
<children>
@ -79,11 +79,22 @@
</padding>
</Separator>
<EffectComponentGroup fx:id="rotateSpeed" increment="0.05" label="rotateSpeed" majorTickUnit="1.0" max="10.0" min="0.0" name="2D Rotate speed" type="ROTATE" value="0.0" />
<EffectComponentGroup fx:id="depthScale" increment="0.005" label="depthScale" majorTickUnit="0.1" max="1.0" min="0.0" name="3D Depth" type="DEPTH_3D" value="0.1" />
<AnchorPane prefHeight="34.0" prefWidth="602.0">
<children>
<Button fx:id="resetRotationButton" layoutX="245.0" layoutY="1.0" mnemonicParsing="false" text="Reset 2D Rotation" />
</children>
</AnchorPane>
<EffectComponentGroup fx:id="depthScale" increment="0.005" label="depthScale" majorTickUnit="0.1" max="1.0" min="0.0" name="3D Perspective" type="DEPTH_3D" value="1.0" />
<EffectComponentGroup fx:id="zPos" alwaysEnabled="true" increment="0.005" label="zPos" max="1.0" name="3D Distance" type="Z_POS_3D" value="0.1" />
<EffectComponentGroup fx:id="rotateSpeed3D" alwaysEnabled="true" increment="0.005" label="rotateSpeed3d" majorTickUnit="0.2" max="1.0" min="-1.0" name="3D Rotate speed" type="ROTATE_SPEED_3D" value="0.0" />
<EffectComponentGroup fx:id="rotateX" alwaysEnabled="true" increment="0.01" label="imageRotateX" majorTickUnit="0.2" max="1.0" min="-1.0" name="Rotate x" type="ROTATE_X" value="1.0" />
<EffectComponentGroup fx:id="rotateY" alwaysEnabled="true" increment="0.01" label="imageRotateY" majorTickUnit="0.2" max="1.0" min="-1.0" name="Rotate y" type="ROTATE_Y" value="1.0" />
<EffectComponentGroup fx:id="rotateZ" alwaysEnabled="true" increment="0.01" label="imageRotateZ" majorTickUnit="0.2" max="1.0" min="-1.0" name="Rotate z" type="ROTATE_Z" value="0.0" />
<AnchorPane prefHeight="34.0" prefWidth="602.0">
<children>
<Button fx:id="resetPerspectiveRotationButton" layoutX="245.0" layoutY="1.0" mnemonicParsing="false" text="Reset 3D Rotation" />
</children>
</AnchorPane>
<Label alignment="CENTER" prefWidth="601.0" text="Other" textAlignment="JUSTIFY">
<padding>
<Insets bottom="5.0" />