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


C# Body.ApplyForce方法代码示例

本文整理汇总了C#中Box2DX.Dynamics.Body.ApplyForce方法的典型用法代码示例。如果您正苦于以下问题:C# Body.ApplyForce方法的具体用法?C# Body.ApplyForce怎么用?C# Body.ApplyForce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Box2DX.Dynamics.Body的用法示例。


在下文中一共展示了Body.ApplyForce方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddSpringForce

		/// <summary>
		/// Add a spring force
		/// </summary>
		void AddSpringForce(Body bA, Vec2 localA, Body bB, Vec2 localB, float k, float friction, float desiredDist)
		{
			Vec2 pA = bA.GetWorldPoint(localA);
			Vec2 pB = bB.GetWorldPoint(localB);
			Vec2 diff = pB - pA;
			//Find velocities of attach points
			Vec2 vA = bA.GetLinearVelocity() - Vec2.Cross(bA.GetWorldVector(localA), bA.GetAngularVelocity());
			Vec2 vB = bB.GetLinearVelocity() - Vec2.Cross(bB.GetWorldVector(localB), bB.GetAngularVelocity());
			Vec2 vdiff = vB - vA;
			float dx = diff.Normalize(); //normalizes diff and puts length into dx
			float vrel = vdiff.X * diff.X + vdiff.Y * diff.Y;
			float forceMag = -k * (dx - desiredDist) - friction * vrel;
			diff *= forceMag; // diff *= forceMag
			bB.ApplyForce(diff, bA.GetWorldPoint(localA));
			diff *= -1.0f;
			bA.ApplyForce(diff, bB.GetWorldPoint(localB));
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:20,代码来源:ElasticBody.cs

示例2: killWheelOrthogonalVelocity

        void killWheelOrthogonalVelocity(Body hull, Body wheel)
        {
            var p_hull = hull.GetPosition();
            var p_wheel = wheel.GetPosition();
            var velocity = wheel.GetLinearVelocityFromLocalPoint(Vec2.Zero);

            var vec1 = wheel.GetXForm().R.Col1;
            var projection = Vec2.Dot(velocity, vec1);
            vec1 *= projection;

            var k = vec1.Length() / 0.001f; // превышение боковой скорости 1 мм / с
            if (k < 0.1f) k = 0.1f; if (k > 10f) k = 10f;
            float force = -k * 3000; //warning - mn

            vec1.Normalize();

            hull.ApplyForce(force * vec1, p_wheel);
        }
开发者ID:justheuristic,项目名称:GraveRobot,代码行数:18,代码来源:Car_.cs


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