public static Vector2f GetEjectingVector(AABB first, AABB second) { var right = second.Right - first.Left + 1; var left = second.Left - first.Right - 1; var up = second.Top - first.Bottom - 1; var down = second.Bottom - first.Top + 1; var dx = right * right > left * left ? left : right; var dy = down * down > up * up ? up : down; if (dx * dx > dy * dy) dx = 0; else dy = 0; return new Vector2f(dx, dy); }
public PhysicalModel(Vector2f position, Vector2f size, double weight, bool isSolid, bool isStatic) { Collider = new AABB(position, size); Incircle = new RoundShape(position + size / 2, Math.Min(Size.X, Size.Y) / 2); Circumcircle = new RoundShape(position + size / 2, size.Length() / 2); Position = position; Velocity = new Vector2f(); Rotation = new Vector2f(1, 0); IsSolid = isSolid; IsStatic = isStatic; ColliderOffset = new Vector2f(); Weight = weight; }
public bool Intersects(AABB collider) { bool verticalIntersect = this.Top < collider.Bottom && this.Bottom > collider.Top; bool horizontalIntersect = this.Left < collider.Right && this.Right > collider.Left; return verticalIntersect && horizontalIntersect; }