Пример #1
0
        void Demo6()
        {
            waitHandle.Reset();
            Reset();
            AddGravityField();

            List<Body> chain = AddChain(new Vector2D(400, 50), 100, 30, 200, 10, 800);
            Vector2D point = new Vector2D(300, 50);

            Body Anchor = AddRectangle(60, 60, float.PositiveInfinity, new ALVector2D(0, point));
            Anchor.IgnoresGravity = true;
            HingeJoint joint = new HingeJoint(chain[0], Anchor, point, new Lifespan());
            engine.AddJoint(joint);
            Console.WriteLine(count);
            waitHandle.Set();
        }
Пример #2
0
        void Demo8()
        {
            waitHandle.Reset();
            Reset();
            AddGravityField();

            float boxlength = 50;
            float spacing = 4;
            float anchorLenght = 30;
            float anchorGap = (boxlength / 2) + spacing + (anchorLenght / 2);
            List<Body> chain = AddChain(new Vector2D(200, 500), boxlength, 20, 200, spacing, 600);

            Vector2D point2 = new Vector2D(chain[chain.Count - 1].State.Position.Linear.X + anchorGap, 500);
            Body end2 = AddRectangle(anchorLenght, anchorLenght, float.PositiveInfinity, new ALVector2D(0, point2));
            end2.IgnoresGravity = true;
            HingeJoint joint2 = new HingeJoint(chain[chain.Count - 1], end2, point2, new Lifespan());
            joint2.SplitImpulse = true;
            engine.AddJoint(joint2);

            Vector2D point1 = new Vector2D(chain[0].State.Position.Linear.X - anchorGap, 500);
            Body end1 = AddRectangle(anchorLenght, anchorLenght, float.PositiveInfinity, new ALVector2D(0, point1));
            end1.IgnoresGravity = true;
            HingeJoint joint1 = new HingeJoint(chain[0], end1, point1, new Lifespan());
            joint1.SplitImpulse = true;
            engine.AddJoint(joint1);
            end2.State.Position.Linear.X -= 10;
            end1.State.Position.Linear.X += 10;
            end2.ApplyMatrix();
            end1.ApplyMatrix();

            AddTower2();


            Console.WriteLine(count);
            waitHandle.Set();
        }
Пример #3
0
 List<Body> AddChain(Vector2D position, float boxLenght, float boxWidth, float boxMass, float spacing, float length)
 {
     List<Body> bodies = new List<Body>();
     Body last = null;
     for (float x = 0; x < length; x += boxLenght + spacing, position.X += boxLenght + spacing)
     {
         Body current = AddRectangle(boxWidth, boxLenght, boxMass, new ALVector2D(0, position));
         bodies.Add(current);
         if (last != null)
         {
             Vector2D anchor = (current.State.Position.Linear + last.State.Position.Linear) * .5f;
             HingeJoint joint = new HingeJoint(last, current, anchor, new Lifespan());
             joint.SplitImpulse = true;
             this.engine.AddJoint(joint);
         }
         last = current;
     }
     return bodies;
 }