public static void UpdateKinematicsWithGravity(this IPhysObject obj, double dt, Vector gravity) { var actualAcceleration = obj.Acceleration + (obj.Mass == 0 ? Vector.Zero : gravity); obj.Velocity += actualAcceleration * dt; obj.Cords += obj.Velocity * dt; }
public void IntersectsWith_IntersectingWithObject_ShouldReturnExpectedAnswer(Landscape landscape, IPhysObject obj, bool expected) { var sut = landscape.IntersectsWith(obj); sut.Should().Be(expected); }
private static bool IsRectangleObjectsIntersectsold(this IPhysObject obj, IPhysObject otherObj) { if (ReferenceEquals(obj, otherObj)) { return(false); } if (otherObj == null) { return(false); } return(IsSegmentIntersects(obj.Cords.X, obj.Size.Width, otherObj.Cords.X, otherObj.Size.Width) && IsSegmentIntersects(obj.Cords.Y, obj.Size.Height, otherObj.Cords.Y, otherObj.Size.Height)); }
private static double[] GetTops(IPhysObject obj) { var x11 = obj.Cords.X; var y11 = obj.Cords.Y; var x12 = x11 + obj.Size.Width * Math.Cos(obj.Direction.Angle) - obj.Size.Height * Math.Sin(obj.Direction.Angle); var y12 = y11 + obj.Size.Width * Math.Sin(obj.Direction.Angle) + obj.Size.Height * Math.Cos(obj.Direction.Angle); var x13 = x11 + obj.Size.Width * Math.Cos(obj.Direction.Angle); var y13 = y11 + obj.Size.Width * Math.Sin(obj.Direction.Angle); var x14 = x11 - obj.Size.Height * Math.Sin(obj.Direction.Angle); var y14 = y11 + obj.Size.Height * Math.Cos(obj.Direction.Angle); return(new double[] { x11, y11, x12, y12, x13, y13, x14, y14 }); }
public bool IntersectsWith(IPhysObject obj) { if (ReferenceEquals(this, obj)) { return(false); } if (ReferenceEquals(obj, null)) { return(false); } if (obj is Landscape) { return(obj.IntersectsWith(this)); } return(this.IsRectangleObjectsIntersects(obj)); }
public static bool IsRectangleObjectsIntersects(this IPhysObject obj, IPhysObject otherObj) { if (ReferenceEquals(obj, otherObj)) { return(false); } if (otherObj == null) { return(false); } if (!IsRectangleObjectsIntersectsold(obj, otherObj)) { return(false); } var firstRectangleTops = GetTops(obj); var secondRectangleTops = GetTops(otherObj); var firstRectangleSides = GetSides(firstRectangleTops); var secondRectangleSides = GetSides(secondRectangleTops); foreach (var firstSide in firstRectangleSides) { foreach (var secondSide in secondRectangleSides) { if (AreLinesIntersect(firstSide.Item1, firstSide.Item2, firstSide.Item3, firstSide.Item4, secondSide.Item1, secondSide.Item2, secondSide.Item3, secondSide.Item4)) { return(true); } } } return(false); }
private static void UpdateObject(IPhysObject obj, double dt) { obj.UpdateKinematicsWithGravity(dt, Vector.Zero); obj.Update(dt); }