public ApplyForce ( System.Vector2 force, System.Vector2 point ) : void | ||
force | System.Vector2 | The world force vector, usually in Newtons (N). |
point | System.Vector2 | The world position of the point of application. |
return | void |
/// <summary> /// Add a spring force /// </summary> void AddSpringForce(Body bA, Vec2 localA, Body bB, Vec2 localB, float k, float friction, float desiredDist) { Vec2 pA = bA.GetWorldPoint(localA); Vec2 pB = bB.GetWorldPoint(localB); Vec2 diff = pB - pA; //Find velocities of attach points Vec2 vA = bA.GetLinearVelocity() - Vec2.Cross(bA.GetWorldVector(localA), bA.GetAngularVelocity()); Vec2 vB = bB.GetLinearVelocity() - Vec2.Cross(bB.GetWorldVector(localB), bB.GetAngularVelocity()); Vec2 vdiff = vB - vA; float dx = diff.Normalize(); //normalizes diff and puts length into dx float vrel = vdiff.X * diff.X + vdiff.Y * diff.Y; float forceMag = -k * (dx - desiredDist) - friction * vrel; diff *= forceMag; // diff *= forceMag bB.ApplyForce(diff, bA.GetWorldPoint(localA)); diff *= -1.0f; bA.ApplyForce(diff, bB.GetWorldPoint(localB)); }
void killWheelOrthogonalVelocity(Body hull, Body wheel) { var p_hull = hull.GetPosition(); var p_wheel = wheel.GetPosition(); var velocity = wheel.GetLinearVelocityFromLocalPoint(Vec2.Zero); var vec1 = wheel.GetXForm().R.Col1; var projection = Vec2.Dot(velocity, vec1); vec1 *= projection; var k = vec1.Length() / 0.001f; // превышение боковой скорости 1 мм / с if (k < 0.1f) k = 0.1f; if (k > 10f) k = 10f; float force = -k * 3000; //warning - mn vec1.Normalize(); hull.ApplyForce(force * vec1, p_wheel); }