本文整理汇总了C#中Vertices.ToMeters方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.ToMeters方法的具体用法?C# Vertices.ToMeters怎么用?C# Vertices.ToMeters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.ToMeters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBody
public override void CreateBody(World world, float width, float height)
{
_collisionWidth = width;
_collisionHeight = height;
var carPosition = Position2.ToMeters();
_body = new Body(world) {BodyType = BodyType.Dynamic, Position = carPosition, AngularDamping = 5};
var halfWidth = width/2;
var halfHeight = height/2;
var frontWheelOffset = (float) CarInfo.FrontWheelOffset/64;
var rearWheelOffset = (float) CarInfo.RearWheelOffset/64;
//collision detection Fixture
var vertices = new Vertices(4);
vertices.Add(new Vector2(-halfWidth, -halfHeight)); //Top-Left
vertices.Add(new Vector2(halfWidth, -halfHeight)); //Top-Right
vertices.Add(new Vector2(halfWidth, halfHeight)); //Bottom-Right
vertices.Add(new Vector2(-halfWidth, halfHeight)); //Bottom-Left
_shape = new PolygonShape(vertices.ToMeters(), 0.1f);
var fixture = _body.CreateFixture(_shape); //shape, density
fixture.OnCollision += OnCollision;
//SpriteId Fixture
//var spriteHalfWidth = (float) CarInfo.Sprite.Rectangle.CollisionWidth/2; //ToDo
//var spriteHalfHeight = (float) CarInfo.Sprite.Rectangle.CollisionHeight/2;
var spriteHalfWidth = (float) 52/64/2;
var spriteHalfHeight = (float) 128/64/2;
var spriteVertices = new Vertices(4);
spriteVertices.Add(new Vector2(-spriteHalfWidth, -spriteHalfHeight)); //Top-Left
spriteVertices.Add(new Vector2(spriteHalfWidth, -spriteHalfHeight)); //Top-Right
spriteVertices.Add(new Vector2(spriteHalfWidth, spriteHalfHeight)); //Bottom-Right
spriteVertices.Add(new Vector2(-spriteHalfWidth, spriteHalfHeight)); //Bottom-Left
_spriteShape = new PolygonShape(spriteVertices.ToMeters(), 0.1f);
var spriteFixture = _body.CreateFixture(_spriteShape);
spriteFixture.IsSensor = true;
float maxForwardSpeed = 300;
float maxBackwardSpeed = -40;
float backWheelMaxDriveForce = 950;
float frontWheelMaxDriveForce = 400;
float backWheelMaxLateralImpulse = 9;
float fronWheelMaxLateralImpulse = 9;
//back left wheel
var wheelOffsetPosition = new Vector2(halfWidth, rearWheelOffset).ToMeters();
var wheel = new Wheel(world);
wheel.SetCharacteristics(maxForwardSpeed, maxBackwardSpeed, backWheelMaxDriveForce, backWheelMaxLateralImpulse);
_wheels[0] = wheel;
_backLeftJoint = CreateJoint(_body, wheel.Body, wheelOffsetPosition, world);
//back right wheel
wheelOffsetPosition = new Vector2(-halfWidth, rearWheelOffset).ToMeters();
wheel = new Wheel(world);
wheel.SetCharacteristics(maxForwardSpeed, maxBackwardSpeed, backWheelMaxDriveForce, backWheelMaxLateralImpulse);
_wheels[1] = wheel;
_backRightJoint = CreateJoint(_body, wheel.Body, wheelOffsetPosition, world);
//front left wheel
wheelOffsetPosition = new Vector2(halfWidth, frontWheelOffset).ToMeters();
wheel = new Wheel(world);
wheel.SetCharacteristics(maxForwardSpeed, maxBackwardSpeed, frontWheelMaxDriveForce, fronWheelMaxLateralImpulse);
_wheels[2] = wheel;
_frontLeftJoint = CreateJoint(_body, wheel.Body, wheelOffsetPosition, world);
//front right wheel
wheelOffsetPosition = new Vector2(-halfWidth, frontWheelOffset).ToMeters();
wheel = new Wheel(world);
wheel.SetCharacteristics(maxForwardSpeed, maxBackwardSpeed, frontWheelMaxDriveForce, fronWheelMaxLateralImpulse);
_wheels[3] = wheel;
_frontRightJoint = CreateJoint(_body, wheel.Body, wheelOffsetPosition, world);
}