Nez.Portable/ECS/Components/Renderables/Particles/Particle.cs
/// <summary>
/// given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision
/// response.
/// </summary>
/// <param name="relativeVelocity">Relative velocity.</param>
/// <param name="minimumTranslationVector">Minimum translation vector.</param>
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision
response.
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision response .
void calculateCollisionResponseVelocity(float friction, float elasticity, ref Vector2 minimumTranslationVector)
        {
            var inverseMTV = minimumTranslationVector * -1f;
            Vector2 normal;
            Vector2.Normalize(ref inverseMTV, out normal);
            float n;
            Vector2.Dot(ref _velocity, ref normal, out n);
            var normalVelocityComponent = normal * n;
            var tangentialVelocityComponent = _velocity - normalVelocityComponent;
            if (n > 0.0f)
                normalVelocityComponent = Vector2.Zero;
            var responseVelocity =
                -(1.0f + elasticity) * normalVelocityComponent - friction * tangentialVelocityComponent;
            _velocity += responseVelocity;
        }
void calculateCollisionResponseVelocity ( float friction , float elasticity , ref Vector2 minimumTranslationVector ) { var inverseMTV = minimumTranslationVector * - 1f ; Vector2 normal ; Vector2 . Normalize ( ref inverseMTV , out normal ) ; float n ; Vector2 . Dot ( ref _velocity , ref normal , out n ) ; var normalVelocityComponent = normal * n ; var tangentialVelocityComponent = _velocity - normalVelocityComponent ; if ( n > 0.0f ) normalVelocityComponent = Vector2 . Zero ; var responseVelocity = - ( 1.0f + elasticity ) * normalVelocityComponent - friction * tangentialVelocityComponent ; _velocity += responseVelocity ; }
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision
response.
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision response .
// first, we get the normalized MTV in the opposite direction: the surface normal // the velocity is decomposed along the normal of the collision and the plane of collision. // The elasticity will affect the response along the normal (normalVelocityComponent) and the friction will affect // the tangential component of the velocity (tangentialVelocityComponent) // elasticity affects the normal component of the velocity and friction affects the tangential component
friction
float
elasticity
float
Vector2
ref
relativeVelocity
None
minimumTranslationVector
Minimum translation vector.
Minimum translation vector .