本文整理汇总了C#中BulletXNA.BulletDynamics.RigidBody.InternalGetVelocityInLocalPointObsolete方法的典型用法代码示例。如果您正苦于以下问题:C# RigidBody.InternalGetVelocityInLocalPointObsolete方法的具体用法?C# RigidBody.InternalGetVelocityInLocalPointObsolete怎么用?C# RigidBody.InternalGetVelocityInLocalPointObsolete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BulletXNA.BulletDynamics.RigidBody
的用法示例。
在下文中一共展示了RigidBody.InternalGetVelocityInLocalPointObsolete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SolveLinearAxis
public float SolveLinearAxis(
float timeStep,
float jacDiagABInv,
RigidBody body1, ref IndexedVector3 pointInA,
RigidBody body2, ref IndexedVector3 pointInB,
int limit_index,
ref IndexedVector3 axis_normal_on_a,
ref IndexedVector3 anchorPos)
{
///find relative velocity
// IndexedVector3 rel_pos1 = pointInA - body1.getCenterOfMassPosition();
// IndexedVector3 rel_pos2 = pointInB - body2.getCenterOfMassPosition();
IndexedVector3 rel_pos1 = anchorPos - body1.GetCenterOfMassPosition();
IndexedVector3 rel_pos2 = anchorPos - body2.GetCenterOfMassPosition();
IndexedVector3 vel1 = IndexedVector3.Zero;
body1.InternalGetVelocityInLocalPointObsolete(ref rel_pos1, ref vel1);
IndexedVector3 vel2 = IndexedVector3.Zero; ;
body2.InternalGetVelocityInLocalPointObsolete(ref rel_pos2, ref vel2);
IndexedVector3 vel = vel1 - vel2;
float rel_vel = IndexedVector3.Dot(axis_normal_on_a, vel);
/// apply displacement correction
//positional error (zeroth order error)
float depth = -IndexedVector3.Dot((pointInA - pointInB), axis_normal_on_a);
float lo = float.MinValue;
float hi = float.MaxValue;
float minLimit = m_lowerLimit[limit_index];
float maxLimit = m_upperLimit[limit_index];
//handle the limits
if (minLimit < maxLimit)
{
{
if (depth > maxLimit)
{
depth -= maxLimit;
lo = 0f;
}
else
{
if (depth < minLimit)
{
depth -= minLimit;
hi = 0f;
}
else
{
return 0.0f;
}
}
}
}
float normalImpulse = m_limitSoftness * (m_restitution * depth / timeStep - m_damping * rel_vel) * jacDiagABInv;
float oldNormalImpulse = m_accumulatedImpulse[limit_index];
float sum = oldNormalImpulse + normalImpulse;
m_accumulatedImpulse[limit_index] = (sum > hi ? 0f : sum < lo ? 0f : sum);
normalImpulse = m_accumulatedImpulse[limit_index] - oldNormalImpulse;
IndexedVector3 impulse_vector = axis_normal_on_a * normalImpulse;
//body1.applyImpulse( impulse_vector, rel_pos1);
//body2.applyImpulse(-impulse_vector, rel_pos2);
IndexedVector3 ftorqueAxis1 = IndexedVector3.Cross(rel_pos1, axis_normal_on_a);
IndexedVector3 ftorqueAxis2 = IndexedVector3.Cross(rel_pos2, axis_normal_on_a);
body1.InternalApplyImpulse(axis_normal_on_a * body1.GetInvMass(), body1.GetInvInertiaTensorWorld() * ftorqueAxis1, normalImpulse, "Generic6DoF body1");
body2.InternalApplyImpulse(axis_normal_on_a * body2.GetInvMass(), body2.GetInvInertiaTensorWorld() * ftorqueAxis2, -normalImpulse, "Generic6DoF body2");
return normalImpulse;
}
示例2: solveConstraintObsolete
public void solveConstraintObsolete(RigidBody bodyA, RigidBody bodyB, float timeStep)
{
if (m_useSolveConstraintObsolete)
{
IndexedVector3 pivotAInW = m_rbA.GetCenterOfMassTransform()*m_rbAFrame._origin;
IndexedVector3 pivotBInW = m_rbB.GetCenterOfMassTransform()*m_rbBFrame._origin;
float tau = 0.3f;
//linear part
if (!m_angularOnly)
{
IndexedVector3 rel_pos1 = pivotAInW - m_rbA.GetCenterOfMassPosition();
IndexedVector3 rel_pos2 = pivotBInW - m_rbB.GetCenterOfMassPosition();
IndexedVector3 vel1 = IndexedVector3.Zero;
bodyA.InternalGetVelocityInLocalPointObsolete(ref rel_pos1,ref vel1);
IndexedVector3 vel2 = IndexedVector3.Zero;
bodyB.InternalGetVelocityInLocalPointObsolete(ref rel_pos2,ref vel2);
IndexedVector3 vel = vel1 - vel2;
for (int i=0;i<3;i++)
{
IndexedVector3 normal = m_jac[i].m_linearJointAxis;
float jacDiagABInv = 1.0f / m_jac[i].GetDiagonal();
float rel_vel = normal.Dot(ref vel);
//positional error (zeroth order error)
float depth = -(pivotAInW - pivotBInW).Dot(ref normal); //this is the error projected on the normal
float impulse = depth*tau/timeStep * jacDiagABInv - rel_vel * jacDiagABInv;
m_appliedImpulse += impulse;
IndexedVector3 ftorqueAxis1 = rel_pos1.Cross(ref normal);
IndexedVector3 ftorqueAxis2 = rel_pos2.Cross(ref normal);
bodyA.InternalApplyImpulse(normal*m_rbA.GetInvMass(), m_rbA.GetInvInertiaTensorWorld()*ftorqueAxis1,impulse,null);
bodyB.InternalApplyImpulse(normal*m_rbB.GetInvMass(), m_rbB.GetInvInertiaTensorWorld()*ftorqueAxis2,-impulse,null);
}
}
// apply motor
if (m_bMotorEnabled)
{
// compute current and predicted transforms
IndexedMatrix trACur = m_rbA.GetCenterOfMassTransform();
IndexedMatrix trBCur = m_rbB.GetCenterOfMassTransform();
IndexedVector3 omegaA = IndexedVector3.Zero; bodyA.InternalGetAngularVelocity(ref omegaA);
IndexedVector3 omegaB = IndexedVector3.Zero; bodyB.InternalGetAngularVelocity(ref omegaB);
IndexedMatrix trAPred;
IndexedVector3 zerovec = new IndexedVector3(0,0,0);
TransformUtil.IntegrateTransform(ref trACur, ref zerovec, ref omegaA, timeStep, out trAPred);
IndexedMatrix trBPred;
TransformUtil.IntegrateTransform(ref trBCur, ref zerovec, ref omegaB, timeStep, out trBPred);
// compute desired transforms in world
IndexedMatrix trPose = IndexedMatrix.CreateFromQuaternion(m_qTarget);
IndexedMatrix trABDes = m_rbBFrame * trPose * m_rbAFrame.Inverse();
IndexedMatrix trADes = trBPred * trABDes;
IndexedMatrix trBDes = trAPred * trABDes.Inverse();
// compute desired omegas in world
IndexedVector3 omegaADes, omegaBDes;
TransformUtil.CalculateVelocity(ref trACur, ref trADes, timeStep, out zerovec, out omegaADes);
TransformUtil.CalculateVelocity(ref trBCur, ref trBDes, timeStep, out zerovec, out omegaBDes);
// compute delta omegas
IndexedVector3 dOmegaA = omegaADes - omegaA;
IndexedVector3 dOmegaB = omegaBDes - omegaB;
// compute weighted avg axis of dOmega (weighting based on inertias)
IndexedVector3 axisA = IndexedVector3.Zero, axisB = IndexedVector3.Zero;
float kAxisAInv = 0, kAxisBInv = 0;
if (dOmegaA.LengthSquared() > MathUtil.SIMD_EPSILON)
{
axisA = dOmegaA.Normalized();
kAxisAInv = GetRigidBodyA().ComputeAngularImpulseDenominator(ref axisA);
}
if (dOmegaB.LengthSquared() > MathUtil.SIMD_EPSILON)
{
axisB = dOmegaB.Normalized();
kAxisBInv = GetRigidBodyB().ComputeAngularImpulseDenominator(ref axisB);
}
IndexedVector3 avgAxis = kAxisAInv * axisA + kAxisBInv * axisB;
if (bDoTorque && avgAxis.LengthSquared() > MathUtil.SIMD_EPSILON)
{
avgAxis.Normalize();
kAxisAInv = GetRigidBodyA().ComputeAngularImpulseDenominator(ref avgAxis);
kAxisBInv = GetRigidBodyB().ComputeAngularImpulseDenominator(ref avgAxis);
float kInvCombined = kAxisAInv + kAxisBInv;
IndexedVector3 impulse = (kAxisAInv * dOmegaA - kAxisBInv * dOmegaB) /
(kInvCombined * kInvCombined);
if (m_maxMotorImpulse >= 0)
{
//.........这里部分代码省略.........