What I made in JavaFx: https://i.stack.imgur.com/OfOmO.gif
problem: The box is moving under the box instead of through the box
What supposed to be happen: https://i.stack.imgur.com/ZWgda.gif //preview made in blender
explain: The moving cube should passes through the other cube when I'm pressing the down key
And here's my code:
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.transform.*;
import javafx.stage.Stage;
public class Main extends Application {
@Override public void start(Stage stage) throws Exception {
Group root3D = new Group();
AnchorPane globalRoot = new AnchorPane();
Scene scene = new Scene(globalRoot, 800, 400, true);
PerspectiveCamera camera = new PerspectiveCamera(true);
SubScene sub = new SubScene(root3D,800,400,false,SceneAntialiasing.BALANCED);
camera.getTransforms().addAll(new Translate(),new Rotate(0, Rotate.Z_AXIS),new Rotate(0, Rotate.Y_AXIS), new Rotate(30, Rotate.X_AXIS), new Translate(0, 0, -50));
sub.setCamera(camera);
globalRoot.getChildren().add(sub);
stage.setScene(scene);
stage.show();
PhongMaterial material = new PhongMaterial();
Image image = new Image(getClass().getResourceAsStream("texture.png"));
material.setDiffuseMap(image);
material.setSpecularColor(Color.WHITE);
Box box1 = new Box(5,5,5);
box1.setMaterial(material);
box1.setTranslateY(-5);
root3D.getChildren().add(box1);
Box box2 = new Box(5,5,5);
box2.setMaterial(material);
root3D.getChildren().add(box2);
scene.setOnKeyPressed((EventHandler<? super KeyEvent>) new EventHandler <KeyEvent>() {
@Override public void handle(KeyEvent arg0) {
if (arg0.getCode().toString() == "DOWN") {
box1.setTranslateY(box1.getTranslateY()+1);
}}});
}
public static void main(String[] args) {
launch(args);
}
}
Here's the texture: https://i.stack.imgur.com/NQjGN.png
Help, please
