本文整理汇总了C#中BulletSharp.RigidBody.GetVelocityInLocalPoint方法的典型用法代码示例。如果您正苦于以下问题:C# RigidBody.GetVelocityInLocalPoint方法的具体用法?C# RigidBody.GetVelocityInLocalPoint怎么用?C# RigidBody.GetVelocityInLocalPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BulletSharp.RigidBody
的用法示例。
在下文中一共展示了RigidBody.GetVelocityInLocalPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateWheel
public void UpdateWheel(RigidBody chassis, RaycastInfo raycastInfo)
{
if (raycastInfo.IsInContact)
{
float project = Vector3.Dot(raycastInfo.ContactNormalWS, raycastInfo.WheelDirectionWS);
Vector3 chassis_velocity_at_contactPoint;
Vector3 relpos = raycastInfo.ContactPointWS - chassis.CenterOfMassPosition;
chassis_velocity_at_contactPoint = chassis.GetVelocityInLocalPoint(relpos);
float projVel = Vector3.Dot(raycastInfo.ContactNormalWS, chassis_velocity_at_contactPoint);
if (project >= -0.1f)
{
SuspensionRelativeVelocity = 0;
ClippedInvContactDotSuspension = 1.0f / 0.1f;
}
else
{
float inv = -1.0f / project;
SuspensionRelativeVelocity = projVel * inv;
ClippedInvContactDotSuspension = inv;
}
}
else // Not in contact : position wheel in a nice (rest length) position
{
RaycastInfo.SuspensionLength = SuspensionRestLength;
SuspensionRelativeVelocity = 0;
RaycastInfo.ContactNormalWS = -raycastInfo.WheelDirectionWS;
ClippedInvContactDotSuspension = 1.0f;
}
}
示例2: ResolveSingleBilateral
private void ResolveSingleBilateral(RigidBody body1, Vector3 pos1, RigidBody body2, Vector3 pos2, float distance, Vector3 normal, ref float impulse, float timeStep)
{
float normalLenSqr = normal.LengthSquared();
Debug.Assert(Math.Abs(normalLenSqr) < 1.1f);
if (normalLenSqr > 1.1f)
{
impulse = 0;
return;
}
Vector3 rel_pos1 = pos1 - body1.CenterOfMassPosition;
Vector3 rel_pos2 = pos2 - body2.CenterOfMassPosition;
Vector3 vel1 = body1.GetVelocityInLocalPoint(rel_pos1);
Vector3 vel2 = body2.GetVelocityInLocalPoint(rel_pos2);
Vector3 vel = vel1 - vel2;
Matrix world2A = body1.CenterOfMassTransform;
world2A.Origin = Vector3.Zero;
world2A = Matrix.Transpose(world2A);
Matrix world2B = body2.CenterOfMassTransform;
world2B.Origin = Vector3.Zero;
world2B = Matrix.Transpose(world2B);
Vector3 m_aJ = Vector3.TransformCoordinate(Vector3.Cross(rel_pos1, normal), world2A);
Vector3 m_bJ = Vector3.TransformCoordinate(Vector3.Cross(rel_pos2, -normal), world2B);
Vector3 m_0MinvJt = body1.InvInertiaDiagLocal * m_aJ;
Vector3 m_1MinvJt = body2.InvInertiaDiagLocal * m_bJ;
float jacDiagAB = body1.InvMass + Vector3.Dot(m_0MinvJt, m_aJ) + body2.InvMass + Vector3.Dot(m_1MinvJt, m_bJ);
float jacDiagABInv = 1.0f / jacDiagAB;
float rel_vel = Vector3.Dot(normal, vel);
//todo: move this into proper structure
const float contactDamping = 0.2f;
#if ONLY_USE_LINEAR_MASS
float massTerm = 1.0f / (body1.InvMass + body2.InvMass);
impulse = - contactDamping * rel_vel * massTerm;
#else
float velocityImpulse = -contactDamping * rel_vel * jacDiagABInv;
impulse = velocityImpulse;
#endif
}
示例3: CalcRollingFriction
float CalcRollingFriction(RigidBody body0, RigidBody body1, Vector3 contactPosWorld, Vector3 frictionDirectionWorld, float maxImpulse)
{
float denom0 = body0.ComputeImpulseDenominator(contactPosWorld, frictionDirectionWorld);
float denom1 = body1.ComputeImpulseDenominator(contactPosWorld, frictionDirectionWorld);
const float relaxation = 1.0f;
float jacDiagABInv = relaxation / (denom0 + denom1);
float j1;
Vector3 rel_pos1 = contactPosWorld - body0.CenterOfMassPosition;
Vector3 rel_pos2 = contactPosWorld - body1.CenterOfMassPosition;
Vector3 vel1 = body0.GetVelocityInLocalPoint(rel_pos1);
Vector3 vel2 = body1.GetVelocityInLocalPoint(rel_pos2);
Vector3 vel = vel1 - vel2;
float vrel = Vector3.Dot(frictionDirectionWorld, vel);
// calculate j that moves us to zero relative velocity
j1 = -vrel * jacDiagABInv;
j1 = Math.Min(j1, maxImpulse);
j1 = Math.Max(j1, -maxImpulse);
return j1;
}