本文整理汇总了C#中FarseerPhysics.Dynamics.Body.ApplyForce方法的典型用法代码示例。如果您正苦于以下问题:C# Body.ApplyForce方法的具体用法?C# Body.ApplyForce怎么用?C# Body.ApplyForce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.Body
的用法示例。
在下文中一共展示了Body.ApplyForce方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBullets
private static void CreateBullets(Body ship)
{
Func<Vector2, Body> createBullet = pos =>
{
var body = new Body(world);
body.BodyType = BodyType.Dynamic;
body.IsBullet = true;
var shape = new FarseerCircleShape(0.15f / 4, 1);
body.CreateFixture(shape);
body.Position = ship.Position + ship.GetWorldVector(pos);
body.Rotation = ship.Rotation;
body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f)));
body.OnCollision += (a, b, contact) =>
{
world.RemoveBody(body);
return false;
};
return body;
};
createBullet(new Vector2(-0.575f, -0.20f));
createBullet(new Vector2(0.575f, -0.20f));
}
示例2: CenterGravity
public static void CenterGravity(Body Body)
{
Vector2f Pos = Body.Position.ToVec();
Quantity Radius = SI.px.Quant(Pos.Length()).Convert(SI.m) + SI.m.Quant(1000);
Quantity F = Constants.G * (SI.kg.Quant(Body.Mass) * SI.kg.Quant(5.972e16)) / (Radius ^ 2);
Vector2f Force = -Pos.Normalize() * (float)F.Amount;
Body.ApplyForce(Force.ToVec());
}
示例3: Load
public void Load()
{
var palette = Palette.FromXmlFile(DataPack.Colors.PaleBlue);
Add(new BgColorValue(palette.ColorSets[0].Colors[1]));
_actorColor = palette.ColorSets[0].Colors[3];
// scene
var scene = Add(RubeScene.FromFile(DataPack.Physic.Potato));
Add(new PropertyValue<Vector2>(new Vector2(0, 20),
() => Physic.World.Gravity,
v => Physic.World.Gravity = v));
// ui
_body = scene.GetBody("actor");
Add(new BodyStateRecorder(_body, "actor"));
//_body.Position = new Vector2(0, 10);
var actor = Add(new GameUI { Name = "actor"} );
var tracker = actor.Add(new BodyMouseTracker(_body, .4f));
Add(new BodyStateRecorder(tracker, "tracker"));
actor.AddRange(
new KeyBinding(Keys.Space, () => _body.ApplyForce(new Vector2(0, 20))),
new FlyController(_body, 10, 50),
new MouseZoomController(),
new TrackingBodyCameraController(tracker, UpdateTime.Sim),
new CameraStateRecorder()
);
_body.UserData = this;
// rendering
Add(new DrawComponent(DrawBody));
var staticBodies = scene.Bodies.Where(b => b.BodyType == BodyType.Static);
var contours = staticBodies.GetContours();
foreach (var contour in contours)
{
var strip = ShapeFactory.PolygonStrip(contour, .3f, .01f);
_staticBodiesContours.AddRange(strip);
}
// debug
Add(new UpdateComponent(Update, UpdateTime.Sim));
}
示例4: MoveBodyOnPath
//TODO: Comment better
/// <summary>
/// Moves the body on the path.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="time">The time.</param>
/// <param name="strength">The strength.</param>
/// <param name="timeStep">The time step.</param>
public static void MoveBodyOnPath(Path path, Body body, float time, float strength, float timeStep, bool if_type2 = true)
{
Vector2 destination = path.GetPosition(time);
Vector2 positionDelta = body.Position - destination;
if ( positionDelta.Length() != 0 )
positionDelta.Normalize(); // Added for game
Vector2 velocity = (positionDelta / timeStep) * strength;
Vector2 vel = Math.Min(8,body.LinearVelocity.Length()+3) * -velocity * body.Mass;
if (if_type2 && vel.Length() > 1)
{
float velocity_magnitude_X = Math.Abs(body.LinearVelocity.X);
float velocity_magnitude_Y = Math.Abs(body.LinearVelocity.Y);
float force_magnitude_X = Math.Abs(vel.X);
float force_magnitude_Y = Math.Abs(vel.Y);
bool horiz = force_magnitude_X > 2;
bool vert = force_magnitude_Y > 2;
bool high_vert_low_horiz = (velocity_magnitude_X < velocity_magnitude_Y - 10);
bool high_horiz_low_vert = velocity_magnitude_X > velocity_magnitude_Y + 10;
if ((horiz) && high_vert_low_horiz)
{
vel.X *= 2f;
vel.Y /= 2f;
//body.LinearVelocity = new Vector2(body.LinearVelocity.X,body.LinearVelocity.Y/1.5f);
}
if (vert && high_horiz_low_vert)
{
vel.Y *= 2f;
vel.X /= 2f;
// body.LinearVelocity = new Vector2(body.LinearVelocity.X/1.5f, body.LinearVelocity.Y);
}
if (Math.Sign(vel.Y) != Math.Sign(body.LinearVelocity.Y))
{
vel.Y *= 3;
}
if (Math.Sign(vel.X) != Math.Sign(body.LinearVelocity.X))
{
vel.X *= 3;
}
body.ApplyForce(vel);
}
else if(path.GetLength()>0.5f)
{
body.LinearVelocity = -velocity;
}
}
示例5: CreateBullets
private void CreateBullets()
{
Func<Vector2, Body> createBullet = pos =>
{
var body = new Body(Game.World);
body.BodyType = BodyType.Dynamic;
body.IsBullet = true;
body.UserData = new RadarData(RadarType.Bullet, new NetBullet(body));
var shape = new CircleShape(0.15f / 4, 1);
body.CreateFixture(shape);
body.Position = Body.Position + Body.GetWorldVector(pos);
body.Rotation = Body.Rotation;
body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -10f)));
body.OnCollision += (a, b, contact) =>
{
Game.World.RemoveBody(body);
return false;
};
return body;
};
createBullet(new Vector2(-0.575f, -0.20f));
createBullet(new Vector2(0.575f, -0.20f));
}