本文整理汇总了C#中SolverData类的典型用法代码示例。如果您正苦于以下问题:C# SolverData类的具体用法?C# SolverData怎么用?C# SolverData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SolverData类属于命名空间,在下文中一共展示了SolverData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: InitVelocityConstraints
internal override void InitVelocityConstraints(ref SolverData data)
{
_jointError = BodyA.Sweep.A - TargetAngle;
_bias = -BiasFactor * data.step.inv_dt * _jointError;
_massFactor = (1 - Softness) / (BodyA.InvI);
}
开发者ID:netonjm,项目名称:Rube.Net,代码行数:8,代码来源:FixedAngleJoint.cs
示例2: SolveVelocityConstraints
internal override void SolveVelocityConstraints(ref SolverData data)
{
//GABS: NOT A BOTTLENECK
float p = (_bias - BodyB.AngularVelocity + BodyA.AngularVelocity) * _massFactor;
BodyA.AngularVelocity -= BodyA.InvI * Math.Sign(p) * Math.Min(Math.Abs(p), MaxImpulse);
BodyB.AngularVelocity += BodyB.InvI * Math.Sign(p) * Math.Min(Math.Abs(p), MaxImpulse);
}
开发者ID:frotein,项目名称:TinyUniverse,代码行数:8,代码来源:AngleJoint.cs
示例3: SolvePositionConstraints
internal override bool SolvePositionConstraints(ref SolverData data)
{
Vector2 cA = data.positions[_indexA].c;
float aA = data.positions[_indexA].a;
Vector2 cB = data.positions[_indexB].c;
float aB = data.positions[_indexB].a;
Rot qA = new Rot(aA), qB = new Rot(aB);
float mA = _invMassA, mB = _invMassB;
float iA = _invIA, iB = _invIB;
Vector2 rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA);
Vector2 rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB);
float positionError, angularError;
Mat33 K = new Mat33();
K.ex.X = mA + mB + rA.Y * rA.Y * iA + rB.Y * rB.Y * iB;
K.ey.X = -rA.Y * rA.X * iA - rB.Y * rB.X * iB;
K.ez.X = -rA.Y * iA - rB.Y * iB;
K.ex.Y = K.ey.X;
K.ey.Y = mA + mB + rA.X * rA.X * iA + rB.X * rB.X * iB;
K.ez.Y = rA.X * iA + rB.X * iB;
K.ex.Z = K.ez.X;
K.ey.Z = K.ez.Y;
K.ez.Z = iA + iB;
if (FrequencyHz > 0.0f)
{
Vector2 C1 = cB + rB - cA - rA;
positionError = C1.Length();
angularError = 0.0f;
Vector2 P = -K.Solve22(C1);
cA -= mA * P;
aA -= iA * MathUtils.Cross(rA, P);
cB += mB * P;
aB += iB * MathUtils.Cross(rB, P);
}
else
{
Vector2 C1 = cB + rB - cA - rA;
float C2 = aB - aA - ReferenceAngle;
positionError = C1.Length();
angularError = Math.Abs(C2);
Vector3 C = new Vector3(C1.X, C1.Y, C2);
Vector3 impulse = -K.Solve33(C);
Vector2 P = new Vector2(impulse.X, impulse.Y);
cA -= mA * P;
aA -= iA * (MathUtils.Cross(rA, P) + impulse.Z);
cB += mB * P;
aB += iB * (MathUtils.Cross(rB, P) + impulse.Z);
}
data.positions[_indexA].c = cA;
data.positions[_indexA].a = aA;
data.positions[_indexB].c = cB;
data.positions[_indexB].a = aB;
return positionError <= Settings.LinearSlop && angularError <= Settings.AngularSlop;
}
开发者ID:nagyist,项目名称:Farseer-Physics-Engine-For-MonoMac,代码行数:70,代码来源:WeldJoint.cs
示例4: solveVelocityConstraints
public override void solveVelocityConstraints(SolverData data)
{
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
float mA = m_invMassA, mB = m_invMassB;
float iA = m_invIA, iB = m_invIB;
Vec2 temp = pool.popVec2();
// Solve linear motor constraint.
if (m_enableMotor && m_limitState != LimitState.EQUAL)
{
temp.set_Renamed(vB).subLocal(vA);
float Cdot = Vec2.dot(m_axis, temp) + m_a2 * wB - m_a1 * wA;
float impulse = m_motorMass * (m_motorSpeed - Cdot);
float oldImpulse = m_motorImpulse;
float maxImpulse = data.step.dt * m_maxMotorForce;
m_motorImpulse = MathUtils.clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse);
impulse = m_motorImpulse - oldImpulse;
Vec2 P = pool.popVec2();
P.set_Renamed(m_axis).mulLocal(impulse);
float LA = impulse * m_a1;
float LB = impulse * m_a2;
vA.x -= mA * P.x;
vA.y -= mA * P.y;
wA -= iA * LA;
vB.x += mB * P.x;
vB.y += mB * P.y;
wB += iB * LB;
pool.pushVec2(1);
}
Vec2 Cdot1 = pool.popVec2();
temp.set_Renamed(vB).subLocal(vA);
Cdot1.x = Vec2.dot(m_perp, temp) + m_s2 * wB - m_s1 * wA;
Cdot1.y = wB - wA;
// System.out.println(Cdot1);
if (m_enableLimit && m_limitState != LimitState.INACTIVE)
{
// Solve prismatic and limit constraint in block form.
float Cdot2;
temp.set_Renamed(vB).subLocal(vA);
Cdot2 = Vec2.dot(m_axis, temp) + m_a2 * wB - m_a1 * wA;
Vec3 Cdot = pool.popVec3();
Cdot.set_Renamed(Cdot1.x, Cdot1.y, Cdot2);
Cdot.negateLocal();
Vec3 f1 = pool.popVec3();
Vec3 df = pool.popVec3();
f1.set_Renamed(m_impulse);
m_K.solve33ToOut(Cdot.negateLocal(), df);
//Cdot.negateLocal(); not used anymore
m_impulse.addLocal(df);
if (m_limitState == LimitState.AT_LOWER)
{
m_impulse.z = MathUtils.max(m_impulse.z, 0.0f);
}
else if (m_limitState == LimitState.AT_UPPER)
{
m_impulse.z = MathUtils.min(m_impulse.z, 0.0f);
}
// f2(1:2) = invK(1:2,1:2) * (-Cdot(1:2) - K(1:2,3) * (f2(3) - f1(3))) +
// f1(1:2)
Vec2 b = pool.popVec2();
Vec2 f2r = pool.popVec2();
temp.set_Renamed(m_K.ez.x, m_K.ez.y).mulLocal(m_impulse.z - f1.z);
b.set_Renamed(Cdot1).negateLocal().subLocal(temp);
temp.set_Renamed(f1.x, f1.y);
m_K.solve22ToOut(b, f2r);
f2r.addLocal(temp);
m_impulse.x = f2r.x;
m_impulse.y = f2r.y;
df.set_Renamed(m_impulse).subLocal(f1);
Vec2 P = pool.popVec2();
temp.set_Renamed(m_axis).mulLocal(df.z);
P.set_Renamed(m_perp).mulLocal(df.x).addLocal(temp);
float LA = df.x * m_s1 + df.y + df.z * m_a1;
float LB = df.x * m_s2 + df.y + df.z * m_a2;
vA.x -= mA * P.x;
vA.y -= mA * P.y;
wA -= iA * LA;
//.........这里部分代码省略.........
开发者ID:thdtjsdn,项目名称:box2dnet,代码行数:101,代码来源:PrismaticJoint.cs
示例5: initVelocityConstraints
public override void initVelocityConstraints(SolverData data)
{
m_indexA = m_bodyA.m_islandIndex;
m_indexB = m_bodyB.m_islandIndex;
m_localCenterA.set_Renamed(m_bodyA.m_sweep.localCenter);
m_localCenterB.set_Renamed(m_bodyB.m_sweep.localCenter);
m_invMassA = m_bodyA.m_invMass;
m_invMassB = m_bodyB.m_invMass;
m_invIA = m_bodyA.m_invI;
m_invIB = m_bodyB.m_invI;
Vec2 cA = data.positions[m_indexA].c;
float aA = data.positions[m_indexA].a;
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
Rot qA = pool.popRot();
Rot qB = pool.popRot();
Vec2 d = pool.popVec2();
Vec2 temp = pool.popVec2();
Vec2 rA = pool.popVec2();
Vec2 rB = pool.popVec2();
qA.set_Renamed(aA);
qB.set_Renamed(aB);
// Compute the effective masses.
Rot.mulToOutUnsafe(qA, d.set_Renamed(m_localAnchorA).subLocal(m_localCenterA), rA);
Rot.mulToOutUnsafe(qB, d.set_Renamed(m_localAnchorB).subLocal(m_localCenterB), rB);
d.set_Renamed(cB).subLocal(cA).addLocal(rB).subLocal(rA);
float mA = m_invMassA, mB = m_invMassB;
float iA = m_invIA, iB = m_invIB;
// Compute motor Jacobian and effective mass.
{
Rot.mulToOutUnsafe(qA, m_localXAxisA, m_axis);
temp.set_Renamed(d).addLocal(rA);
m_a1 = Vec2.cross(temp, m_axis);
m_a2 = Vec2.cross(rB, m_axis);
m_motorMass = mA + mB + iA * m_a1 * m_a1 + iB * m_a2 * m_a2;
if (m_motorMass > 0.0f)
{
m_motorMass = 1.0f / m_motorMass;
}
}
// Prismatic constraint.
{
Rot.mulToOutUnsafe(qA, m_localYAxisA, m_perp);
temp.set_Renamed(d).addLocal(rA);
m_s1 = Vec2.cross(temp, m_perp);
m_s2 = Vec2.cross(rB, m_perp);
float k11 = mA + mB + iA * m_s1 * m_s1 + iB * m_s2 * m_s2;
float k12 = iA * m_s1 + iB * m_s2;
float k13 = iA * m_s1 * m_a1 + iB * m_s2 * m_a2;
float k22 = iA + iB;
if (k22 == 0.0f)
{
// For bodies with fixed rotation.
k22 = 1.0f;
}
float k23 = iA * m_a1 + iB * m_a2;
float k33 = mA + mB + iA * m_a1 * m_a1 + iB * m_a2 * m_a2;
m_K.ex.set_Renamed(k11, k12, k13);
m_K.ey.set_Renamed(k12, k22, k23);
m_K.ez.set_Renamed(k13, k23, k33);
}
// Compute motor and limit terms.
if (m_enableLimit)
{
float jointTranslation = Vec2.dot(m_axis, d);
if (MathUtils.abs(m_upperTranslation - m_lowerTranslation) < 2.0f * Settings.linearSlop)
{
m_limitState = LimitState.EQUAL;
}
else if (jointTranslation <= m_lowerTranslation)
{
if (m_limitState != LimitState.AT_LOWER)
{
m_limitState = LimitState.AT_LOWER;
m_impulse.z = 0.0f;
}
}
else if (jointTranslation >= m_upperTranslation)
{
if (m_limitState != LimitState.AT_UPPER)
{
m_limitState = LimitState.AT_UPPER;
//.........这里部分代码省略.........
开发者ID:thdtjsdn,项目名称:box2dnet,代码行数:101,代码来源:PrismaticJoint.cs
示例6: SolvePositionConstraints
internal override bool SolvePositionConstraints(ref SolverData data)
{
if (Frequency > 0.0f)
{
// There is no position correction for soft distance constraints.
return true;
}
Body b1 = BodyA;
Body b2 = BodyB;
Transform xf1, xf2;
b1.GetTransform(out xf1);
b2.GetTransform(out xf2);
Vector2 r1 = MathUtils.Mul(ref xf1.q, LocalAnchorA - b1.LocalCenter);
Vector2 r2 = MathUtils.Mul(ref xf2.q, LocalAnchorB - b2.LocalCenter);
Vector2 d = b2.Sweep.C + r2 - b1.Sweep.C - r1;
float length = d.Length();
if (length < MaxLength && length > MinLength)
{
return true;
}
if (length == 0.0f)
return true;
d /= length;
float C = length - MaxLength;
C = MathUtils.Clamp(C, -Settings.MaxLinearCorrection, Settings.MaxLinearCorrection);
float impulse = -_mass * C;
_u = d;
Vector2 P = impulse * _u;
b1.Sweep.C -= b1.InvMass * P;
b1.Sweep.A -= b1.InvI * MathUtils.Cross(r1, P);
b2.Sweep.C += b2.InvMass * P;
b2.Sweep.A += b2.InvI * MathUtils.Cross(r2, P);
b1.SynchronizeTransform();
b2.SynchronizeTransform();
return Math.Abs(C) < Settings.LinearSlop;
}
开发者ID:boris2,项目名称:mmogameproject2,代码行数:48,代码来源:SliderJoint.cs
示例7: SolvePositionConstraints
internal override bool SolvePositionConstraints(ref SolverData data)
{
Vector2 cA = data.positions[_indexA].c;
float aA = data.positions[_indexA].a;
Vector2 cB = data.positions[_indexB].c;
float aB = data.positions[_indexB].a;
Rot qA = new Rot(aA), qB = new Rot(aB);
Vector2 rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA);
Vector2 rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB);
Vector2 u = cB + rB - cA - rA;
float length = u.Length(); u.Normalize();
float C = length - MaxLength;
C = MathUtils.Clamp(C, 0.0f, Settings.MaxLinearCorrection);
float impulse = -_mass * C;
Vector2 P = impulse * u;
cA -= _invMassA * P;
aA -= _invIA * MathUtils.Cross(rA, P);
cB += _invMassB * P;
aB += _invIB * MathUtils.Cross(rB, P);
data.positions[_indexA].c = cA;
data.positions[_indexA].a = aA;
data.positions[_indexB].c = cB;
data.positions[_indexB].a = aB;
return length - MaxLength < Settings.LinearSlop;
}
开发者ID:netonjm,项目名称:Rube.Net,代码行数:33,代码来源:RopeJoint.cs
示例8: InitVelocityConstraints
internal override void InitVelocityConstraints(ref SolverData data)
{
_indexA = BodyA.IslandIndex;
_indexB = BodyB.IslandIndex;
_localCenterA = BodyA.Sweep.LocalCenter;
_localCenterB = BodyB.Sweep.LocalCenter;
_invMassA = BodyA.InvMass;
_invMassB = BodyB.InvMass;
_invIA = BodyA.InvI;
_invIB = BodyB.InvI;
Vector2 cA = data.positions[_indexA].c;
float aA = data.positions[_indexA].a;
Vector2 vA = data.velocities[_indexA].v;
float wA = data.velocities[_indexA].w;
Vector2 cB = data.positions[_indexB].c;
float aB = data.positions[_indexB].a;
Vector2 vB = data.velocities[_indexB].v;
float wB = data.velocities[_indexB].w;
Rot qA = new Rot(aA), qB = new Rot(aB);
_rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA);
_rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB);
_u = cB + _rB - cA - _rA;
_length = _u.Length();
float C = _length - MaxLength;
if (C > 0.0f)
{
_state = LimitState.AtUpper;
}
else
{
_state = LimitState.Inactive;
}
if (_length > Settings.LinearSlop)
{
_u *= 1.0f / _length;
}
else
{
_u = Vector2.Zero;
_mass = 0.0f;
_impulse = 0.0f;
return;
}
// Compute effective mass.
float crA = MathUtils.Cross(_rA, _u);
float crB = MathUtils.Cross(_rB, _u);
float invMass = _invMassA + _invIA * crA * crA + _invMassB + _invIB * crB * crB;
_mass = invMass != 0.0f ? 1.0f / invMass : 0.0f;
if (Settings.EnableWarmstarting)
{
// Scale the impulse to support a variable time step.
_impulse *= data.step.dtRatio;
Vector2 P = _impulse * _u;
vA -= _invMassA * P;
wA -= _invIA * MathUtils.Cross(_rA, P);
vB += _invMassB * P;
wB += _invIB * MathUtils.Cross(_rB, P);
}
else
{
_impulse = 0.0f;
}
data.velocities[_indexA].v = vA;
data.velocities[_indexA].w = wA;
data.velocities[_indexB].v = vB;
data.velocities[_indexB].w = wB;
}
开发者ID:netonjm,项目名称:Rube.Net,代码行数:79,代码来源:RopeJoint.cs
示例9: solveVelocityConstraints
public override void solveVelocityConstraints(SolverData data)
{
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
float mA = m_invMassA, mB = m_invMassB;
float iA = m_invIA, iB = m_invIB;
bool fixedRotation = (iA + iB == 0.0f);
// Solve motor constraint.
if (m_enableMotor && m_limitState != LimitState.EQUAL && fixedRotation == false)
{
float Cdot = wB - wA - m_motorSpeed;
float impulse = -m_motorMass*Cdot;
float oldImpulse = m_motorImpulse;
float maxImpulse = data.step.dt*m_maxMotorTorque;
m_motorImpulse = MathUtils.clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse);
impulse = m_motorImpulse - oldImpulse;
wA -= iA*impulse;
wB += iB*impulse;
}
Vec2 temp = pool.popVec2();
// Solve limit constraint.
if (m_enableLimit && m_limitState != LimitState.INACTIVE && fixedRotation == false)
{
Vec2 Cdot1 = pool.popVec2();
Vec3 Cdot = pool.popVec3();
// Solve point-to-point constraint
Vec2.crossToOutUnsafe(wA, m_rA, ref temp);
Vec2.crossToOutUnsafe(wB, m_rB, ref Cdot1);
Cdot1.addLocal(vB);
Cdot1.subLocal(vA);
Cdot1.subLocal(temp);
float Cdot2 = wB - wA;
Cdot.set(Cdot1.x, Cdot1.y, Cdot2);
Vec3 impulse = pool.popVec3();
m_mass.solve33ToOut(Cdot, ref impulse);
impulse.negateLocal();
if (m_limitState == LimitState.EQUAL)
{
m_impulse.addLocal(impulse);
}
else if (m_limitState == LimitState.AT_LOWER)
{
float newImpulse = m_impulse.z + impulse.z;
if (newImpulse < 0.0f)
{
Vec2 rhs = pool.popVec2();
rhs.set(m_mass.ez.x, m_mass.ez.y);
rhs.mulLocal(m_impulse.z);
rhs.subLocal(Cdot1);
m_mass.solve22ToOut(rhs, ref temp);
impulse.x = temp.x;
impulse.y = temp.y;
impulse.z = -m_impulse.z;
m_impulse.x += temp.x;
m_impulse.y += temp.y;
m_impulse.z = 0.0f;
pool.pushVec2(1);
}
else
{
m_impulse.addLocal(impulse);
}
}
else if (m_limitState == LimitState.AT_UPPER)
{
float newImpulse = m_impulse.z + impulse.z;
if (newImpulse > 0.0f)
{
Vec2 rhs = pool.popVec2();
rhs.set(m_mass.ez.x, m_mass.ez.y);
rhs.mulLocal(m_impulse.z);
rhs.subLocal(Cdot1);
m_mass.solve22ToOut(rhs, ref temp);
impulse.x = temp.x;
impulse.y = temp.y;
impulse.z = -m_impulse.z;
m_impulse.x += temp.x;
m_impulse.y += temp.y;
m_impulse.z = 0.0f;
pool.pushVec2(1);
}
else
{
m_impulse.addLocal(impulse);
}
}
Vec2 P = pool.popVec2();
//.........这里部分代码省略.........
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:101,代码来源:RevoluteJoint.cs
示例10: solvePositionConstraints
public override bool solvePositionConstraints(SolverData data)
{
Rot qA = pool.popRot();
Rot qB = pool.popRot();
Vec2 cA = data.positions[m_indexA].c;
float aA = data.positions[m_indexA].a;
Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
qA.set(aA);
qB.set(aB);
float angularError = 0.0f;
float positionError = 0.0f;
bool fixedRotation = (m_invIA + m_invIB == 0.0f);
// Solve angular limit constraint.
if (m_enableLimit && m_limitState != LimitState.INACTIVE && fixedRotation == false)
{
float angle = aB - aA - m_referenceAngle;
float limitImpulse = 0.0f;
if (m_limitState == LimitState.EQUAL)
{
// Prevent large angular corrections
float C =
MathUtils.clamp(angle - m_lowerAngle, -Settings.maxAngularCorrection,
Settings.maxAngularCorrection);
limitImpulse = -m_motorMass*C;
angularError = MathUtils.abs(C);
}
else if (m_limitState == LimitState.AT_LOWER)
{
float C = angle - m_lowerAngle;
angularError = -C;
// Prevent large angular corrections and allow some slop.
C = MathUtils.clamp(C + Settings.angularSlop, -Settings.maxAngularCorrection, 0.0f);
limitImpulse = -m_motorMass*C;
}
else if (m_limitState == LimitState.AT_UPPER)
{
float C = angle - m_upperAngle;
angularError = C;
// Prevent large angular corrections and allow some slop.
C = MathUtils.clamp(C - Settings.angularSlop, 0.0f, Settings.maxAngularCorrection);
limitImpulse = -m_motorMass*C;
}
aA -= m_invIA*limitImpulse;
aB += m_invIB*limitImpulse;
}
// Solve point-to-point constraint.
{
qA.set(aA);
qB.set(aB);
Vec2 rA = pool.popVec2();
Vec2 rB = pool.popVec2();
Vec2 C = pool.popVec2();
Vec2 impulse = pool.popVec2();
C.set(m_localAnchorA);
C.subLocal(m_localCenterA);
Rot.mulToOutUnsafe(qA, C, ref rA);
C.set(m_localAnchorB);
C.subLocal(m_localCenterB);
Rot.mulToOutUnsafe(qB, C, ref rB);
C.set(cB);
C.addLocal(rB);
C.subLocal(cA);
C.subLocal(rA);
positionError = C.length();
float mA = m_invMassA, mB = m_invMassB;
float iA = m_invIA, iB = m_invIB;
Mat22 K = pool.popMat22();
K.ex.x = mA + mB + iA*rA.y*rA.y + iB*rB.y*rB.y;
K.ex.y = -iA*rA.x*rA.y - iB*rB.x*rB.y;
K.ey.x = K.ex.y;
K.ey.y = mA + mB + iA*rA.x*rA.x + iB*rB.x*rB.x;
K.solveToOut(C, ref impulse);
impulse.negateLocal();
cA.x -= mA*impulse.x;
cA.y -= mA*impulse.y;
aA -= iA*Vec2.cross(rA, impulse);
cB.x += mB*impulse.x;
cB.y += mB*impulse.y;
aB += iB*Vec2.cross(rB, impulse);
pool.pushVec2(4);
pool.pushMat22(1);
}
// data.positions[m_indexA].c.set(cA);
data.positions[m_indexA].a = aA;
//.........这里部分代码省略.........
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:101,代码来源:RevoluteJoint.cs
示例11: initVelocityConstraints
public override void initVelocityConstraints(SolverData data)
{
m_indexA = m_bodyA.m_islandIndex;
m_indexB = m_bodyB.m_islandIndex;
m_localCenterA.set(m_bodyA.m_sweep.localCenter);
m_localCenterB.set(m_bodyB.m_sweep.localCenter);
m_invMassA = m_bodyA.m_invMass;
m_invMassB = m_bodyB.m_invMass;
m_invIA = m_bodyA.m_invI;
m_invIB = m_bodyB.m_invI;
// Vec2 cA = data.positions[m_indexA].c;
float aA = data.positions[m_indexA].a;
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
// Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
Rot qA = pool.popRot();
Rot qB = pool.popRot();
Vec2 temp = pool.popVec2();
qA.set(aA);
qB.set(aB);
// Compute the effective masses.
temp.set(m_localAnchorA);
temp.subLocal(m_localCenterA);
Rot.mulToOutUnsafe(qA, temp, ref m_rA);
temp.set(m_localAnchorB);
temp.subLocal(m_localCenterB);
Rot.mulToOutUnsafe(qB, temp, ref m_rB);
// J = [-I -r1_skew I r2_skew]
// [ 0 -1 0 1]
// r_skew = [-ry; rx]
// Matlab
// K = [ mA+r1y^2*iA+mB+r2y^2*iB, -r1y*iA*r1x-r2y*iB*r2x, -r1y*iA-r2y*iB]
// [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB]
// [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB]
float mA = m_invMassA, mB = m_invMassB;
float iA = m_invIA, iB = m_invIB;
bool fixedRotation = (iA + iB == 0.0f);
m_mass.ex.x = mA + mB + m_rA.y*m_rA.y*iA + m_rB.y*m_rB.y*iB;
m_mass.ey.x = -m_rA.y*m_rA.x*iA - m_rB.y*m_rB.x*iB;
m_mass.ez.x = -m_rA.y*iA - m_rB.y*iB;
m_mass.ex.y = m_mass.ey.x;
m_mass.ey.y = mA + mB + m_rA.x*m_rA.x*iA + m_rB.x*m_rB.x*iB;
m_mass.ez.y = m_rA.x*iA + m_rB.x*iB;
m_mass.ex.z = m_mass.ez.x;
m_mass.ey.z = m_mass.ez.y;
m_mass.ez.z = iA + iB;
m_motorMass = iA + iB;
if (m_motorMass > 0.0f)
{
m_motorMass = 1.0f/m_motorMass;
}
if (m_enableMotor == false || fixedRotation)
{
m_motorImpulse = 0.0f;
}
if (m_enableLimit && fixedRotation == false)
{
float jointAngle = aB - aA - m_referenceAngle;
if (MathUtils.abs(m_upperAngle - m_lowerAngle) < 2.0f*Settings.angularSlop)
{
m_limitState = LimitState.EQUAL;
}
else if (jointAngle <= m_lowerAngle)
{
if (m_limitState != LimitState.AT_LOWER)
{
m_impulse.z = 0.0f;
}
m_limitState = LimitState.AT_LOWER;
}
else if (jointAngle >= m_upperAngle)
{
if (m_limitState != LimitState.AT_UPPER)
{
m_impulse.z = 0.0f;
}
m_limitState = LimitState.AT_UPPER;
}
else
{
m_limitState = LimitState.INACTIVE;
m_impulse.z = 0.0f;
}
}
else
//.........这里部分代码省略.........
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:101,代码来源:RevoluteJoint.cs
示例12: SolveVelocityConstraints
internal abstract void SolveVelocityConstraints(ref SolverData data);
开发者ID:tracer0707,项目名称:OpenGLF,代码行数:1,代码来源:Joint.cs
示例13: SolvePositionConstraints
/// <summary>
/// Solves the position constraints.
/// </summary>
/// <param name="data"></param>
/// <returns>returns true if the position errors are within tolerance.</returns>
internal abstract bool SolvePositionConstraints(ref SolverData data);
开发者ID:tracer0707,项目名称:OpenGLF,代码行数:6,代码来源:Joint.cs
示例14: SolveVelocityConstraints
public override void SolveVelocityConstraints(SolverData data)
{
float crossMassSum = 0.0f;
float dotMassSum = 0.0f;
Vec2[] d = Pool.GetVec2Array(Bodies.Length);
for (int i = 0; i < Bodies.Length; ++i)
{
int prev = (i == 0) ? Bodies.Length - 1 : i - 1;
int next = (i == Bodies.Length - 1) ? 0 : i + 1;
d[i].Set(Bodies[next].WorldCenter);
d[i].SubLocal(Bodies[prev].WorldCenter);
dotMassSum += (d[i].LengthSquared()) / Bodies[i].Mass;
crossMassSum += Vec2.Cross(Bodies[i].LinearVelocity, d[i]);
}
float lambda = (-2.0f) * crossMassSum / dotMassSum;
// System.out.println(crossMassSum + " " +dotMassSum);
// lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
// Settings.maxLinearCorrection);
m_impulse += lambda;
// System.out.println(m_impulse);
for (int i = 0; i < Bodies.Length; ++i)
{
Bodies[i].LinearVelocity.X += Bodies[i].InvMass * d[i].Y * .5f * lambda;
Bodies[i].LinearVelocity.Y += Bodies[i].InvMass * (-d[i].X) * .5f * lambda;
}
}
开发者ID:gerich-home,项目名称:box2dnet,代码行数:28,代码来源:ConstantVolumeJoint.cs
示例15: SolvePositionConstraints
public override bool SolvePositionConstraints(SolverData data)
{
return ConstrainEdges(data.Step);
}
开发者ID:gerich-home,项目名称:box2dnet,代码行数:4,代码来源:ConstantVolumeJoint.cs
示例16: solvePositionConstraints
public override bool solvePositionConstraints(SolverData data)
{
Rot qA = pool.popRot();
Rot qB = pool.popRot();
Vec2 rA = pool.popVec2();
Vec2 rB = pool.popVec2();
Vec2 uA = pool.popVec2();
Vec2 uB = pool.popVec2();
Vec2 temp = pool.popVec2();
Vec2 PA = pool.popVec2();
Vec2 PB = pool.popVec2();
Vec2 cA = data.positions[m_indexA].c;
float aA = data.positions[m_indexA].a;
Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
qA.set_Renamed(aA);
qB.set_Renamed(aB);
Rot.mulToOutUnsafe(qA, temp.set_Renamed(m_localAnchorA).subLocal(m_localCenterA), rA);
Rot.mulToOutUnsafe(qB, temp.set_Renamed(m_localAnchorB).subLocal(m_localCenterB), rB);
uA.set_Renamed(cA).addLocal(rA).subLocal(m_groundAnchorA);
uB.set_Renamed(cB).addLocal(rB).subLocal(m_groundAnchorB);
float lengthA = uA.length();
float lengthB = uB.length();
if (lengthA > 10.0f * Settings.linearSlop)
{
uA.mulLocal(1.0f / lengthA);
}
else
{
uA.setZero();
}
if (lengthB > 10.0f * Settings.linearSlop)
{
uB.mulLocal(1.0f / lengthB);
}
else
{
uB.setZero();
}
// Compute effective mass.
float ruA = Vec2.cross(rA, uA);
float ruB = Vec2.cross(rB, uB);
float mA = m_invMassA + m_invIA * ruA * ruA;
float mB = m_invMassB + m_invIB * ruB * ruB;
float mass = mA + m_ratio * m_ratio * mB;
if (mass > 0.0f)
{
mass = 1.0f / mass;
}
float C = m_constant - lengthA - m_ratio * lengthB;
float linearError = MathUtils.abs(C);
float impulse = (-mass) * C;
PA.set_Renamed(uA).mulLocal(-impulse);
PB.set_Renamed(uB).mulLocal((-m_ratio) * impulse);
cA.x += m_invMassA * PA.x;
cA.y += m_invMassA * PA.y;
aA += m_invIA * Vec2.cross(rA, PA);
cB.x += m_invMassB * PB.x;
cB.y += m_invMassB * PB.y;
aB += m_invIB * Vec2.cross(rB, PB);
data.positions[m_indexA].c.set_Renamed(cA);
data.positions[m_indexA].a = aA;
data.positions[m_indexB].c.set_Renamed(cB);
data.positions[m_indexB].a = aB;
pool.pushRot(2);
pool.pushVec2(7);
return linearError < Settings.linearSlop;
}
开发者ID:thdtjsdn,项目名称:box2dnet,代码行数:86,代码来源:PulleyJoint.cs
示例17: solveVelocityConstraints
public override void solveVelocityConstraints(SolverData data)
{
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
Vec2 vpA = pool.popVec2();
Vec2 vpB = pool.popVec2();
Vec2 PA = pool.popVec2();
Vec2 PB = pool.popVec2();
Vec2.crossToOutUnsafe(wA, m_rA, vpA);
vpA.addLocal(vA);
Vec2.crossToOutUnsafe(wB, m_rB, vpB);
vpB.addLocal(vB);
float Cdot = -Vec2.dot(m_uA, vpA) - m_ratio * Vec2.dot(m_uB, vpB);
float impulse = (-m_mass) * Cdot;
m_impulse += impulse;
PA.set_Renamed(m_uA).mulLocal(-impulse);
PB.set_Renamed(m_uB).mulLocal((-m_ratio) * impulse);
vA.x += m_invMassA * PA.x;
vA.y += m_invMassA * PA.y;
wA += m_invIA * Vec2.cross(m_rA, PA);
vB.x += m_invMassB * PB.x;
vB.y += m_invMassB * PB.y;
wB += m_invIB * Vec2.cross(m_rB, PB);
data.velocities[m_indexA].v.set_Renamed(vA);
data.velocities[m_indexA].w = wA;
data.velocities[m_indexB].v.set_Renamed(vB);
data.velocities[m_indexB].w = wB;
pool.pushVec2(4);
}
开发者ID:thdtjsdn,项目名称:box2dnet,代码行数:37,代码来源:PulleyJoint.cs
示例18: initVelocityConstraints
public override void initVelocityConstraints(SolverData data)
{
m_indexA = m_bodyA.m_islandIndex;
m_indexB = m_bodyB.m_islandIndex;
m_localCenterA.set(m_bodyA.m_sweep.localCenter);
m_localCenterB.set(m_bodyB.m_sweep.localCenter);
m_invMassA = m_bodyA.m_invMass;
m_invMassB = m_bodyB.m_invMass;
m_invIA = m_bodyA.m_invI;
m_invIB = m_bodyB.m_invI;
float mA = m_invMassA, mB = m_invMassB;
float iA = m_invIA, iB = m_invIB;
Vec2 cA = data.positions[m_indexA].c;
float aA = data.positions[m_indexA].a;
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
Rot qA = pool.popRot();
Rot qB = pool.popRot();
Vec2 temp = pool.popVec2();
qA.set(aA);
qB.set(aB);
// Compute the effective masses.
temp.set(m_localAnchorA);
temp.subLocal(m_localCenterA);
Rot.mulToOutUnsafe(qA, temp , ref rA);
temp.set(m_localAnchorB);
temp.subLocal(m_localCenterB);
Rot.mulToOutUnsafe(qB, temp, ref rB);
d.set(cB);
d.addLocal(rB);
d.subLocal(cA);
d.subLocal(rA);
// Point to line constraint
{
Rot.mulToOut(qA, m_localYAxisA, ref m_ay);
temp.set(d);
temp.addLocal(rA);
m_sAy = Vec2.cross(temp, m_ay);
m_sBy = Vec2.cross(rB, m_ay);
m_mass = mA + mB + iA*m_sAy*m_sAy + iB*m_sBy*m_sBy;
if (m_mass > 0.0f)
{
m_mass = 1.0f/m_mass;
}
}
// Spring constraint
m_springMass = 0.0f;
m_bias = 0.0f;
m_gamma = 0.0f;
if (m_frequencyHz > 0.0f)
{
Rot.mulToOut(qA, m_localXAxisA, ref m_ax);
temp.set(d);
temp.addLocal(rA);
m_sAx = Vec2.cross(temp, m_ax);
m_sBx = Vec2.cross(rB, m_ax);
float invMass = mA + mB + iA*m_sAx*m_sAx + iB*m_sBx*m_sBx;
if (invMass > 0.0f)
{
m_springMass = 1.0f/invMass;
float C = Vec2.dot(d, m_ax);
// Frequency
float omega = 2.0f*MathUtils.PI*m_frequencyHz;
// Damping coefficient
float da = 2.0f*m_springMass*m_dampingRatio*omega;
// Spring stiffness
float k = m_springMass*omega*omega;
// magic formulas
float h = data.step.dt;
m_gamma = h*(da + h*k);
if (m_gamma > 0.0f)
{
m_gamma = 1.0f/m_gamma;
}
m_bias = C*h*k*m_gamma;
m_springMass = invMass + m_gamma;
if (m_springMass > 0.0f)
//.........这里部分代码省略.........
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:101,代码来源:WheelJoint.cs
示例19: SolveVelocityConstraints
internal override void SolveVelocityConstraints(ref SolverData data)
{
Vector2 vA = data.velocities[_indexA].v;
float wA = data.velocities[_indexA].w;
Vector2 vB = data.velocities[_indexB].v;
float wB = data.velocities[_indexB].w;
// Cdot = dot(u, v + cross(w, r))
Vector2 vpA = vA + MathUtils.Cross(wA, _rA);
Vector2 vpB = vB + MathUtils.Cross(wB, _rB);
float C = _length - MaxLength;
float Cdot = Vector2.Dot(_u, vpB - vpA);
// Predictive constraint.
if (C < 0.0f)
{
Cdot += data.step.inv_dt * C;
}
float impulse = -_mass * Cdot;
float oldImpulse = _impulse;
_impulse = Math.Min(0
|
请发表评论