Distance joint definition. This requires defining an anchor point on both bodies and the non-zero length of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game.
Inheritance: JointDef
        public ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def)
            : base(argWorld.Pool, def)
        {
            world = argWorld;
            if (def.Bodies.Count <= 2)
            {
                throw new ArgumentException("You cannot create a constant volume joint with less than three bodies.");
            }
            Bodies = def.Bodies.ToArray();

            TargetLengths = new float[Bodies.Length];
            for (int i = 0; i < TargetLengths.Length; ++i)
            {
                int next = (i == TargetLengths.Length - 1) ? 0 : i + 1;
                float dist = Bodies[i].WorldCenter.Sub(Bodies[next].WorldCenter).Length();
                TargetLengths[i] = dist;
            }
            TargetVolume = Area;

            if (def.Joints != null && def.Joints.Count != def.Bodies.Count)
            {
                throw new ArgumentException("Incorrect joint definition.  Joints have to correspond to the bodies");
            }
            if (def.Joints == null)
            {
                DistanceJointDef djd = new DistanceJointDef();
                Joints = new DistanceJoint[Bodies.Length];
                for (int i = 0; i < TargetLengths.Length; ++i)
                {
                    int next = (i == TargetLengths.Length - 1) ? 0 : i + 1;
                    djd.FrequencyHz = def.FrequencyHz; // 20.0f;
                    djd.DampingRatio = def.DampingRatio; // 50.0f;
                    djd.Initialize(Bodies[i], Bodies[next], Bodies[i].WorldCenter, Bodies[next].WorldCenter);
                    Joints[i] = (DistanceJoint)world.CreateJoint(djd);
                }
            }
            else
            {
                Joints = def.Joints.ToArray();
            }

            FrequencyHz = def.FrequencyHz;
            DampingRatio = def.DampingRatio;

            Normals = new Vec2[Bodies.Length];
            for (int i = 0; i < Normals.Length; ++i)
            {
                Normals[i] = new Vec2();
            }

            this.BodyA = Bodies[0];
            this.BodyB = Bodies[1];
            this.CollideConnected = false;
        }
Beispiel #2
0
        public ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def)
            : base(argWorld.Pool, def)
        {
            world = argWorld;
            if (def.Bodies.Count <= 2)
            {
                throw new ArgumentException("You cannot create a constant volume joint with less than three bodies.");
            }
            Bodies = def.Bodies.ToArray();

            TargetLengths = new float[Bodies.Length];
            for (int i = 0; i < TargetLengths.Length; ++i)
            {
                int   next = (i == TargetLengths.Length - 1) ? 0 : i + 1;
                float dist = Bodies[i].WorldCenter.Sub(Bodies[next].WorldCenter).Length();
                TargetLengths[i] = dist;
            }
            TargetVolume = Area;

            if (def.Joints != null && def.Joints.Count != def.Bodies.Count)
            {
                throw new ArgumentException("Incorrect joint definition.  Joints have to correspond to the bodies");
            }
            if (def.Joints == null)
            {
                DistanceJointDef djd = new DistanceJointDef();
                Joints = new DistanceJoint[Bodies.Length];
                for (int i = 0; i < TargetLengths.Length; ++i)
                {
                    int next = (i == TargetLengths.Length - 1) ? 0 : i + 1;
                    djd.FrequencyHz  = def.FrequencyHz;  // 20.0f;
                    djd.DampingRatio = def.DampingRatio; // 50.0f;
                    djd.Initialize(Bodies[i], Bodies[next], Bodies[i].WorldCenter, Bodies[next].WorldCenter);
                    Joints[i] = (DistanceJoint)world.CreateJoint(djd);
                }
            }
            else
            {
                Joints = def.Joints.ToArray();
            }

            FrequencyHz  = def.FrequencyHz;
            DampingRatio = def.DampingRatio;

            Normals = new Vec2[Bodies.Length];
            for (int i = 0; i < Normals.Length; ++i)
            {
                Normals[i] = new Vec2();
            }

            this.BodyA            = Bodies[0];
            this.BodyB            = Bodies[1];
            this.CollideConnected = false;
        }
        public ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def)
            : base(argWorld.Pool, def)
        {
            world = argWorld;
            if (def.bodies.Count <= 2)
            {
                throw new ArgumentException("You cannot create a constant volume joint with less than three bodies.");
            }
            bodies = def.bodies.ToArray();

            targetLengths = new float[bodies.Length];
            for (int i = 0; i < targetLengths.Length; ++i)
            {
                int next = (i == targetLengths.Length - 1) ? 0 : i + 1;
                float dist = bodies[i].WorldCenter.sub(bodies[next].WorldCenter).length();
                targetLengths[i] = dist;
            }
            targetVolume = Area;

            if (def.joints != null && def.joints.Count != def.bodies.Count)
            {
                throw new ArgumentException("Incorrect joint definition.  Joints have to correspond to the bodies");
            }
            if (def.joints == null)
            {
                DistanceJointDef djd = new DistanceJointDef();
                distanceJoints = new DistanceJoint[bodies.Length];
                for (int i = 0; i < targetLengths.Length; ++i)
                {
                    int next = (i == targetLengths.Length - 1) ? 0 : i + 1;
                    djd.frequencyHz = def.frequencyHz; // 20.0f;
                    djd.dampingRatio = def.dampingRatio; // 50.0f;
                    djd.initialize(bodies[i], bodies[next], bodies[i].WorldCenter, bodies[next].WorldCenter);
                    distanceJoints[i] = (DistanceJoint)world.createJoint(djd);
                }
            }
            else
            {
                distanceJoints = def.joints.ToArray();
            }

            frequencyHz = def.frequencyHz;
            dampingRatio = def.dampingRatio;

            normals = new Vec2[bodies.Length];
            for (int i = 0; i < normals.Length; ++i)
            {
                normals[i] = new Vec2();
            }

            this.m_bodyA = bodies[0];
            this.m_bodyB = bodies[1];
            this.m_collideConnected = false;
        }
 public DistanceJoint(IWorldPool argWorld, DistanceJointDef def)
     : base(argWorld, def)
 {
     LocalAnchorA = def.LocalAnchorA.Clone();
     LocalAnchorB = def.LocalAnchorB.Clone();
     Length       = def.Length;
     Impulse      = 0.0f;
     FrequencyHz  = def.FrequencyHz;
     DampingRatio = def.DampingRatio;
     Gamma        = 0.0f;
     Bias         = 0.0f;
 }
Beispiel #5
0
 public DistanceJoint(IWorldPool argWorld, DistanceJointDef def)
     : base(argWorld, def)
 {
     m_localAnchorA = def.localAnchorA.Clone();
     m_localAnchorB = def.localAnchorB.Clone();
     m_length = def.length;
     m_impulse = 0.0f;
     m_frequencyHz = def.frequencyHz;
     m_dampingRatio = def.dampingRatio;
     m_gamma = 0.0f;
     m_bias = 0.0f;
 }
Beispiel #6
0
 public DistanceJoint(IWorldPool argWorld, DistanceJointDef def)
     : base(argWorld, def)
 {
     LocalAnchorA = def.LocalAnchorA.Clone();
     LocalAnchorB = def.LocalAnchorB.Clone();
     Length = def.Length;
     Impulse = 0.0f;
     FrequencyHz = def.FrequencyHz;
     DampingRatio = def.DampingRatio;
     Gamma = 0.0f;
     Bias = 0.0f;
 }