示例#1
0
        ///<summary>
        /// Warning: This method is locked during callbacks.
        /// </summary>>
        /// <exception cref="System.InvalidOperationException">Thrown when the world is Locked/Stepping.</exception>
        public void Add(Fixture fixture)
        {
            if (World != null && World.IsLocked)
            {
                throw new WorldLockedException("Cannot add fixtures to a body when the World is locked.");
            }
            if (fixture == null)
            {
                throw new ArgumentNullException("fixture");
            }
            if (fixture.Body != null)
            {
                if (fixture.Body == this)
                {
                    throw new ArgumentException("You are adding the same fixture more than once.", "fixture");
                }
                else
                {
                    throw new ArgumentException("fixture belongs to another body.", "fixture");
                }
            }

            fixture.Body = this;
            this.FixtureList.Add(fixture);
#if DEBUG
            if (fixture.Shape.ShapeType == ShapeType.Polygon)
            {
                ((PolygonShape)fixture.Shape).Vertices.AttachedToBody = true;
            }
#endif

            // Adjust mass properties if needed.
            if (fixture.Shape._density > 0.0f)
            {
                ResetMassData();
            }

            if (World != null)
            {
                if (Enabled)
                {
                    IBroadPhase broadPhase = World.ContactManager.BroadPhase;
                    fixture.CreateProxies(broadPhase, ref _xf);
                }

                // Let the world know we have a new fixture. This will cause new contacts
                // to be created at the beginning of the next time step.
                World._worldHasNewFixture = true;

                if (World.FixtureAdded != null)
                {
                    World.FixtureAdded(World, this, fixture);
                }
            }
        }
示例#2
0
文件: Body.cs 项目: jwmcglynn/float
        /// <summary>
        /// Creates a fixture and attach it to this body.
        /// If the density is non-zero, this function automatically updates the mass of the body.
        /// Contacts are not created until the next time step.
        /// Warning: This function is locked during callbacks.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="density">The density.</param>
        /// <returns></returns>
        public Fixture CreateFixture(Shape shape, float density)
        {
            Debug.Assert(World.IsLocked == false);
            if (World.IsLocked)
            {
                return(null);
            }

            Fixture fixture = new Fixture(this, shape, density);

            if ((Flags & BodyFlags.Active) == BodyFlags.Active)
            {
                BroadPhase broadPhase = World.ContactManager.BroadPhase;
                fixture.CreateProxies(broadPhase, ref Xf);
            }

            FixtureList.Add(fixture);
            fixture.Body = this;

            // Adjust mass properties if needed.
            if (fixture.Density > 0.0f)
            {
                ResetMassData();
            }

            // Let the world know we have a new fixture. This will cause new contacts
            // to be created at the beginning of the next time step.
            World.Flags |= WorldFlags.NewFixture;

            if (World.FixtureAdded != null)
            {
                World.FixtureAdded(fixture);
            }

            return(fixture);
        }
示例#3
0
        public void PopulateWorld(World w) {


            foreach (Body b in bodyList) {
                
                b.setWorld(w);

                foreach (Fixture f in b.FixtureList)
                {
                    f.Shape.ComputeProperties();
                    w.FixtureAdded(f);
                }

                float mass = b.Mass;
                //b.ResetMassData();
                b.Mass = mass;
                b.Enabled = true;
                b.Awake = true;
                w.AddBody(b); 
                //w.BodyList.Add(b);
            }

            w.ProcessChanges();

            foreach (Joint j in jointList)
            {
                w.AddJoint(j);
            }

            w.ProcessChanges();

        }