Ejemplo n.º 1
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.0d;
     m_frequencyHz  = def.frequencyHz;
     m_dampingRatio = def.dampingRatio;
     m_gamma        = 0.0d;
     m_bias         = 0.0d;
 }
        public ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def) : base(argWorld.getPool(), 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 double[bodies.Length];
            for (int i = 0; i < targetLengths.Length; ++i)
            {
                int    next = (i == targetLengths.Length - 1) ? 0 : i + 1;
                double dist = bodies[i].getWorldCenter().sub(bodies[next].getWorldCenter()).length();
                targetLengths[i] = dist;
            }
            targetVolume = getBodyArea();

            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)
            {
                var 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.0d;
                    djd.dampingRatio     = def.dampingRatio; // 50.0d;
                    djd.collideConnected = def.collideConnected;
                    djd.initialize(bodies[i], bodies[next], bodies[i].getWorldCenter(),
                                   bodies[next].getWorldCenter());
                    distanceJoints[i] = (DistanceJoint)world.createJoint(djd);
                }
            }
            else
            {
                distanceJoints = def.joints.ToArray();
            }

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