Пример #1
0
 public override void OnLink(Entity Entity)
 {
     Entity.RegisterLinkHandler<PhysicsComponent>(delegate(PhysicsComponent Physics)
     {
         this._Physics = Physics;
     });
 }
Пример #2
0
        /// <summary>
        /// Responds (by correcting positions and velocities) to the collision of two driftoids.
        /// </summary>
        internal static void _CollisionResponse(PhysicsComponent A, PhysicsComponent B, Vector Difference, double Distance, double Factor)
        {
            double trad = A.Radius + B.Radius;
            Vector ncol = Difference * (1.0 / Difference.Length);
            double pen = trad - Distance;
            double ima = 1.0 / A._Mass;
            double imb = 1.0 / B._Mass;
            Vector sep = ncol * (pen / (ima + imb)) * Factor;
            A._MotionState.Position -= sep * ima;
            B._MotionState.Position += sep * imb;

            Vector vcol = B._MotionState.Velocity - A._MotionState.Velocity;
            double impact = Vector.Dot(vcol, ncol);
            if (impact < 0.0)
            {
                double cor = 0.5;
                double j = -(1.0f + cor) * (impact) / (ima + imb);
                Vector impulse = ncol * j;
                A._MotionState.Velocity -= impulse * ima;
                B._MotionState.Velocity += impulse * imb;
            }
        }