kopia lustrzana https://github.com/jameshball/osci-render
Add camera pos TextFields
rodzic
931e3a4b71
commit
64b149b3c4
|
@ -1,5 +1,6 @@
|
|||
package audio;
|
||||
|
||||
import engine.Vector3;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
@ -56,4 +57,8 @@ public class FrameProducer implements Runnable {
|
|||
public void setFocalLength(Double focalLength) {
|
||||
objParser.setFocalLength(focalLength);
|
||||
}
|
||||
|
||||
public void setCameraPos(Vector3 vector) {
|
||||
objParser.setCameraPos(vector);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ import java.util.List;
|
|||
|
||||
public class Camera {
|
||||
|
||||
private static final int MAX_NUM_STEPS = 1000;
|
||||
|
||||
public static double DEFAULT_FOCAL_LENGTH = 1;
|
||||
|
||||
// Threshold for the max vertex value being displayed when rendering (will change position of
|
||||
|
@ -52,9 +54,11 @@ public class Camera {
|
|||
setPos(new Vector3());
|
||||
List<Vector2> vertices = new ArrayList<>();
|
||||
|
||||
while (maxVertexValue(vertices) > VERTEX_VALUE_THRESHOLD) {
|
||||
int stepsMade = 0;
|
||||
while (maxVertexValue(vertices) > VERTEX_VALUE_THRESHOLD && stepsMade < MAX_NUM_STEPS) {
|
||||
move(new Vector3(0, 0, CAMERA_MOVE_INCREMENT));
|
||||
vertices = sampleVerticesInRender(object);
|
||||
stepsMade++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package engine;
|
||||
|
||||
import com.mokiat.data.front.error.WFException;
|
||||
import com.mokiat.data.front.parser.*;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -117,10 +119,17 @@ public class WorldObject {
|
|||
return newVertices;
|
||||
}
|
||||
|
||||
private Set<Line3D> loadFromFile(String filename) throws IOException {
|
||||
InputStream in = new FileInputStream(filename);
|
||||
final IOBJParser parser = new OBJParser();
|
||||
final OBJModel model = parser.parse(in);
|
||||
private Set<Line3D> loadFromFile(String filename) {
|
||||
OBJModel model;
|
||||
|
||||
try {
|
||||
InputStream in = new FileInputStream(filename);
|
||||
|
||||
IOBJParser parser = new OBJParser();
|
||||
model = parser.parse(in);
|
||||
} catch (IOException e) {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
Set<Line3D> edges = new HashSet<>();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package gui;
|
|||
|
||||
import audio.AudioPlayer;
|
||||
import audio.FrameProducer;
|
||||
import engine.Vector3;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
@ -43,33 +44,39 @@ public class Controller implements Initializable {
|
|||
@FXML
|
||||
private Button chooseFileButton;
|
||||
@FXML
|
||||
public Label fileLabel;
|
||||
private Label fileLabel;
|
||||
@FXML
|
||||
public TextField translationXTextField;
|
||||
private TextField translationXTextField;
|
||||
@FXML
|
||||
public TextField translationYTextField;
|
||||
private TextField translationYTextField;
|
||||
@FXML
|
||||
public Slider weightSlider;
|
||||
private Slider weightSlider;
|
||||
@FXML
|
||||
public Label weightLabel;
|
||||
private Label weightLabel;
|
||||
@FXML
|
||||
public Slider rotateSpeedSlider;
|
||||
private Slider rotateSpeedSlider;
|
||||
@FXML
|
||||
public Label rotateSpeedLabel;
|
||||
private Label rotateSpeedLabel;
|
||||
@FXML
|
||||
public Slider translationSpeedSlider;
|
||||
private Slider translationSpeedSlider;
|
||||
@FXML
|
||||
public Label translationSpeedLabel;
|
||||
private Label translationSpeedLabel;
|
||||
@FXML
|
||||
public Slider scaleSlider;
|
||||
private Slider scaleSlider;
|
||||
@FXML
|
||||
public Label scaleLabel;
|
||||
private Label scaleLabel;
|
||||
@FXML
|
||||
public TitledPane objTitledPane;
|
||||
private TitledPane objTitledPane;
|
||||
@FXML
|
||||
private Slider focalLengthSlider;
|
||||
@FXML
|
||||
private Label focalLengthLabel;
|
||||
@FXML
|
||||
private TextField cameraXTextField;
|
||||
@FXML
|
||||
private TextField cameraYTextField;
|
||||
@FXML
|
||||
private TextField cameraZTextField;
|
||||
|
||||
private Map<Slider, SliderUpdater<Double>> initializeSliderMap() {
|
||||
return Map.of(
|
||||
|
@ -88,7 +95,7 @@ public class Controller implements Initializable {
|
|||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
chooseFile(DEFAULT_PATH);
|
||||
chooseFile(new File(DEFAULT_PATH));
|
||||
|
||||
Map<Slider, SliderUpdater<Double>> sliders = initializeSliderMap();
|
||||
|
||||
|
@ -107,12 +114,23 @@ public class Controller implements Initializable {
|
|||
translationXTextField.textProperty().addListener(translationUpdate);
|
||||
translationYTextField.textProperty().addListener(translationUpdate);
|
||||
|
||||
InvalidationListener cameraPosUpdate = observable ->
|
||||
producer.setCameraPos(new Vector3(
|
||||
tryParse(cameraXTextField.getText()),
|
||||
tryParse(cameraYTextField.getText()),
|
||||
tryParse(cameraZTextField.getText())
|
||||
));
|
||||
|
||||
cameraXTextField.textProperty().addListener(cameraPosUpdate);
|
||||
cameraYTextField.textProperty().addListener(cameraPosUpdate);
|
||||
cameraZTextField.textProperty().addListener(cameraPosUpdate);
|
||||
|
||||
chooseFileButton.setOnAction(e -> {
|
||||
File file = null;
|
||||
while (file == null) {
|
||||
file = fileChooser.showOpenDialog(stage);
|
||||
}
|
||||
chooseFile(file.getAbsolutePath());
|
||||
chooseFile(file);
|
||||
});
|
||||
|
||||
new Thread(producer).start();
|
||||
|
@ -127,11 +145,16 @@ public class Controller implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
private void chooseFile(String path) {
|
||||
private void chooseFile(File file) {
|
||||
try {
|
||||
String path = file.getAbsolutePath();
|
||||
producer.setParser(path);
|
||||
fileLabel.setText(path);
|
||||
objTitledPane.setDisable(!ObjParser.isObjFile(path));
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
fileLabel.setText(path);
|
||||
objTitledPane.setDisable(!ObjParser.isObjFile(path));
|
||||
} else {
|
||||
objTitledPane.setDisable(true);
|
||||
}
|
||||
} catch (IOException | ParserConfigurationException | SAXException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,13 @@
|
|||
<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" />
|
||||
<TextField fx:id="cameraXTextField" layoutX="134.0" layoutY="39.0" prefHeight="26.0" prefWidth="38.0" text="0" />
|
||||
<Label layoutX="44.0" layoutY="44.0" text="Camera pos" />
|
||||
<Label layoutX="118.0" layoutY="44.0" text="x :" />
|
||||
<Label layoutX="180.0" layoutY="43.0" text="y :" />
|
||||
<TextField fx:id="cameraYTextField" layoutX="199.0" layoutY="39.0" prefHeight="26.0" prefWidth="38.0" text="0" />
|
||||
<Label layoutX="244.0" layoutY="43.0" text="z :" />
|
||||
<TextField fx:id="cameraZTextField" layoutX="263.0" layoutY="39.0" prefHeight="26.0" prefWidth="38.0" text="0" />
|
||||
</AnchorPane>
|
||||
</TitledPane>
|
||||
</SplitPane>
|
||||
|
|
|
@ -6,6 +6,7 @@ import engine.WorldObject;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import shapes.Shape;
|
||||
import shapes.Vector2;
|
||||
|
||||
public class ObjParser extends FileParser {
|
||||
|
||||
|
@ -74,4 +75,8 @@ public class ObjParser extends FileParser {
|
|||
public static boolean isObjFile(String path) {
|
||||
return path.matches(".*\\.obj");
|
||||
}
|
||||
|
||||
public void setCameraPos(Vector3 vector) {
|
||||
camera.setPos(vector);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue