Definition for a {@link ConstantVolumeJoint}, which connects a group a bodies together so they maintain a constant volume within them.
Inheritance: JointDef
Example #1
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();
                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;
        }
Example #3
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();
                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;
        }