Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Vector2f doCollideEx(Box2D a, Box2D b)
- {
- Vector2f[] edge_normals = a.getEdgeNormals();
- Projection2D p1,p2;
- float overlap = Float.MAX_VALUE;
- Vector2f axis = new Vector2f(0.0f,0.0f);
- for(int i=0;i<=3;i++)
- {
- p1 = a.projectOnto(edge_normals[i]);
- p2 = b.projectOnto(edge_normals[i]);
- if(!p1.overlaps(p2))
- return new Vector2f(0.0f,0.0f);
- else
- {
- if(p1.getOverlap(p2)<overlap)
- {
- overlap = p1.getOverlap(p2);
- axis = edge_normals[i];
- }
- }
- }
- for(int i=0;i<=3;i++)
- {
- p1 = a.projectOnto(edge_normals[i]);
- p2 = b.projectOnto(edge_normals[i]);
- if(!p1.overlaps(p2))
- return new Vector2f(0.0f,0.0f);
- else
- {
- if(p1.getOverlap(p2)<overlap)
- {
- overlap = p1.getOverlap(p2);
- axis = edge_normals[i];
- }
- }
- }
- return Vector2f.multiply(axis,overlap);
- }
Advertisement
Add Comment
Please, Sign In to add comment