Пример #1
0
        public static RigidBody UpdatePhysics(RigidBody body, Time.TimeEventArgs t)
        {
            if (body.AllowMovement)
            {
                body.Drag         = SolveDrag(body);
                body.Force        = SolveForce(body);
                body.Acceleration = body.Force / body.Mass;
                body.Velocity    += body.Acceleration * t.Delta;

                var movement = (body.Velocity + body.InputVelocity) * t.Delta;
                body.Transform.Translate(offset: movement, relativeTo: Space.World);
            }

            return(body);
        }
Пример #2
0
 private void RenderUpdated(object sender, Time.TimeEventArgs e)
 {
     this.Dispatcher.Invoke(delegate {
         ForceLabel.Content         = "Force: " + Entity.Body.Force;
         ExternalForceLabel.Content = "External Force: " + Entity.Body.ExternalForces;
         InputVelocityLabel.Content = "Input Velocity: " + Entity.Body.InputVelocity;
         WeightLabel.Content        = "Weight: " + Entity.Body.Weight;
         AccelerationLabel.Content  = "Acceleration: " + Entity.Body.Acceleration;
         VelocityLabel.Content      = "Velocity: " + Entity.Body.Velocity;
         PositionLabel.Content      = "Position: " + Entity.Body.Position;
         DragLabel.Content          = "Drag: " + Entity.Body.Drag;
         MassLabel.Content          = "Mass: " + Entity.Body.Mass;
         DeltaTime.Content          = "dt: " + e.Delta + "ms";
         Performance.Content        = "Performance: " + Math.Floor(e.Delta * 3600) + " calculations per second";
     });
 }
Пример #3
0
        private void RenderUpdated(object sender, Time.TimeEventArgs e)
        {
            this.Dispatcher.Invoke(delegate {
                var scale = Game.Scene.Scale;

                Canvas.SetLeft(this, Body.Position.X * scale);
                Canvas.SetTop(this, -Body.Position.Y * scale);

                Body.Transform.Resize(new Vector(this.ActualWidth, this.ActualHeight, 50));

                var moveX = Input.Get(Engine.Input.InputType.Horizontal);
                var moveY = Input.Get(Engine.Input.InputType.Jump);
                var speed = 5;

                Body.InputVelocity.X = moveX;
                Body.InputVelocity  *= speed;

                if (moveY > 0 && !IsJumping)
                {
                    IsJumping      = true;
                    Body.Velocity += (Vector.Up * 15);
                }

                if (Body.Position.Y - Body.Size.Y / scale - 1.5f + 0.001f <= -Application.Current.MainWindow.ActualHeight / scale)
                {
                    Body.AllowGravity = false;
                    Body.Position.Y   = (float)-Application.Current.MainWindow.ActualHeight / scale + Body.Size.Y / scale + 1.5f;
                    Body.Force        = Vector.Zero;
                    Body.Acceleration = Vector.Zero;
                    Body.Velocity     = Vector.Zero;
                    IsJumping         = false;
                }
                else
                {
                    Body.AllowGravity = true;
                }
            });
        }
Пример #4
0
 private void PhysicsUpdated(object sender, Time.TimeEventArgs t) =>
 RigidBodyHelper.UpdatePhysics(this, t);