private Vec2 CalculatePointGravity(PhysicsObject obj) { var forces = new Vec2(0, 0); if (obj.Locked) { return(forces); } foreach (var gpt in ListGravityObjects) { var diff = gpt.Center - obj.Center; PhysMath.RoundToZero(ref diff, 5F); //apply inverse square law var falloffMultiplier = gpt.Mass / diff.LengthSquared; diff.X = (int)diff.X == 0 ? 0 : diff.X * falloffMultiplier; diff.Y = (int)diff.Y == 0 ? 0 : diff.Y * falloffMultiplier; if (diff.Length > .005F) { forces += diff; } } return(forces); }
public static PhysicsObject CreateStaticBox(Vec2 start, Vec2 end, bool locked, aShader shader, float mass) { var oAabb = new AABB { Min = new Vec2 { X = start.X, Y = start.Y }, Max = new Vec2 { X = end.X, Y = end.Y } }; PhysMath.CorrectBoundingBox(ref oAabb); var obj = new PhysicsObject(oAabb, PhysicsObject.Type.Box, .95F, locked, shader, mass); ListStaticObjects.Add(obj); return(obj); }
public static PhysicsObject CreateStaticCircle(Vec2 loc, int radius, float restitution, bool locked, aShader shader) { var oAabb = new AABB { Min = new Vec2 { X = loc.X - radius, Y = loc.Y - radius }, Max = new Vec2 { X = loc.X + radius, Y = loc.Y + radius } }; PhysMath.CorrectBoundingBox(ref oAabb); var obj = new PhysicsObject(oAabb, PhysicsObject.Type.Circle, restitution, locked, shader); ListStaticObjects.Add(obj); return(obj); }