Skip to content

Commit

Permalink
Adjusted particle damping & Added damp on impact
Browse files Browse the repository at this point in the history
Decreased the generel damping (need to be adjusted much more) and added
a impact damping - Energy loos by 20%.
  • Loading branch information
ThuCommix committed Oct 1, 2013
1 parent 055d964 commit 7643518
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Sharpex.GameLibrary/Framework/Physics/PhysicProvider.cs
Expand Up @@ -284,7 +284,7 @@ private Vector2 ParticleDamping(Vector2 velocity, float damping)
{
float xDamped;
float yDamped;
var dampingValue = damping / 10;
var dampingValue = damping / 15;
if (velocity.X > 0)
{
xDamped = velocity.X - dampingValue >= 0 ? velocity.X - dampingValue : 0;
Expand All @@ -304,6 +304,17 @@ private Vector2 ParticleDamping(Vector2 velocity, float damping)

return new Vector2(xDamped, yDamped);
}
/// <summary>
/// Damps the particle on impact.
/// </summary>
/// <param name="originVelocity">The Velocity.</param>
/// <returns>Damped Velocity</returns>
private Vector2 DampOnImpact(Vector2 originVelocity)
{
// lets say we loos 20% of power after impact
return new Vector2(originVelocity.X * 80 / 100, originVelocity.Y * 80 / 100);
}

/// <summary>
/// Returns the new velocity of two particles after an elastic impact.
/// </summary>
Expand Down Expand Up @@ -338,25 +349,31 @@ private Vector2[] ElasticImpact(Particle particle1, Particle particle2)
if (particle2.Mass/particle1.Mass > 10)
{
//only use reflection:
return new[] { -particle1.Velocity * particle1.Elasticity, particle2.Velocity};
particle1.Velocity = DampOnImpact(particle1.Velocity);
return new[] {-particle1.Velocity*particle1.Elasticity, particle2.Velocity};
}

//check if obj2.velocity = 0 and the mass of both objects are the same
//get min elasticity
var elasticity = MathHelper.Min(particle1.Elasticity, particle2.Elasticity);


//check if obj2.velocity = 0 and the mass of both objects are the same
//then velocity of obj1 = velocity of obj2, obj1.velocity = 0
if (particle2.Velocity == new Vector2(0, 0) && System.Math.Abs(particle1.Mass - particle2.Mass) < 0.01f)
{
return new[] {new Vector2(0, 0), particle1.Velocity};
}
var u1 = particle1.Velocity * particle1.Mass +
(particle2.Velocity * 2 - particle1.Velocity)*particle2.Mass/
var u1 = particle1.Velocity*particle1.Mass +
(particle2.Velocity*2 - particle1.Velocity)*particle2.Mass/
(particle1.Mass + particle2.Mass);
var u2 = particle2.Velocity * particle2.Mass +
var u2 = particle2.Velocity*particle2.Mass +
(particle1.Velocity*2 - particle2.Velocity)*particle1.Mass/
(particle1.Mass + particle2.Mass);
return new[] { (u1 * elasticity), (u2 * elasticity)};
var velocity1 = DampOnImpact(u1*elasticity);
var velocity2 = DampOnImpact(u2*elasticity);
return new[] {velocity1, velocity2};
}

/// <summary>
/// Returns the new velocity after a non elastic impact.
/// </summary>
Expand Down

0 comments on commit 7643518

Please sign in to comment.