public BoxCollider(FixedVector2 _position, FixedVector2 _positionOffset, FixedVector2 _size) { positionOffset = _positionOffset; bounds = new BoundingBox(_position + positionOffset, _size); edges = new FixedLine2[] { new FixedLine2( bounds.min, new FixedVector2(bounds.max.x, bounds.min.y) ), new FixedLine2( new FixedVector2(bounds.min.x, bounds.max.y), bounds.max ), new FixedLine2( bounds.min, new FixedVector2(bounds.min.x, bounds.max.y) ), new FixedLine2( new FixedVector2(bounds.max.x, bounds.min.y), bounds.max ) }; }
public BoxCollider(FixedVector2 position, FixedVector2 halfExtents) { bounds = new BoundingBox(position, halfExtents); edges = new FixedLine2[] { new FixedLine2( bounds.min, new FixedVector2(bounds.max.x, bounds.min.y) ), new FixedLine2( new FixedVector2(bounds.min.x, bounds.max.y), bounds.max ), new FixedLine2( bounds.min, new FixedVector2(bounds.min.x, bounds.max.y) ), new FixedLine2( new FixedVector2(bounds.max.x, bounds.min.y), bounds.max ) }; }
public static bool CheckIntersection(FixedVector2 origin, FixedVector2 length, out FixedVector2 intersection, Determinism.BoxCollider collider) { intersection = FixedVector2.NAN; FixedLine2 l = new FixedLine2(origin, origin + length); if (l.isHorizontal) { for (int i = 2; i < 4; i++) { // if (FixedMath.Min (l.start.y, l.end.y) > collider.edges[i].start.y) continue; // if (FixedMath.Max (l.start.y, l.end.y) < collider.edges[i].start.y) continue; // if (FixedLine2.LineIntersection (l, collider.edges[i], out intersection)) // return true; if (FixedLine2.AAOrthogonalLineIntersection(l, collider.edges[i], out intersection)) { return(true); } } } if (l.isVertical) { for (int i = 0; i < 2; i++) { //if (edge.isVertical) continue; // if (FixedMath.Min (l.start.x, l.end.x) > collider.edges[i].start.x) continue; // if (FixedMath.Max (l.start.x, l.end.x) < collider.edges[i].start.x) continue; // if (FixedLine2.LineIntersection (l, collider.edges[i], out intersection)) // return true; if (FixedLine2.AAOrthogonalLineIntersection(collider.edges[i], l, out intersection)) { return(true); } } } return(false); intersection = FixedVector2.NAN; return(FixedVector2.LineBoxIntersection(collider.broadBounds, origin, length, out intersection)); }
public static bool CheckIntersection(FixedVector2 origin, FixedVector2 length, out FixedVector2 intersection, RectilinearCollider collider) { intersection = FixedVector2.NAN; FixedLine2 l = new FixedLine2(origin, origin + length); if (l.isHorizontal) { foreach (FixedLine2 edge in collider.vEdges) { //if (FixedMath.Min (l.start.y, l.end.y) > edge.start.y) continue; //if (FixedMath.Max (l.start.y, l.end.y) < edge.start.y) continue; if (FixedLine2.AAOrthogonalLineIntersection(l, edge, out intersection)) { return(true); } // // if (FixedLine2.LineIntersection (l, edge, out intersection)) { // return true; // } } } if (l.isVertical) { foreach (FixedLine2 edge in collider.hEdges) { //if (edge.isVertical) continue; //if (FixedMath.Min (l.start.x, l.end.x) > edge.start.x) continue; //if (FixedMath.Max (l.start.x, l.end.x) < edge.start.x) continue; if (FixedLine2.AAOrthogonalLineIntersection(edge, l, out intersection)) { return(true); } // if (FixedLine2.LineIntersection (l, edge, out intersection)) { // return true; // } } } return(false); }
public static bool CheckIntersection(FixedVector2 origin, FixedVector2 length, out FixedVector2 intersection, PolygonCollider collider) { intersection = FixedVector2.NAN; FixedLine2 l = new FixedLine2(origin, origin + length); foreach (FixedLine2 edge in collider.edges) { //if (edge.isVertical) continue; //if (FixedMath.Min (l.start.y, l.end.y) > edge.start.y) continue; //if (FixedMath.Max (l.start.y, l.end.y) < edge.start.y) continue; if (FixedLine2.LineIntersection(l, edge, out intersection)) { return(true); } } return(false); }
public void UpdateEdges() { edges = new FixedLine2[] { new FixedLine2( bounds.min, new FixedVector2(bounds.max.x, bounds.min.y) ), new FixedLine2( new FixedVector2(bounds.min.x, bounds.max.y), bounds.max ), new FixedLine2( bounds.min, new FixedVector2(bounds.min.x, bounds.max.y) ), new FixedLine2( new FixedVector2(bounds.max.x, bounds.min.y), bounds.max ) }; }
protected override void Execute(List <LogicEntity> entities) { foreach (LogicEntity e in entities) { horizontalHit = FixedVector2.NAN; verticallHit = FixedVector2.NAN; r = e.rayCastCollision.value; c = e.collider.value; left = right = up = down = -1; int direction = e.direction.value; long rayLength = e.move.target.x.Abs() + r.skinWidth; if (e.move.target.x.Abs() < r.skinWidth) { rayLength = r.skinWidth; } for (int i = 0; i < r.horizontalRayCount; i++) { FixedVector2 origin = (direction == -1) ? c.broadBounds.bottomLeft : c.broadBounds.bottomRight; origin += FixedVector2.UP * (r.horizontalRaySpacing * i); FixedVector2 hit; FixedVector2 end = FixedVector2.RIGHT * (rayLength * direction); l = new FixedLine2(origin, origin + end); int otherId = -1; if (RayCastSystem.Check(origin, end, out hit, e.id.value, c.check, out otherId)) { if (direction < 0) { left = otherId; } else { right = otherId; } long distance = (hit - origin).magnitude; if (distance > minDistance) { distance -= minDistance; } else { distance = 0; } e.move.target.x = distance * direction; horizontalHit = hit; } } direction = e.move.target.y.Sign(); rayLength = e.move.target.y.Abs() + r.skinWidth; for (int i = 0; i < r.verticalRayCount; i++) { FixedVector2 origin = (direction == -1) ? c.broadBounds.bottomLeft : c.broadBounds.topLeft; origin.x += e.move.target.x; origin += FixedVector2.RIGHT * (r.verticalRaySpacing * i); FixedVector2 hit; FixedVector2 end = FixedVector2.UP * (rayLength * direction); l = new FixedLine2(origin, origin + end); int otherId = -1; if (RayCastSystem.Check(origin, end, out hit, e.id.value, c.check, out otherId)) { if (direction < 0) { down = otherId; } else { up = otherId; } long distance = (hit - origin).magnitude; if (distance > minDistance) { distance -= minDistance; } else { distance = 0; } e.move.target.y = distance * direction; verticallHit = hit; } } r = null; c = null; e.ReplaceLastPosition(e.position.value); e.ReplacePosition(e.position.value + e.move.target); e.collider.value.MoveCollider(e.position.value); e.RemoveMove(); RaycastCollisionInfo info = new RaycastCollisionInfo(left, right, up, down, horizontalHit, verticallHit); if (e.hasCollisionInfo) { info.RecordLastPreviousCollision( e.collisionInfo.value.leftID, e.collisionInfo.value.rightID, e.collisionInfo.value.upID, e.collisionInfo.value.downID ); } e.ReplaceCollisionInfo(info); } }