示例#1
0
        /// <summary>
        /// Set the mass properties to override the mass properties of the fixtures. Note that this changes
        /// the center of mass position. Note that creating or destroying fixtures can also alter the mass.
        /// This function has no effect if the body isn't dynamic.
        /// </summary>
        /// <param name="massData">the mass properties.</param>
        public void SetMassData(MassData massData)
        {
            // TODO_ERIN adjust linear velocity and torque to account for movement of center.
            Debug.Assert(World.Locked == false);
            if (World.Locked)
            {
                return;
            }

            if (m_type != BodyType.Dynamic)
            {
                return;
            }

            InvMass = 0.0f;
            I       = 0.0f;
            InvI    = 0.0f;

            Mass = massData.Mass;
            if (Mass <= 0.0f)
            {
                Mass = 1f;
            }

            InvMass = 1.0f / Mass;

            if (massData.I > 0.0f && (Flags & TypeFlags.FixedRotation) == 0)
            {
                I = massData.I - Mass * Vec2.Dot(massData.Center, massData.Center);
                Debug.Assert(I > 0.0f);
                InvI = 1.0f / I;
            }

            Vec2 oldCenter = World.Pool.PopVec2();

            // Move center of mass.
            oldCenter.Set(Sweep.C);
            Sweep.LocalCenter.Set(massData.Center);
            // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
            Transform.MulToOutUnsafe(Xf, Sweep.LocalCenter, Sweep.C0);
            Sweep.C.Set(Sweep.C0);

            // Update center of mass velocity.
            // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
            Vec2 temp = World.Pool.PopVec2();

            temp.Set(Sweep.C).SubLocal(oldCenter);
            Vec2.CrossToOut(m_angularVelocity, temp, temp);
            m_linearVelocity.AddLocal(temp);

            World.Pool.PushVec2(2);
        }
示例#2
0
 /// <summary>
 /// Set this as a single edge.
 /// </summary>
 /// <param name="v1"></param>
 /// <param name="v2"></param>
 /// <deprecated></deprecated>
 public void SetAsEdge(Vec2 v1, Vec2 v2)
 {
     VertexCount = 2;
     Vertices[0].Set(v1);
     Vertices[1].Set(v2);
     Centroid.Set(v1).AddLocal(v2).MulLocal(0.5f);
     // = 0.5f * (v1 + v2);
     Normals[0].Set(v2).SubLocal(v1);
     Vec2.CrossToOut(Normals[0], 1f, Normals[0]);
     // m_normals[0] = Cross(v2 - v1, 1.0f);
     Normals[0].Normalize();
     Normals[1].Set(Normals[0]).NegateLocal();
 }
示例#3
0
 public void GetLinearVelocityFromWorldPointToOut(Vec2 worldPoint, Vec2 result)
 {
     result.Set(worldPoint).SubLocal(Sweep.C);
     Vec2.CrossToOut(m_angularVelocity, result, result);
     result.AddLocal(m_linearVelocity);
 }