public void applyThreaded() { if (on) { if (a.IsFree || b.IsFree) { Vector2 delta; //lock(a) lock(b) { //faster square root approx from Advanced Character Physics delta = a.Position - b.Position; //} delta *= restLength2 / (delta.sqrMagnitude + restLength2) - 0.5f; if (a.IsFree) { //lock(a) { //a.Position += delta * sim.springConstant; Extension.InterlockAddFloat(ref a.Position.x, delta.x * sim.Settings.springConstant); Extension.InterlockAddFloat(ref a.Position.y, delta.y * sim.Settings.springConstant); //} } if (b.IsFree) { //lock (b) { //b.Position -= delta * sim.springConstant; Extension.InterlockAddFloat(ref b.Position.x, -delta.x * sim.Settings.springConstant); Extension.InterlockAddFloat(ref b.Position.y, -delta.y * sim.Settings.springConstant); //} } } } }
public void applyThreaded() { if (on) { Vector2 posA, posB, posM; //lock(particleA) lock(particleB) lock(particleM) { posA = particleA.Position; posB = particleB.Position; posM = particleM.Position; angle_Cur = GetAngleRadian(posA, posM, posB); //} float deltaAngle = GetDeltaAngle(); if (deltaAngle == 0f || Mathf.Abs(deltaAngle) < 0.01f) { return; } else { if (particleA.IsFree) { //lock (particleA) { Vector2 posA2 = Mathp.RotateVector2(posA, posM, deltaAngle * sim.Settings.angleConstant); posA2 = posA2 - posA; Extension.InterlockAddFloat(ref particleA.Position.x, posA2.x); Extension.InterlockAddFloat(ref particleA.Position.y, posA2.y); //} } if (particleB.IsFree) { //lock(particleB) { Vector2 posB2 = Mathp.RotateVector2(posB, posM, -deltaAngle * sim.Settings.angleConstant); posB2 -= posB; Extension.InterlockAddFloat(ref particleB.Position.x, posB2.x); Extension.InterlockAddFloat(ref particleB.Position.y, posB2.y); //} } if (particleM.IsFree) { //lock (particleM) { Vector2 posM2 = Mathp.RotateVector2(posM, posA, deltaAngle * sim.Settings.angleConstant); posM2 = Mathp.RotateVector2(posM2, posB, -deltaAngle * sim.Settings.angleConstant); posM2 -= posM; Extension.InterlockAddFloat(ref particleM.Position.x, posM2.x); Extension.InterlockAddFloat(ref particleM.Position.y, posM2.y); //} } } } }