本文整理汇总了C#中Box2DX.Dynamics.Body.SetLinearVelocity方法的典型用法代码示例。如果您正苦于以下问题:C# Body.SetLinearVelocity方法的具体用法?C# Body.SetLinearVelocity怎么用?C# Body.SetLinearVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2DX.Dynamics.Body
的用法示例。
在下文中一共展示了Body.SetLinearVelocity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Keyboard
public override void Keyboard(System.Windows.Forms.Keys key)
{
switch (key)
{
case System.Windows.Forms.Keys.B:
if (_bullet != null)
{
_world.DestroyBody(_bullet);
_bullet = null;
}
{
CircleDef sd = new CircleDef();
sd.Density = 20.0f;
sd.Radius = 0.25f;
sd.Restitution = 0.05f;
BodyDef bd = new BodyDef();
bd.IsBullet = true;
bd.Position.Set(-31.0f, 5.0f);
_bullet = _world.CreateBody(bd);
_bullet.CreateFixture(sd);
_bullet.SetMassFromShapes();
_bullet.SetLinearVelocity(new Vec2(400.0f, 0.0f));
}
break;
}
}
示例2: limitVelocity
float limitVelocity(Body hull, float max)
{
Vec2 velocity = hull.GetLinearVelocityFromLocalPoint(Box2DX.Common.Vec2.Zero);
var vec1 = hull.GetXForm().R.Col2;
var projection = Vec2.Dot(velocity, vec1);
vec1 *= projection;
var A = vec1.Length();
if (A > max)
{
var k = max / A;
hull.SetLinearVelocity(vec1 * k);
}
return A;
}
示例3: LaunchBomb
public void LaunchBomb(Vec2 position, Vec2 velocity)
{
if (_bomb != null)
{
_world.DestroyBody(_bomb);
_bomb = null;
}
BodyDef bd = new BodyDef();
bd.AllowSleep = true;
bd.Position = position;
bd.IsBullet = true;
_bomb = _world.CreateBody(bd);
_bomb.SetLinearVelocity(velocity);
CircleShape circle = new CircleShape();
circle._radius = 0.3f;
FixtureDef fd = new FixtureDef();
fd.Shape = circle;
fd.Density = 20.0f;
fd.Restitution = 0.1f;
Vec2 minV = position - new Vec2(0.3f, 0.3f);
Vec2 maxV = position + new Vec2(0.3f, 0.3f);
AABB aabb = new AABB();
aabb.LowerBound = minV;
aabb.UpperBound = maxV;
_bomb.CreateFixture(fd);
}
示例4: LaunchBomb
public void LaunchBomb()
{
if (_bomb != null)
{
_world.DestroyBody(_bomb);
_bomb = null;
}
BodyDef bd = new BodyDef();
bd.AllowSleep = true;
bd.Position.Set(Box2DX.Common.Math.Random(-15.0f, 15.0f), 30.0f);
bd.IsBullet = true;
_bomb = _world.CreateBody(bd);
_bomb.SetLinearVelocity(-5.0f * bd.Position);
CircleDef sd = new CircleDef();
sd.Radius = 0.3f;
sd.Density = 20.0f;
sd.Restitution = 0.1f;
_bomb.CreateShape(sd);
_bomb.SetMassFromShapes();
}