Commit d07cc99e authored by Sergio Emanuel Rodriguez Rivera's avatar Sergio Emanuel Rodriguez Rivera
Browse files

made same changes to MillionTriangle

parent 1d794007
Loading
Loading
Loading
Loading
+21 −23
Original line number Diff line number Diff line
package org.example.newmat;
import Graph.readFile;

import Shape.MovingObject;
import Shape.VisibleWindow;
import Shape.Obstacle;
import Shape.ObstacleField;

import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.geometry.Bounds;
import javafx.geometry.Point3D;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.*;
import javafx.scene.shape.Box;
import javafx.scene.shape.Line;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static java.lang.Math.*;
import static java.lang.Math.min;


/**
@@ -189,19 +181,24 @@ public class MillionTriangle extends Application {
        //Lays out the children in Z order with the last member being front most
        //Effectively allows you to layer multiple elements
        //We are layering our 3D scene with a 2D label on top of it
        StackPane Layers = new StackPane();
        Layers.getChildren().addAll(subScene3D, fpsLabel, scoreLabel);
        StackPane.setAlignment(fpsLabel, Pos.BOTTOM_RIGHT); //Places FPS in bottom right
        StackPane.setAlignment(scoreLabel, Pos.TOP_LEFT); //Places FPS in bottom right
        Pane layers = new Pane();  // This replaces StackPane for direct control
        layers.setPrefSize(1500, 800); // Set the preferred size to match the scene
        layers.getChildren().add(subScene3D);  // Add the 3D subscene
        layers.getChildren().addAll(fpsLabel, scoreLabel);  // Add labels

        fpsLabel.setLayoutX(1350); // Position the FPS label in the bottom-right corner
        fpsLabel.setLayoutY(780);
        scoreLabel.setLayoutX(20);  // Position the score label in the top-left corner
        scoreLabel.setLayoutY(20);

        Scene scene = new Scene(Layers, 1500, 800);

        Scene scene = new Scene(layers, 1500, 800);


        /*
        Mouse event for setting anchors
         */
        ourWindow.setOnMousePressed(mouseEvent -> {
        layers.setOnMousePressed(mouseEvent -> {
            anchorX = mouseEvent.getX();
            anchorY = mouseEvent.getY();
            //System.out.println("Mouse pressed at: " + anchorX + ", " + anchorY);
@@ -212,14 +209,14 @@ public class MillionTriangle extends Application {
            slingLine.setStartY(anchorY);
            slingLine.setEndX(anchorX);
            slingLine.setEndY(anchorY);
            group3D.getChildren().add(slingLine);
            layers.getChildren().add(slingLine);
        });

        /*
        Mouse event for drawing line as the mouse is dragged through the window.
         */

        ourWindow.setOnMouseDragged(mouseEvent -> {
        layers.setOnMouseDragged(mouseEvent -> {
            double dragX = mouseEvent.getX();
            double dragY = mouseEvent.getY();
            //System.out.println("Mouse dragged to: " + dragX + ", " + dragY);
@@ -233,12 +230,13 @@ public class MillionTriangle extends Application {
        Mouse event to launch object and delete the slingLine drawn on window.
         */

        ourWindow.setOnMouseReleased(mouseEvent -> {
        layers.setOnMouseReleased(mouseEvent -> {
            releaseX = mouseEvent.getX();
            releaseY = mouseEvent.getY();
            //System.out.println("Mouse released at: " + releaseX + ", " + releaseY);

            for (MovingObject o : objects ) {

                double x = releaseX -anchorX;
                double y = releaseY - anchorY;
                x = min(x,50);
@@ -247,7 +245,7 @@ public class MillionTriangle extends Application {
            }

            // Remove the sling visualization line
            group3D.getChildren().remove(slingLine);
            layers.getChildren().remove(slingLine);

        });