本文整理汇总了C#中RigidBody.GetVelocityOfWorldPoint方法的典型用法代码示例。如果您正苦于以下问题:C# RigidBody.GetVelocityOfWorldPoint方法的具体用法?C# RigidBody.GetVelocityOfWorldPoint怎么用?C# RigidBody.GetVelocityOfWorldPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RigidBody
的用法示例。
在下文中一共展示了RigidBody.GetVelocityOfWorldPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
//--------------------------------------------------------------
/// <inheritdoc/>
public override void Apply(RigidBody body)
{
if (body == null)
throw new ArgumentNullException("body", "Rigid body in area of effect must not be null.");
// Get BuoyancyData. If necessary create new data.
BuoyancyData data = body.BuoyancyData;
if (data == null)
{
Prepare(body);
data = body.BuoyancyData;
}
// Compute size of volume that is in the water and the center of the submerged volume.
Vector3F centerOfSubmergedVolume;
float submergedVolume = GetSubmergedVolume(body.Scale, body.Pose, data.Mesh, out centerOfSubmergedVolume);
if (submergedVolume > 0)
{
// The up force.
Vector3F buoyancyForce = (Density * submergedVolume * Gravity) * Surface.Normal;
// The total volume of the body.
float totalVolume = data.Volume * body.Scale.X * body.Scale.Y * body.Scale.Z;
// The fraction of the total mass that is under the water (assuming constant density).
float submergedMass = body.MassFrame.Mass * submergedVolume / totalVolume;
// Compute linear drag.
Vector3F centerLinearVelocity = body.GetVelocityOfWorldPoint(centerOfSubmergedVolume);
Vector3F dragForce = (submergedMass * LinearDrag) * (Velocity - centerLinearVelocity);
// Apply up force and linear drag force.
Vector3F totalForce = buoyancyForce + dragForce;
AddForce(body, totalForce, centerOfSubmergedVolume);
// Apply torque for angular drag.
// body.Length is proportional to the unscaled shape. Apply scaling to get a new
// proportional value for the scaled shape.
float length = data.Length * 1.0f / 3.0f * (body.Scale.X + body.Scale.Y + body.Scale.Z);
float lengthSquared = length * length;
Vector3F dragTorque = (-submergedMass * AngularDrag * lengthSquared) * body.AngularVelocity;
AddTorque(body, dragTorque);
}
}