Пример #1
0
        /// <summary>
        /// Attach a fixture to this shape.
        /// </summary>
        /// <param name="def">The fixture definition to add.</param>
        /// <returns>The created Fixture object.</returns>
        public Fixture CreateFixture(FixtureDef def)
        {
            def.SetShape(def.Shape.Lock());
            Fixture fixture;

            using (var structPtr = new StructToPtrMarshaller(def.Internal))
                fixture = Fixture.FromPtr(NativeMethods.b2body_createfixture(_bodyPtr, structPtr.Pointer));
            def.Shape.Unlock();
            return(fixture);
        }
Пример #2
0
        public Body[] GenerateBodies(World world, Vec2 basePosition, FixtureDef def)
        {
            if (_vecs.Count <= 1)
            {
                throw new ArgumentOutOfRangeException("Vecs");
            }

            Body[] bodies = new Body[_vecs.Count - 1];

            for (int i = 0; i < _vecs.Count - 1; ++i)
            {
                PolygonShape edge = new PolygonShape(_vecs[i], _vecs[i + 1]);

                BodyDef bd = new BodyDef();
                bd.Position = basePosition;

                bodies[i] = world.CreateBody(bd);
                bodies[i].CreateFixture(new FixtureDef(edge, 0, def.Restitution, def.Friction, false, def.UserData));
            }

            return(bodies);
        }