SetAsBox() public method

Build vertices to represent an axis-aligned box.
public SetAsBox ( float hx, float hy ) : void
hx float The half-width
hy float The half-height.
return void
Exemplo n.º 1
0
		public CCDTest()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(10.0f, 0.2f);
				sd.Density = 0.0f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -0.2f);
				Body body = _world.CreateBody(bd);
				body.CreateFixture(sd);

				sd.SetAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.2f), 0.0f);
				body.CreateFixture(sd);
			}
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(2.0f, 0.1f);
				sd.Density = 1.0f;
				sd.Restitution = 0;

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 20.0f);
				Body body = _world.CreateBody(bd);
				body.CreateFixture(sd);
				body.SetMassFromShapes();
				body.SetLinearVelocity(new Vec2(0.0f, -100.0f));
				body.SetAngularVelocity(Box2DX.Common.Math.Random(-50.0f, 50.0f));
			}
		}
Exemplo n.º 2
0
        public DamageBox(Player creator, float x, float y, float width, float height)
            : base(creator, x, y)
        {
            PolygonDef def = new PolygonDef();
            def.SetAsBox(width / 2, height / 2, new Vec2(x, y), 0);
            def.IsSensor = true;
            def.UserData = this;

            fixture = creator.body.CreateFixture(def);
            fixture.UserData = this;
        }
Exemplo n.º 3
0
		public VerticalStack()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f, new Vec2(0.0f, -10.0f), 0.0f);

				BodyDef bd = new BodyDef();
				Body ground = _world.CreateBody(bd);
				ground.CreateFixture(sd);

				sd.SetAsBox(0.1f, 10.0f, new Vec2(20.0f, 10.0f), 0.0f);
				ground.CreateFixture(sd);
			}

			float[] xs = new float[] { 0.0f, -10.0f, -5.0f, 5.0f, 10.0f };

			for (int j = 0; j < 5; ++j)
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.5f, 0.5f);
				sd.Density = 1.0f;
				sd.Friction = 0.3f;

				for (int i = 0; i < 16; ++i)
				{
					BodyDef bd = new BodyDef();
				
					bd.Position.Set(xs[j], 0.752f + 1.54f * i);
					Body body = _world.CreateBody(bd);

					body.CreateFixture(sd);
					body.SetMassFromShapes();
				}
			}

			_bullet = null;
		}
Exemplo n.º 4
0
		public Pyramid()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);
				Body ground = _world.CreateBody(bd);
				ground.CreateFixture(sd);
			}

			{
				PolygonDef sd = new PolygonDef();
				float a = 0.5f;
				sd.SetAsBox(a, a);
				sd.Density = 5.0f;

				Vec2 x = new Vec2(-10.0f, 0.75f);
				Vec2 y;
				Vec2 deltaX = new Vec2(0.5625f, 2.0f);
				Vec2 deltaY = new Vec2(1.125f, 0.0f);

				for (int i = 0; i < 25; ++i)
				{
					y = x;

					for (int j = i; j < 25; ++j)
					{
						BodyDef bd = new BodyDef();
						bd.Position = y;
						Body body = _world.CreateBody(bd);
						body.CreateFixture(sd);
						body.SetMassFromShapes();

						y += deltaY;
					}

					x += deltaX;
				}
			}
		}
Exemplo n.º 5
0
		public SimpleTest()
		{
			// Define the ground body.
			BodyDef groundBodyDef = new BodyDef();
			groundBodyDef.Position.Set(0.0f, -10.0f);

			// Call the body factory which creates the ground box shape.
			// The body is also added to the world.
			Body groundBody = _world.CreateBody(groundBodyDef);

			// Define the ground box shape.
			PolygonDef groundShapeDef = new PolygonDef();

			// The extents are the half-widths of the box.
			groundShapeDef.SetAsBox(50.0f, 10.0f);

			// Add the ground shape to the ground body.
			groundBody.CreateFixture(groundShapeDef);

			// Define the dynamic body. We set its position and call the body factory.
			BodyDef bodyDef = new BodyDef();
			bodyDef.Position.Set(0.0f, 4.0f);
			Body body = _world.CreateBody(bodyDef);

			// Define another box shape for our dynamic body.
			PolygonDef shapeDef = new PolygonDef();
			shapeDef.SetAsBox(1.0f, 1.0f);
			
			// Set the box density to be non-zero, so it will be dynamic.
			shapeDef.Density = 1.0f;

			// Override the default friction.
			shapeDef.Friction = 0.3f;

			// Add the shape to the body.
			body.CreateFixture(shapeDef);

			// Now tell the dynamic body to compute it's mass properties base
			// on its shape.
			body.SetMassFromShapes();			
		}
Exemplo n.º 6
0
        public FrictionTest()
        {
            // Define the ground body.
            BodyDef groundBodyDef = new BodyDef();
            groundBodyDef.Position.Set(0.0f, -10.0f);

            // Call the body factory which creates the ground box shape.
            // The body is also added to the world.
            Body groundBody = _world.CreateBody(groundBodyDef);

            // Define the ground box shape.
            PolygonDef groundShapeDef = new PolygonDef();

            // The extents are the half-widths of the box.
            groundShapeDef.SetAsBox(50.0f, 10.0f);

            // Add the ground shape to the ground body.
            groundBody.CreateFixture(groundShapeDef);

            // Define the dynamic body. We set its position and call the body factory.
            BodyDef bodyDef = new BodyDef();
            bodyDef.Position.Set(1.0f, 2.0f);
            Body bodyfast = _world.CreateBody(bodyDef);

            // Define another box shape for our dynamic body.
            PolygonDef shapeDef = new PolygonDef();
            shapeDef.SetAsBox(1.0f, 1.0f);
            shapeDef.Density = 1.0f;
            shapeDef.Friction = 0.3f;
            bodyfast.CreateFixture(shapeDef);
            bodyfast.SetMassFromShapes();

            bodyDef.Position.Set(-1.0f, 2.0f);
            Body bodyslow = _world.CreateBody(bodyDef);
            shapeDef.Friction = 0.8f;
            bodyslow.CreateFixture(shapeDef);
            bodyslow.SetMassFromShapes();

            bodyslow.SetLinearVelocity(new Vec2(-3, 0));
            bodyfast.SetLinearVelocity(new Vec2(3, 0));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called to register this block with the collision contexts, etc.
        /// </summary>
        /// <param name="arena"></param>
        public void Bind(LoadableBattleArena arena)
        {
            // Define the ground box shape.
            PolygonDef groundShapeDef = new PolygonDef();
            groundShapeDef.SetAsBox(Width / 2, Height / 2, new Box2DX.Common.Vec2(Position.X, Position.Y), 0);

            // Add the ground shape to the ground body.
            Fixture fix = arena.GroundBody.CreateFixture(groundShapeDef);

            fix.UserData = arena;
            fix.Filter.CategoryBits = (ushort)Layer;
        }