本文整理汇总了C#中FVector2.LengthSquared方法的典型用法代码示例。如果您正苦于以下问题:C# FVector2.LengthSquared方法的具体用法?C# FVector2.LengthSquared怎么用?C# FVector2.LengthSquared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FVector2
的用法示例。
在下文中一共展示了FVector2.LengthSquared方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SolveVelocityConstraints
internal override void SolveVelocityConstraints(ref SolverData data)
{
FVector2 vB = data.velocities[_indexB].v;
float wB = data.velocities[_indexB].w;
// Cdot = v + cross(w, r)
FVector2 Cdot = vB + MathUtils.Cross(wB, _rB);
FVector2 impulse = MathUtils.Mul(ref _mass, -(Cdot + _C + _gamma * _impulse));
FVector2 oldImpulse = _impulse;
_impulse += impulse;
float maxImpulse = data.step.dt * MaxForce;
if (_impulse.LengthSquared() > maxImpulse * maxImpulse)
{
_impulse *= maxImpulse / _impulse.Length();
}
impulse = _impulse - oldImpulse;
vB += _invMassB * impulse;
wB += _invIB * MathUtils.Cross(_rB, impulse);
data.velocities[_indexB].v = vB;
data.velocities[_indexB].w = wB;
}
示例2: SolveVelocityConstraints
internal override void SolveVelocityConstraints(ref SolverData data)
{
FVector2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
FVector2 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;
float h = data.step.dt;
// Solve angular friction
{
float Cdot = wB - wA;
float impulse = -_angularMass * Cdot;
float oldImpulse = _angularImpulse;
float maxImpulse = h * MaxTorque;
_angularImpulse = MathUtils.Clamp(_angularImpulse + impulse, -maxImpulse, maxImpulse);
impulse = _angularImpulse - oldImpulse;
wA -= iA * impulse;
wB += iB * impulse;
}
// Solve linear friction
{
FVector2 Cdot = vB + MathUtils.Cross(wB, m_rB) - vA - MathUtils.Cross(wA, m_rA);
FVector2 impulse = -MathUtils.Mul(ref _linearMass, Cdot);
FVector2 oldImpulse = _linearImpulse;
_linearImpulse += impulse;
float maxImpulse = h * MaxForce;
if (_linearImpulse.LengthSquared() > maxImpulse * maxImpulse)
{
_linearImpulse.Normalize();
_linearImpulse *= maxImpulse;
}
impulse = _linearImpulse - oldImpulse;
vA -= mA * impulse;
wA -= iA * MathUtils.Cross(m_rA, impulse);
vB += mB * impulse;
wB += iB * MathUtils.Cross(m_rB, impulse);
}
data.velocities[m_indexA].v = vA;
data.velocities[m_indexA].w = wA;
data.velocities[m_indexB].v = vB;
data.velocities[m_indexB].w = wB;
}