当前位置: 首页>>代码示例>>C#>>正文


C# RigidBody.GetVelocityOfWorldPoint方法代码示例

本文整理汇总了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);
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:47,代码来源:Buoyancy.cs


注:本文中的RigidBody.GetVelocityOfWorldPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。