本文整理汇总了C#中Box2DX.Dynamics.Body.GetWorldCenter方法的典型用法代码示例。如果您正苦于以下问题:C# Body.GetWorldCenter方法的具体用法?C# Body.GetWorldCenter怎么用?C# Body.GetWorldCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2DX.Dynamics.Body
的用法示例。
在下文中一共展示了Body.GetWorldCenter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Car
public Car()
{
{ // car body
PolygonDef poly1 = new PolygonDef(), poly2 = new PolygonDef();
// bottom half
poly1.VertexCount = 5;
poly1.Vertices[4].Set(-2.2f, -0.74f);
poly1.Vertices[3].Set(-2.2f, 0);
poly1.Vertices[2].Set(1.0f, 0);
poly1.Vertices[1].Set(2.2f, -0.2f);
poly1.Vertices[0].Set(2.2f, -0.74f);
poly1.Filter.GroupIndex = -1;
poly1.Density = 20.0f;
poly1.Friction = 0.68f;
poly1.Filter.GroupIndex = -1;
// top half
poly2.VertexCount = 4;
poly2.Vertices[3].Set(-1.7f, 0);
poly2.Vertices[2].Set(-1.3f, 0.7f);
poly2.Vertices[1].Set(0.5f, 0.74f);
poly2.Vertices[0].Set(1.0f, 0);
poly2.Filter.GroupIndex = -1;
poly2.Density = 5.0f;
poly2.Friction = 0.68f;
poly2.Filter.GroupIndex = -1;
BodyDef bd = new BodyDef();
bd.Position.Set(-35.0f, 2.8f);
_vehicle = _world.CreateBody(bd);
_vehicle.CreateShape(poly1);
_vehicle.CreateShape(poly2);
_vehicle.SetMassFromShapes();
}
{ // vehicle wheels
CircleDef circ = new CircleDef();
circ.Density = 40.0f;
circ.Radius = 0.38608f;
circ.Friction = 0.8f;
circ.Filter.GroupIndex = -1;
BodyDef bd = new BodyDef();
bd.AllowSleep = false;
bd.Position.Set(-33.8f, 2.0f);
_rightWheel = _world.CreateBody(bd);
_rightWheel.CreateShape(circ);
_rightWheel.SetMassFromShapes();
bd.Position.Set(-36.2f, 2.0f);
_leftWheel = _world.CreateBody(bd);
_leftWheel.CreateShape(circ);
_leftWheel.SetMassFromShapes();
}
{ // join wheels to chassis
Vec2 anchor = new Vec2();
RevoluteJointDef jd = new RevoluteJointDef();
jd.Initialize(_vehicle, _leftWheel, _leftWheel.GetWorldCenter());
jd.CollideConnected = false;
jd.EnableMotor = true;
jd.MaxMotorTorque = 10.0f;
jd.MotorSpeed = 0.0f;
_leftJoint = (RevoluteJoint)_world.CreateJoint(jd);
jd.Initialize(_vehicle, _rightWheel, _rightWheel.GetWorldCenter());
jd.CollideConnected = false;
_rightJoint = (RevoluteJoint)_world.CreateJoint(jd);
}
{ // ground
PolygonDef box = new PolygonDef();
box.SetAsBox(19.5f, 0.5f);
box.Friction = 0.62f;
BodyDef bd = new BodyDef();
bd.Position.Set(-25.0f, 1.0f);
Body ground = _world.CreateBody(bd);
ground.CreateShape(box);
}
{ // more ground
PolygonDef box = new PolygonDef();
BodyDef bd = new BodyDef();
box.SetAsBox(9.5f, 0.5f, Vec2.Zero, 0.1f * Box2DX.Common.Settings.Pi);
box.Friction = 0.62f;
bd.Position.Set(27.0f - 30.0f, 3.1f);
Body ground = _world.CreateBody(bd);
ground.CreateShape(box);
}
{ // more ground
//.........这里部分代码省略.........