/// <inheritdoc /> public void Draw(Window window, Camera camera) { ScreenPoint pos = camera.WorldToViewportPosition(Position.PixelTranslate(Rect.BottomLeft)); int w = HMath.RoundToInt(Rect.Extents.X * 2); int h = HMath.RoundToInt(Rect.Extents.Y * 2); ScreenRect rect = new ScreenRect(pos.X, pos.Y, w, h); window.DrawRect(rect, Fill, Color); }
/// <inheritdoc /> public void Draw(Window window, Camera camera) { ScreenPoint[] points = new ScreenPoint[Polygon.Points.Count]; for (int i = 0; i < points.Length; i++) { WorldPoint pointPos = Position.PixelTranslate(Polygon.Points[i]); points[i] = camera.WorldToViewportPosition(pointPos); } window.DrawPolygon(points, Color); }
IPhysicsBody IPhysicsBody.CollisionPass(IEnumerable <CollisionData> collisions) { WorldPoint newPosition = Position; Vector2 newVelocity = Velocity; foreach (CollisionData collision in collisions) { newPosition = newPosition.PixelTranslate(collision.MTV); newVelocity = GetMomentumChange(this, collision) + GetFriction(this, collision); } return(new RigidBody(this, position: newPosition, velocity: newVelocity)); }
IPhysicsBody IPhysicsBody.ImpulsePass(Vector2 gravity, float deltaT) { WorldPoint secOrigin = new WorldPoint(Position.Sector, Vector2.Zero); Vector2 f = Forces + gravity; Vector2 a = GetAccel(f, Mass); Vector2 p = Position.PixelDistance(secOrigin); Vector2 newP = GetNewPosition(p, a, Velocity, deltaT); Vector2 newVelocity = GetNewVelocity(a, Velocity, deltaT); WorldPoint newPosition = secOrigin.PixelTranslate(newP); return(new RigidBody(this, position: newPosition, velocity: newVelocity, forces: Vector2.Zero)); }