Convex polygon. The vertices must be ordered so that the outside of the polygon is on the right side of the edges (looking along the edge from start to end).
Inheritance: FixtureDef
Exemple #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));
			}
		}
Exemple #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;
        }
Exemple #3
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;
				}
			}
		}
Exemple #4
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();			
		}
Exemple #5
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));
        }
Exemple #6
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;
		}
Exemple #7
0
        public void Create(BroadPhase broadPhase, Body body, XForm xf, FixtureDef def)
        {
            UserData    = def.UserData;
            Friction    = def.Friction;
            Restitution = def.Restitution;
            Density     = def.Density;

            _body = body;
            _next = null;

            Filter = def.Filter;

            _isSensor = def.IsSensor;

            _type = def.Type;

            // Allocate and initialize the child shape.
            switch (_type)
            {
            case ShapeType.CircleShape:
            {
                CircleShape circle    = new CircleShape();
                CircleDef   circleDef = (CircleDef)def;
                circle._position = circleDef.LocalPosition;
                circle._radius   = circleDef.Radius;
                _shape           = circle;
            }
            break;

            case ShapeType.PolygonShape:
            {
                PolygonShape polygon    = new PolygonShape();
                PolygonDef   polygonDef = (PolygonDef)def;
                polygon.Set(polygonDef.Vertices, polygonDef.VertexCount);
                _shape = polygon;
            }
            break;

            case ShapeType.EdgeShape:
            {
                EdgeShape edge    = new EdgeShape();
                EdgeDef   edgeDef = (EdgeDef)def;
                edge.Set(edgeDef.Vertex1, edgeDef.Vertex2);
                _shape = edge;
            }
            break;

            default:
                Box2DXDebug.Assert(false);
                break;
            }

            // Create proxy in the broad-phase.
            AABB aabb;

            _shape.ComputeAABB(out aabb, xf);

            bool inRange = broadPhase.InRange(aabb);

            // You are creating a shape outside the world box.
            Box2DXDebug.Assert(inRange);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }
        /// <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;
        }