Commit 02d7b501 authored by Timothy  Borunov's avatar Timothy Borunov
Browse files

Fixed collision bug

parent 742c17ee
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
package Graph;
import org.apache.commons.math3.ml.clustering.Cluster;
import org.apache.commons.math3.ml.clustering.Clusterable;

import java.io.Serializable;
import java.util.Arrays;

/**
+59 −17
Original line number Diff line number Diff line
@@ -177,35 +177,55 @@ public class MovingObject {
            deformDir[axis*2+side].deformed = true;
            counter++;
            for (Integer k : deformDir[axis*2 + side].layer5) {
                if (side == 0) {
                    points[k] += (float) deformDir[axis * 2 + side].deformation;
                } else {
                    points[k] -= (float) deformDir[axis * 2 + side].deformation;
                }
            }
        }
        newSpeed -= decrement;
        if (newSpeed > 0) {
            counter++;
            for (Integer k : deformDir[axis*2 + side].layer4) {
                if (side == 0) {
                    points[k] += (float) deformDir[axis * 2 + side].deformation;
                } else {
                    points[k] -= (float) deformDir[axis * 2 + side].deformation;
                }
            }
        }
        newSpeed -= decrement;
        if (newSpeed > 0) {
            counter++;
            for (Integer k : deformDir[axis*2 + side].layer3) {
                if (side == 0) {
                    points[k] += (float) deformDir[axis * 2 + side].deformation;
                } else {
                    points[k] -= (float) deformDir[axis * 2 + side].deformation;
                }
            }
        }
        newSpeed -= decrement;
        if (newSpeed > 0) {
            counter++;
            for (Integer k : deformDir[axis*2 + side].layer2) {
                if (side == 0) {
                    points[k] += (float) deformDir[axis * 2 + side].deformation;
                } else {
                    points[k] -= (float) deformDir[axis * 2 + side].deformation;
                }
            }
        }
        newSpeed -= decrement;
        if (newSpeed > 0) {
            counter++;
            for (Integer k : deformDir[axis*2 + side].layer1) {
                if (side == 0) {
                    points[k] += (float) deformDir[axis * 2 + side].deformation;
                } else {
                    points[k] -= (float) deformDir[axis * 2 + side].deformation;
                }
            }
        }
        deformDir[axis*2+side].counter = counter;
@@ -245,22 +265,22 @@ public class MovingObject {
                side2 = meshBounds.getMaxZ();
            }
        }
        Deformation newDeform = new Deformation(half / 5.0);
        Deformation newDeform = new Deformation(half / 5.0, side);

        for (int j = axis; j < points.length; j += 3) {
            if ((points[j] + trans - side2) < half) {
            if (Math.abs(points[j] + trans - side2) < half) {
                newDeform.layer1.add(j);
                //points[j] += newDeform.deformation;
                if ((points[j] + trans - side2) < (4 * half / 5.0)) {
                if (Math.abs(points[j] + trans - side2) < (4 * half / 5.0)) {
                    newDeform.layer2.add(j);
                    //points[j] += newDeform.deformation;
                    if ((points[j] + trans - side2) < (3 * half/5.0)) {
                    if (Math.abs(points[j] + trans - side2) < (3 * half/5.0)) {
                        newDeform.layer3.add(j);
                        //points[j] += newDeform.deformation;
                        if ((points[j] + trans - side2) < (2 * half/5.0)) {
                        if (Math.abs(points[j] + trans - side2) < (2 * half/5.0)) {
                            newDeform.layer4.add(j);
                            //points[j] += newDeform.deformation;
                            if ((points[j] + trans - side2) < (half/5.0)) {
                            if (Math.abs(points[j] + trans - side2) < (half/5.0)) {
                                newDeform.layer5.add(j);
                                //points[j] += newDeform.deformation;
                            }
@@ -286,27 +306,47 @@ public class MovingObject {
                    System.out.println("Undeformed = " + d.counter);
                    if(d.counter == 5) {
                        for (Integer k : d.layer1) {
                            if (d.side == 0) {
                                points[k] -= (float) d.deformation;
                            } else {
                                points[k] += (float) d.deformation;
                            }
                        }
                        d.counter--;
                    } else if (d.counter == 4) {
                        for (Integer k : d.layer2) {
                            if (d.side == 0) {
                                points[k] -= (float) d.deformation;
                            } else {
                                points[k] += (float) d.deformation;
                            }
                        }
                        d.counter--;
                    } else if (d.counter == 3) {
                        for (Integer k : d.layer3) {
                            if (d.side == 0) {
                                points[k] -= (float) d.deformation;
                            } else {
                                points[k] += (float) d.deformation;
                            }
                        }
                        d.counter--;
                    } else if (d.counter == 2) {
                        for (Integer k : d.layer4) {
                            if (d.side == 0) {
                                points[k] -= (float) d.deformation;
                            } else {
                                points[k] += (float) d.deformation;
                            }
                        }
                        d.counter--;
                    } else if (d.counter == 1) {
                        for (Integer k : d.layer5) {
                            if (d.side == 0) {
                                points[k] -= (float) d.deformation;
                            } else {
                                points[k] += (float) d.deformation;
                            }
                        }
                        d.counter--;
                        d.deformed = false;
@@ -327,7 +367,7 @@ public class MovingObject {
         * Constructs a deformation with a specified magnitude.
         * @param deform Magnitude of deformation.
         */
        Deformation(double deform) {
        Deformation(double deform, int s) {
            deformed = false;
            layer1 = new HashSet<>();
            layer2 = new HashSet<>();
@@ -336,7 +376,9 @@ public class MovingObject {
            layer5 = new HashSet<>();
            counter = 0;
            deformation = deform;
            side = s;
        }
        public int side;

        public boolean deformed;
        public int counter;
+2 −2
Original line number Diff line number Diff line
@@ -417,7 +417,7 @@ public class GraphicsAndWindowsTest extends Application {
                            if (meshBounds[i].getMinX() + x < winLeftXBound) {
                                x = direction[i][0] + (winLeftXBound - (meshBounds[i].getMinX() + x));
                                objects[i].deformShape(0,0,direction[i][0]);
                                direction[i][0] += 1;
                                //direction[i][0] += 1;
                            } else {
                                x = direction[i][0] - (meshBounds[i].getMaxX() + direction[i][0] - (winLeftXBound + WindowSize));
                                objects[i].deformShape(1,0,direction[i][0]);
@@ -448,7 +448,7 @@ public class GraphicsAndWindowsTest extends Application {
                            if (meshBounds[i].getMinZ() + z < 0) {
                                z = direction[i][2] + (0 - (meshBounds[i].getMinZ() + z));
                                objects[i].deformShape(0,2,direction[i][2]);
                                direction[i][2] += 1;
                                //direction[i][2] += 1;
                            } else {
                                z = direction[i][2] - (meshBounds[i].getMaxZ() + direction[i][2] - (WindowSize));
                                objects[i].deformShape(1,2,direction[i][2]);