Commit c57779bd authored by Timothy  Borunov's avatar Timothy Borunov
Browse files

Made collisions work correctly and gravity works correctly. Need to make a zero velocity condition

parent 1fcb9094
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class MovingObject {
    */

    public void initPhysics(double grav, double speed) {
        gravity = 1;
        gravity = 10;
    }

    public void setTexCoords(float t1, float t2) {
@@ -85,11 +85,11 @@ public class MovingObject {
        triangleView.getTransforms().add(translate);
    }

    public void updateTranslate() {
        velocityVec[1] += gravity;
        translate.setX(translate.getX() + velocityVec[0]);
        translate.setY(translate.getY() + velocityVec[1]);
        translate.setZ(translate.getZ() + velocityVec[2]);
    public void updateTranslate(double x, double y, double z) {
        //velocityVec[1] += gravity;
        translate.setX(translate.getX() + x);
        translate.setY(translate.getY() + y);
        translate.setZ(translate.getZ() + z);
    }

    public Translate getTranslate() {
@@ -100,6 +100,12 @@ public class MovingObject {
        return velocityVec;
    }

    public void updateVelocity() {
        velocityVec[1] += gravity;
    }

    public void checkCollision() {}

    public void initVelocity() {
        for (int ii = 0; ii < 3; ii++) {
            velocityVec[ii] = directionVec[ii] * speed;
+32 −8
Original line number Diff line number Diff line
@@ -56,18 +56,18 @@ public class GraphicsAndWindowsTest extends Application {
//                sceneWindow.getYOffset(),350,100, 20, 50, "Box",
//                Color.ORANGERED);

        String[] ob2 = {"--image", "src/teapot.txt", "--speed", "20", "--dir", "4,", "10,", "6"};
        String[] ob2 = {"--image", "src/teapot.txt", "--speed", "15", "--dir", "4,", "7,", "10"};
        String[] ob3 = {"--image", "src/teapot.txt", "--speed", "5", "--dir", "1,", "1,", "1"};
        String[] ob4 = {"--image", "src/teapot.txt", "--speed", "100", "--dir", "3,", "5,", "7"};
        //String[] ob4 = {"--image", "src/teapot.txt", "--speed", "100", "--dir", "3,", "5,", "7"};
        MovingObject newObject1 = new MovingObject(getParameters().getRaw().toArray(new String[0]));
        MovingObject newObject2 = new MovingObject(ob2);
        MovingObject newObject3 = new MovingObject(ob3);
        MovingObject newObject4 = new MovingObject(ob4);
        objects = new MovingObject[4];
        //MovingObject newObject4 = new MovingObject(ob4);
        objects = new MovingObject[3];
        objects[0] = newObject1;
        objects[1] = newObject2;
        objects[2] = newObject3;
        objects[3] = newObject4;
        //objects[3] = newObject4;


        Group group3D = new Group(); // Group of our 3D elements
@@ -176,7 +176,6 @@ public class GraphicsAndWindowsTest extends Application {
            @Override
            public void handle(long now) {
                //Built in class that helps calculate the bounds of the mesh for collision
                //Bounds meshBounds = newObject1.getMesh().getBoundsInParent();
                Bounds[] meshBounds = new Bounds[objects.length];
                double[][] direction = new double[objects.length][3];
                for (int i = 0; i < objects.length; i++) {
@@ -191,16 +190,41 @@ public class GraphicsAndWindowsTest extends Application {
                    double WindowSize = sceneWindow.getWindowSize();
                    // Reverse direction at bounds
                    for (int i = 0; i < objects.length; i++) {
                        direction[i][1] += 1;
                        double x = direction[i][0];
                        double y = direction[i][1];
                        double z = direction[i][2];
                        if (meshBounds[i].getMinX() + direction[i][0] < winLeftXBound || meshBounds[i].getMaxX() + direction[i][0]  > winLeftXBound + WindowSize) {

                            if (meshBounds[i].getMinX() + x < winLeftXBound) {
                                x = direction[i][0] + (winLeftXBound - (meshBounds[i].getMinX() + x));
                                direction[i][0] += 1;
                            } else {
                                x = direction[i][0] - (meshBounds[i].getMaxX() + direction[i][0] - (winLeftXBound + WindowSize));
                            }
                            direction[i][0] *= -1;
                            lastChanged = 1;

                        }
                        if (meshBounds[i].getMinY() + direction[i][1] < winTopYBound || meshBounds[i].getMaxY() + direction[i][1] > winTopYBound + WindowSize) {

                            if (meshBounds[i].getMinY() + y < winTopYBound) {
                                y = direction[i][1] + (winTopYBound - (meshBounds[i].getMinY() + y));
                                direction[i][1] += 1;
                            } else {
                                y = direction[i][1] - (meshBounds[i].getMaxY() + direction[i][1] - (winTopYBound + WindowSize));
                            }
                            direction[i][1] *= -1;
                            lastChanged = 2;
                        }
                        if (meshBounds[i].getMinZ() + direction[i][2] < 0 || meshBounds[i].getMaxZ() + direction[i][2] > WindowSize) {
                            if (meshBounds[i].getMinZ() + z < 0) {
                                z = direction[i][2] + (0 - (meshBounds[i].getMinZ() + z));
                                direction[i][2] += 1;
                            } else {
                                z = direction[i][2] - (meshBounds[i].getMaxZ() + direction[i][2] - (WindowSize));
                            }

                            direction[i][2] *= -1;
                            lastChanged = 3;
                        }
@@ -216,9 +240,9 @@ public class GraphicsAndWindowsTest extends Application {
                            default: System.out.println();
                        }
                    }*/
                        objects[i].updateTranslate();
                        objects[i].updateTranslate(x, y, z);
                        System.out.println(Arrays.toString(objects[i].getCentroid()));
                        objects[i].updateRays();
                        //objects[i].updateRays();
                    }
                    lastUpdate = now;
                }
+175 B (5.97 KiB)

File changed.

No diff preview for this file type.