public void UpdateCollisionMap(Drag3D cube) { int ID = cube.gameObject.GetInstanceID(); collisionNote[ID].Clear(); for (int p = 0; p < cubes.Length; p++) { if (cubes[p].gameObject.GetInstanceID() != ID) { cube.GetBottomVertices(out vertices_a); cubes[p].GetBottomVertices(out vertices_b); if (MiscFunc.BoxesColide2D(vertices_a, vertices_b)) { collisionNote[ID].Add(cubes[p].gameObject.GetInstanceID()); if (!collisionNote[cubes[p].gameObject.GetInstanceID()].Contains(ID)) { collisionNote[cubes[p].gameObject.GetInstanceID()].Add(ID); } } /* If did not colide and was previosuly colided clear the colision Note */ else if (collisionNote[cubes[p].gameObject.GetInstanceID()].Contains(ID)) { collisionNote[cubes[p].gameObject.GetInstanceID()].Remove(ID); } } } }
public bool WouldBoxColide(BoxJSON cube) { /* Check if this new hypothetical box would colide */ /* This new box is not placed in the world yet, so we need to obtain the vertices positon in a new way */ Vector2[] vertices = new Vector2[4]; /* Vertices 0 and 3 we can know straigh away since they are on the dragline */ vertices[0] = (draglines.points[cube.cil] + (draglines.points[cube.cil + 1] - draglines.points[cube.cil]) * cube.cpl).to2DwoY(); vertices[3] = (draglines.points[cube.cir] + (draglines.points[cube.cir + 1] - draglines.points[cube.cir]) * cube.cpr).to2DwoY(); /* Calculate the remaning ones */ Vector2 normal = (vertices[0] - vertices[3]).PerpClockWise(); vertices[1] = vertices[0] + (-normal.normalized) * cube.actual_depth; vertices[2] = vertices[3] + (-normal.normalized) * cube.actual_depth; vertices[0] = SG.transform.TransformPoint(vertices[0].to3DwY(0)).to2DwoY(); vertices[1] = SG.transform.TransformPoint(vertices[1].to3DwY(0)).to2DwoY(); vertices[2] = SG.transform.TransformPoint(vertices[2].to3DwY(0)).to2DwoY(); vertices[3] = SG.transform.TransformPoint(vertices[3].to3DwY(0)).to2DwoY(); /* Use the shelf transform to get world coordinates */ for (int i = 0; i < cubes.Length; i++) { Vector2[] other_vertices; cubes[i].GetBottomVertices(out other_vertices); if (MiscFunc.BoxesColide2D(vertices, other_vertices)) { return(true); } } return(false); }