Initialize() публичный Метод

Initialize the bodies, anchors, and length using the world anchors.
public Initialize ( Body b1, Body b2, Vec2 anchor1, Vec2 anchor2 ) : void
b1 Body First body
b2 Body Second body
anchor1 Box2D.Common.Vec2 World anchor on first body
anchor2 Box2D.Common.Vec2 World anchor on second body
Результат void
Пример #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;
        }
Пример #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;
        }