Add reset rotation button

pull/35/head
James Ball 2021-05-18 20:01:29 +01:00
rodzic c552be2f04
commit b3ec9a2442
6 zmienionych plików z 62 dodań i 16 usunięć

Wyświetl plik

@ -24,6 +24,10 @@ public class FrameProducer<T> implements Runnable {
running = false;
}
public Object setFrameSettings(Object settings) {
return setFrameSettings(settings, false);
}
public Object setFrameSettings(Object settings, boolean flushFrames) {
if (flushFrames) {
renderer.flushFrames();

Wyświetl plik

@ -31,6 +31,7 @@ import org.xml.sax.SAXException;
import sh.ball.audio.effect.TranslateEffect;
import sh.ball.engine.Vector3;
import sh.ball.parser.obj.ObjFrameSettings;
import sh.ball.parser.obj.ObjSettingsFactory;
import sh.ball.parser.obj.ObjParser;
import sh.ball.parser.ParserFactory;
import sh.ball.shapes.Shape;
@ -101,6 +102,8 @@ public class Controller implements Initializable {
@FXML
private TextField rotateZTextField;
@FXML
private Button resetRotationButton;
@FXML
private CheckBox vectorCancellingCheckBox;
@FXML
private Slider vectorCancellingSlider;
@ -167,7 +170,7 @@ public class Controller implements Initializable {
translationYTextField.textProperty().addListener(translationUpdate);
InvalidationListener cameraPosUpdate = observable ->
producer.setFrameSettings(new ObjFrameSettings(new Vector3(
producer.setFrameSettings(ObjSettingsFactory.cameraPosition(new Vector3(
tryParse(cameraXTextField.getText()),
tryParse(cameraYTextField.getText()),
tryParse(cameraZTextField.getText())
@ -178,16 +181,18 @@ public class Controller implements Initializable {
cameraZTextField.textProperty().addListener(cameraPosUpdate);
InvalidationListener rotateUpdate = observable ->
producer.setFrameSettings(new ObjFrameSettings(new Vector3(
producer.setFrameSettings(ObjSettingsFactory.rotation(new Vector3(
tryParse(rotateXTextField.getText()),
tryParse(rotateYTextField.getText()),
tryParse(rotateZTextField.getText())
), null), false);
)));
rotateXTextField.textProperty().addListener(rotateUpdate);
rotateYTextField.textProperty().addListener(rotateUpdate);
rotateZTextField.textProperty().addListener(rotateUpdate);
resetRotationButton.setOnAction(e -> producer.setFrameSettings(ObjSettingsFactory.resetRotation()));
InvalidationListener vectorCancellingListener = e ->
updateEffect(EffectType.VECTOR_CANCELLING, vectorCancellingCheckBox.isSelected(),
EffectFactory.vectorCancelling((int) vectorCancellingSlider.getValue()));
@ -219,7 +224,10 @@ public class Controller implements Initializable {
}
private void setFocalLength(double focalLength) {
Vector3 pos = (Vector3) producer.setFrameSettings(new ObjFrameSettings(focalLength), true);
Vector3 pos = (Vector3) producer.setFrameSettings(
ObjSettingsFactory.focalLength(focalLength),
true
);
cameraXTextField.setText(String.valueOf(pos.getX()));
cameraYTextField.setText(String.valueOf(pos.getY()));
cameraZTextField.setText(String.valueOf(pos.getZ()));
@ -227,8 +235,7 @@ public class Controller implements Initializable {
private void setObjectRotateSpeed(double rotateSpeed) {
producer.setFrameSettings(
new ObjFrameSettings(null, (Math.exp(3 * rotateSpeed) - 1) / 50),
false
ObjSettingsFactory.rotateSpeed((Math.exp(3 * rotateSpeed) - 1) / 50)
);
}

Wyświetl plik

@ -48,6 +48,9 @@ public class ObjFrameSet implements FrameSet<List<Shape>> {
if (obj.rotateSpeed != null) {
this.rotateSpeed = obj.rotateSpeed;
}
if (obj.resetRotation) {
object.resetRotation();
}
}
return camera.getPos();

Wyświetl plik

@ -8,17 +8,22 @@ public class ObjFrameSettings {
protected Vector3 cameraPos;
protected Vector3 rotation;
protected Double rotateSpeed;
protected boolean resetRotation = false;
public ObjFrameSettings(double focalLength) {
protected ObjFrameSettings(double focalLength) {
this.focalLength = focalLength;
}
public ObjFrameSettings(Vector3 cameraPos) {
protected ObjFrameSettings(Vector3 cameraPos) {
this.cameraPos = cameraPos;
}
public ObjFrameSettings(Vector3 rotation, Double rotateSpeed) {
protected ObjFrameSettings(Vector3 rotation, Double rotateSpeed) {
this.rotation = rotation;
this.rotateSpeed = rotateSpeed;
}
protected ObjFrameSettings(boolean resetRotation) {
this.resetRotation = resetRotation;
}
}

Wyświetl plik

@ -0,0 +1,26 @@
package sh.ball.parser.obj;
import sh.ball.engine.Vector3;
public class ObjSettingsFactory {
public static ObjFrameSettings focalLength(double focalLength) {
return new ObjFrameSettings(focalLength);
}
public static ObjFrameSettings cameraPosition(Vector3 cameraPos) {
return new ObjFrameSettings(cameraPos);
}
public static ObjFrameSettings rotation(Vector3 rotation) {
return new ObjFrameSettings(rotation, null);
}
public static ObjFrameSettings rotateSpeed(double rotateSpeed) {
return new ObjFrameSettings(null, rotateSpeed);
}
public static ObjFrameSettings resetRotation() {
return new ObjFrameSettings(true);
}
}

Wyświetl plik

@ -12,17 +12,17 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane alignment="center" hgap="10" prefWidth="400.0" vgap="10" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1">
<GridPane alignment="center" hgap="10" prefHeight="653.0" prefWidth="400.0" vgap="10" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<AnchorPane prefHeight="602.0" prefWidth="400.0">
<AnchorPane prefHeight="737.0" prefWidth="400.0">
<Button fx:id="chooseFileButton" layoutX="8.0" layoutY="15.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="119.0" text="Choose File" />
<SplitPane dividerPositions="0.3406015037593984, 0.669548872180451" layoutX="8.0" layoutY="63.0" orientation="VERTICAL" prefHeight="533.0" prefWidth="386.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="271.0" prefWidth="385.0">
<SplitPane dividerPositions="0.31499312242090777, 0.6158872077028884" layoutX="6.0" layoutY="63.0" orientation="VERTICAL" prefHeight="583.0" prefWidth="388.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="178.0" prefWidth="396.0">
<Slider fx:id="rotateSpeedSlider" layoutX="116.0" layoutY="79.0" max="10.0" prefHeight="14.0" prefWidth="198.0" />
<Label layoutX="37.0" layoutY="77.0" text="Rotate speed" />
<Label fx:id="rotateSpeedLabel" layoutX="316.0" layoutY="77.0" maxWidth="40.0" text="0" />
@ -43,7 +43,7 @@
</AnchorPane>
<TitledPane animated="false" collapsible="false" prefHeight="169.0" prefWidth="385.0" text="Effects" SplitPane.resizableWithParent="false">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="66.0" prefWidth="383.0">
<children>
<CheckBox fx:id="vectorCancellingCheckBox" layoutX="14.0" layoutY="14.0" mnemonicParsing="false" text="Vector cancelling" />
<Slider fx:id="vectorCancellingSlider" blockIncrement="1.0" disable="true" layoutX="141.0" layoutY="16.0" majorTickUnit="1.0" max="10.0" min="2.0" minorTickCount="0" prefHeight="33.0" prefWidth="198.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="2.0" />
@ -53,8 +53,8 @@
</AnchorPane>
</content>
</TitledPane>
<TitledPane fx:id="objTitledPane" animated="false" collapsible="false" prefHeight="186.0" prefWidth="385.0" text="3D .obj file settings" SplitPane.resizableWithParent="false">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="96.0" prefWidth="382.0">
<TitledPane fx:id="objTitledPane" animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="400.0" prefWidth="385.0" text="3D .obj file settings" SplitPane.resizableWithParent="false">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="155.0" prefWidth="384.0">
<Slider fx:id="focalLengthSlider" blockIncrement="2.0" layoutX="116.0" layoutY="15.0" max="2.0" min="1.0E-5" prefHeight="14.0" prefWidth="198.0" value="1.0" />
<Label layoutX="43.0" layoutY="14.0" text="Focal length" />
<Label fx:id="focalLengthLabel" layoutX="316.0" layoutY="14.0" text="1" />
@ -75,6 +75,7 @@
<TextField fx:id="rotateYTextField" layoutX="218.0" layoutY="111.0" prefHeight="26.0" prefWidth="58.0" text="0" />
<Label layoutX="283.0" layoutY="115.0" text="z :" />
<TextField fx:id="rotateZTextField" layoutX="302.0" layoutY="111.0" prefHeight="26.0" prefWidth="58.0" text="0" />
<Button fx:id="resetRotationButton" layoutX="145.0" layoutY="153.0" mnemonicParsing="false" text="Reset Rotation" />
</AnchorPane>
</TitledPane>
</SplitPane>