本文整理汇总了C#中FarseerPhysics.Collision.Shapes.PolygonShape.SetAsBox方法的典型用法代码示例。如果您正苦于以下问题:C# PolygonShape.SetAsBox方法的具体用法?C# PolygonShape.SetAsBox怎么用?C# PolygonShape.SetAsBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Collision.Shapes.PolygonShape
的用法示例。
在下文中一共展示了PolygonShape.SetAsBox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tumbler
private Tumbler()
{
var ground = BodyFactory.CreateBody(World);
var body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 10.0f);
PolygonShape shape = new PolygonShape(5);
shape.SetAsBox(0.5f, 10.0f, new Vector2(10.0f, 0.0f), 0.0f);
body.CreateFixture(shape);
shape.SetAsBox(0.5f, 10.0f, new Vector2(-10.0f, 0.0f), 0.0f);
body.CreateFixture(shape);
shape.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, 10.0f), 0.0f);
body.CreateFixture(shape);
shape.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, -10.0f), 0.0f);
body.CreateFixture(shape);
var jd = new RevoluteJoint(ground, body, new Vector2(0.0f, 10.0f), new Vector2(0.0f, 0.0f));
jd.ReferenceAngle = 0.0f;
jd.MotorSpeed = 0.05f * MathHelper.Pi;
jd.MaxMotorTorque = 1e8f;
jd.MotorEnabled = true;
World.AddJoint(jd);
}
示例2: OneSidedPlatformTest
private OneSidedPlatformTest()
{
//Ground
BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
// Platform
{
Body body = BodyFactory.CreateBody(World);
body.Position = new Vector2(0.0f, 10.0f);
PolygonShape shape = new PolygonShape(1);
shape.SetAsBox(3.0f, 0.5f);
_platform = body.CreateFixture(shape);
_top = 10.0f + 0.5f;
}
// Actor
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 12.0f);
_radius = 0.5f;
CircleShape shape = new CircleShape(_radius, 20);
_character = body.CreateFixture(shape);
body.LinearVelocity = new Vector2(0.0f, -50.0f);
}
}
示例3: WheelJointTest
private WheelJointTest()
{
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
PolygonShape shape = new PolygonShape(1);
shape.SetAsBox(0.5f, 2.0f);
Body body = new Body(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 7.0f);
body.CreateFixture(shape);
Vector2 axis = new Vector2(-1000.0f, -2.0f);
axis.Normalize();
WheelJoint jd = new WheelJoint(ground, body, new Vector2(0, 8.5f), axis);
jd.MotorSpeed = 1.0f;
jd.MaxMotorTorque = 1000.0f;
jd.MotorEnabled = true;
jd.SpringFrequencyHz = 1.0f;
jd.SpringDampingRatio = 0.2f;
World.AddJoint(jd);
PolygonShape shape2 = new PolygonShape(1);
shape2.SetAsBox(0.5f, 2.0f);
Body body2 = BodyFactory.CreatePolygon(World, shape2.Vertices, 0.5f);
body2.BodyType = BodyType.Dynamic;
body2.Position = new Vector2(10.0f, 7.0f);
}
}
示例4: Key
public Key(Rectangle pos, Map map)
: base(map)
{
Body BodyDec = new Body(map.PhysicalWorld);
BodyDec.BodyType = BodyType.Static;
PolygonShape S = new PolygonShape(1f);
S.SetAsBox(pos.Width / 2, pos.Height / 2);
Fixture = BodyDec.CreateFixture(S);
Fixture.Restitution = 1f;
Fixture.Friction = 10f;
this.Position = pos;
SetName("Key");
LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");
light = new PointLight()
{
IsEnabled = true,
Color = new Vector4(0.95f, .7f, .05f, 1f),
Power = power,
LightDecay = 350,
Position = new Vector3(Position.X, Position.Y, 20),
Direction = new Vector3(0,0, 0)
};
LE.AddLight(light);
}
示例5: Tank
protected Tank(
ISoundManager soundManager,
World world,
Collection<IDoodad> doodads,
Team team,
Vector2 position,
float rotation,
DoodadFactory doodadFactory)
{
this.soundManager = soundManager;
this.world = world;
this.doodadFactory = doodadFactory;
this.doodads = doodads;
this.body = BodyFactory.CreateBody(world, position, this);
this.body.Rotation = rotation;
this.body.BodyType = BodyType.Dynamic;
this.Team = team;
this.Heading = rotation;
this.activeMissiles = new List<Missile>();
this.powerup = PowerUpType.None;
var shape = new PolygonShape(0);
shape.SetAsBox(15 / Constants.PixelsPerMeter, 15 / Constants.PixelsPerMeter);
var fixture = this.body.CreateFixture(shape);
fixture.CollisionCategories = this.CollisionCategory;
fixture.CollidesWith = PhysicsConstants.MissileCategory;
if (this is PlayerControlledTank)
{
fixture.CollidesWith |= PhysicsConstants.ObstacleCategory | PhysicsConstants.PitCategory |
PhysicsConstants.SensorCategory;
}
}
示例6: PulleysTest
private PulleysTest()
{
//Ground
FixtureFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
const float a = 2.0f;
const float b = 4.0f;
const float y = 16.0f;
const float l = 12.0f;
PolygonShape shape = new PolygonShape(5);
shape.SetAsBox(a, b);
Body body1 = BodyFactory.CreateBody(World);
body1.BodyType = BodyType.Dynamic;
body1.Position = new Vector2(-10.0f, y);
body1.CreateFixture(shape);
Body body2 = BodyFactory.CreateBody(World);
body2.BodyType = BodyType.Dynamic;
body2.Position = new Vector2(10.0f, y);
body2.CreateFixture(shape);
Vector2 anchor1 = new Vector2(-10.0f, y + b);
Vector2 anchor2 = new Vector2(10.0f, y + b);
Vector2 groundAnchor1 = new Vector2(-10.0f, y + b + l);
Vector2 groundAnchor2 = new Vector2(10.0f, y + b + l);
_joint1 = new PulleyJoint(body1, body2, groundAnchor1, groundAnchor2, body1.GetLocalPoint(anchor1),
body2.GetLocalPoint(anchor2), 2.0f);
World.AddJoint(_joint1);
}
}
示例7: RedAlarmLamp
public RedAlarmLamp(Rectangle r, Map m)
: base(m)
{
Body BodyDec = new Body(m.PhysicalWorld);
BodyDec.BodyType = BodyType.Static;
PolygonShape S = new PolygonShape(1f);
S.SetAsBox(r.Width / 2, r.Height / 2);
Fixture = BodyDec.CreateFixture(S);
Fixture.Restitution = 1f;
Fixture.Friction = 10f;
Position = r;
SetName("RedAlarmLamp");
AlertLight = new SpotLight()
{
IsEnabled = true,
Color = new Vector4(0.9f, .1f, .1f, 1f),
Power = .6f,
LightDecay = 600,
Position = new Vector3(r.X, r.Y, 20),
SpotAngle = 1.5f,
SpotDecayExponent = 3,
Direction = new Vector3(0.244402379f, 0.969673932f, 0)
};
LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");
LE.AddLight(AlertLight);
}
示例8: Chest
public Chest(Rectangle r,Map m)
: base(m)
{
Body BodyDec = new Body(m.PhysicalWorld);
BodyDec.BodyType = BodyType.Static;
PolygonShape S = new PolygonShape(1f);
S.SetAsBox(r.Width / 2, r.Height / 2);
Fixture = BodyDec.CreateFixture(S);
Fixture.Restitution = 1f;
Fixture.Friction = 10f;
Position = r;
SetName("Chest");
items = new List<Item>();
ChestWindow = new Window(GeneralManager.GetPartialRect(0.4f, 0.2f, 0.2f, 0.6f));
ChestWindow.BgTex = GeneralManager.Textures["GUI/InGameGUI/ChestMenuBg"];
ChestWindow.Visible = false;
CloseButton = new Button(new Rectangle(ChestWindow.Position.Width - 32, 8, 24, 24), "", GeneralManager.Textures["GUI/InGameGUI/CloseButton"], Color.Gray, Color.White, null);
CloseButton.Action = CloseChestWindow;
ChestWindow.AddGUI(CloseButton );
list = new ListBox(new Rectangle(16,16,ChestWindow.Position.Width - 24,ChestWindow.Position.Height - 32));
ChestWindow.AddGUI(list);
Map.Parent.AddGUI(ChestWindow);
}
示例9: TilesTest
private TilesTest()
{
Stopwatch timer = new Stopwatch();
timer.Start();
{
const float a = 0.5f;
Body ground = BodyFactory.CreateBody(World, new Vector2(0, -a));
const int N = 200;
const int M = 10;
Vector2 position = Vector2.Zero;
position.Y = 0.0f;
for (int j = 0; j < M; ++j)
{
position.X = -N * a;
for (int i = 0; i < N; ++i)
{
PolygonShape shape = new PolygonShape(0);
shape.SetAsBox(a, a, position, 0.0f);
Fixture fix = ground.CreateFixture(shape);
++_fixtureCount;
position.X += 2.0f * a;
}
position.Y -= 2.0f * a;
}
}
{
const float a = 0.5f;
Vertices box = PolygonTools.CreateRectangle(a, a);
PolygonShape shape = new PolygonShape(box, 5);
Vector2 x = new Vector2(-7.0f, 0.75f);
Vector2 deltaX = new Vector2(0.5625f, 1.25f);
Vector2 deltaY = new Vector2(1.125f, 0.0f);
for (int i = 0; i < Count; ++i)
{
Vector2 y = x;
for (int j = i; j < Count; ++j)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = y;
body.CreateFixture(shape);
++_fixtureCount;
y += deltaY;
}
x += deltaX;
}
}
timer.Stop();
_createTime = timer.ElapsedMilliseconds;
}
示例10: createBlock
public void createBlock(Vector2 _position)
{
//body = BodyFactory.CreateBody(Game1.world, _position + new Vector2(8/Game1.scale, 8/Game1.scale));
body = BodyFactory.CreateBody(Game1.world, _position + new Vector2(8.05f / Game1.scale, 8.05f / Game1.scale));
//body = BodyFactory.CreateBody(Game1.world, _position + new Vector2(16f / Game1.scale, 16f / Game1.scale));
PolygonShape shape = new PolygonShape(1f);
//shape.SetAsBox(8/Game1.scale, 8/Game1.scale);
shape.SetAsBox(8.05f / Game1.scale, 8.05f / Game1.scale);
//shape.SetAsBox(16f / Game1.scale, 16f / Game1.scale);
body.CreateFixture(shape);
}
示例11: Pit
public Pit(World world, Vector2 position, float rotation, Rectangle source)
{
this.world = world;
this.body = BodyFactory.CreateBody(world, position, this);
this.body.Rotation = rotation;
var shape = new PolygonShape(0);
shape.SetAsBox(16 / Constants.PixelsPerMeter, 16 / Constants.PixelsPerMeter);
var fixture = this.body.CreateFixture(shape);
fixture.CollisionCategories = PhysicsConstants.PitCategory;
this.source = source;
}
示例12: TilesTest
private TilesTest()
{
{
const float a = 0.5f;
Body ground = BodyFactory.CreateBody(World, new Vector2(0, -a));
const int n = 200;
const int m = 10;
Vector2 position = Vector2.Zero;
position.Y = 0.0f;
for (int j = 0; j < m; ++j)
{
position.X = -n * a;
for (int i = 0; i < n; ++i)
{
PolygonShape shape = new PolygonShape(0);
shape.SetAsBox(a, a, position, 0.0f);
ground.CreateFixture(shape);
position.X += 2.0f * a;
}
position.Y -= 2.0f * a;
}
}
{
const float a = 0.5f;
Vertices box = PolygonTools.CreateRectangle(a, a);
PolygonShape shape = new PolygonShape(box, 5);
Vector2 x = new Vector2(-7.0f, 0.75f);
Vector2 deltaX = new Vector2(0.5625f, 1.25f);
Vector2 deltaY = new Vector2(1.125f, 0.0f);
for (int i = 0; i < Count; ++i)
{
Vector2 y = x;
for (int j = i; j < Count; ++j)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = y;
body.CreateFixture(shape);
y += deltaY;
}
x += deltaX;
}
}
}
示例13: PrismaticTest
private PrismaticTest()
{
Body ground;
{
ground = BodyFactory.CreateBody(World);
PolygonShape shape3 = new PolygonShape(0);
shape3.SetAsEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape3);
}
PolygonShape shape = new PolygonShape(5);
shape.SetAsBox(2.0f, 0.5f);
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 10.0f);
body.CreateFixture(shape);
_fixedJoint = new FixedPrismaticJoint(body, body.Position, new Vector2(0.5f, 1.0f));
_fixedJoint.MotorSpeed = 5.0f;
_fixedJoint.MaxMotorForce = 1000.0f;
_fixedJoint.MotorEnabled = true;
_fixedJoint.LowerLimit = -10.0f;
_fixedJoint.UpperLimit = 20.0f;
_fixedJoint.LimitEnabled = true;
World.AddJoint(_fixedJoint);
PolygonShape shape2 = new PolygonShape(5);
shape2.SetAsBox(2.0f, 0.5f);
Body body2 = BodyFactory.CreateBody(World);
body2.BodyType = BodyType.Dynamic;
body2.Position = new Vector2(10.0f, 10.0f);
body2.CreateFixture(shape2);
_joint = new PrismaticJoint(ground, body2, ground.GetLocalPoint(body2.Position), Vector2.Zero,
new Vector2(0.5f, 1.0f));
_joint.MotorSpeed = 5.0f;
_joint.MaxMotorForce = 1000.0f;
_joint.MotorEnabled = true;
_joint.LowerLimit = -10.0f;
_joint.UpperLimit = 20.0f;
_joint.LimitEnabled = true;
World.AddJoint(_joint);
}
示例14: WindowController
public WindowController( World w, Vector2 r, Vector2 size, WindowSprite s )
{
_fsBody = w.NewBody();
_fsBody.Position = r;
PolygonShape shape = new PolygonShape(1.0f);
shape.SetAsBox(size.X * 2, size.Y * 2);
_fsFixture = _fsBody.CreateFixture(shape, this);
_fsFixture.IsSensor = true;
_fsFixture.OnCollision += BehaviorCollided;
sprite = s;
}
示例15: Wheel
public Wheel(World world)
{
//_mGroundAreas = new List<WaterArea>();
Body = new Body(world) {BodyType = BodyType.Dynamic, IsSensor = true, UserData = this};
var shape = new PolygonShape(1);
shape.SetAsBox(ConvertUnits.ToMeters(0.03125f), ConvertUnits.ToMeters(0.125f));
var fixture = Body.CreateFixture(shape);
fixture.UserData = this;
Body.UserData = this;
_mCurrentTraction = 1;
_mCurrentDrag = 1;
}