Commit 57b46b9c authored by ronan's avatar ronan
Browse files

Add fast collision detection

parent fbfe7d9f
Pipeline #2304 passed with stage
in 1 minute and 1 second
......@@ -17,7 +17,9 @@ public class Form implements Serializable, Cloneable
protected ArrayList<Vector2D> points;
protected float radius;
protected float xMin, xMax, yMin, yMax;
protected float xMax, yMax;
protected Vector2D c1;
protected ArrayList<Vector2D> savedVectorsLocal;
/**
......@@ -37,6 +39,7 @@ public class Form implements Serializable, Cloneable
flipH = false;
flipV = false;
radius = 0;
c1 = new Vector2D();
orientation = Matrix3.orientation(omega, scale, flipH, flipV,
new Vector2D());
......@@ -50,6 +53,7 @@ public class Form implements Serializable, Cloneable
scale = 1f;
flipH = false;
flipV = false;
c1 = new Vector2D();
orientation = Matrix3.orientation(omega, scale, flipH, flipV,
new Vector2D());
......@@ -76,10 +80,9 @@ public class Form implements Serializable, Cloneable
this.flipV = form.getFlipV();
this.radius = form.getOriginalRadius();
this.xMin = form.getXMinRel();
this.xMax = form.getXMaxRel();
this.yMin = form.getYMinRel();
this.yMax = form.getYMaxRel();
this.c1 = form.getC1();
orientation = Matrix3.orientation(omega, scale, flipH, flipV,
form.getCenter());
......@@ -288,6 +291,7 @@ public class Form implements Serializable, Cloneable
{
Vector2D v = points.get(0).getRotatedRadians(omega);
float xMin, yMin;
xMin = yMin = v.x;
xMax = yMax = v.y;
......@@ -339,6 +343,10 @@ public class Form implements Serializable, Cloneable
yMin *= scale;
yMax *= scale;
}
c1.set((xMax + xMin)/2, (yMax + yMin)/2);
xMax -= c1.x;
yMax -= c1.y;
}
/**
......@@ -350,16 +358,6 @@ public class Form implements Serializable, Cloneable
return savedVectorsLocal;
}
/**
* Call update Bound first
* Get saved x Min in a relative coordinate
* With scale transformation
* @return xMin
*/
public float getXMinRel()
{
return xMin;
}
/**
* Call update Bound first
......@@ -372,17 +370,6 @@ public class Form implements Serializable, Cloneable
return xMax;
}
/**
* Call update Bound first
* Get saved y Min in a relative coordinate
* With scale transformation
* @return xMin
*/
public float getYMinRel()
{
return yMin;
}
/**
* Call update Bound first
* Get saved y Max in a relative coordinate
......@@ -394,6 +381,12 @@ public class Form implements Serializable, Cloneable
return yMax;
}
/**
* Get center of bound
* @return c1
*/
public Vector2D getC1() { return c1; }
/**
* return min and max projection of the polygon on the vector axis
......
......@@ -5,11 +5,13 @@ import org.cora.maths.FloatA;
import org.cora.maths.Vector2D;
import org.cora.maths.sRectangle;
import java.util.Vector;
/**
* Created by ronan-h on 11/06/16.
*/
/**
* Optimised collisions detection for special collisions
*/
public class CollisionDetectorFast
{
/**
......@@ -261,7 +263,8 @@ public class CollisionDetectorFast
public static boolean isColliding(sRectangle A, sRectangle B, Vector2D VA, Vector2D VB,
Vector2D push, FloatA t)
{
return isColliding(A.getXMinRel(), A.getXMaxRel(), A.getYMinRel(), A.getYMaxRel(), )
return isColliding(A.getXMaxRel(), A.getYMaxRel(), B.getXMaxRel(), B.getYMaxRel(),
A.getC1(), B.getC1(), VA, VB, push, t);
}
}
\ No newline at end of file
......@@ -118,9 +118,7 @@ public class sRectangle extends Form
@Override
public void updateBound()
{
xMin = points.get(0).x * scale;
xMax = points.get(0).y * scale;
yMin = points.get(2).x * scale;
yMax = points.get(2).y * scale;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment