Ejemplo n.º 1
0
        public SpringBox(
            double px,
            double py,
            double w,
            double h,
            out PhysicsObject[] objs)
        {
            // top left
            p0 = new RectangleParticle(px - w / 2, py - h / 2, 1, 1);
            // top right
            p1 = new RectangleParticle(px + w / 2, py - h / 2, 1, 1);
            // bottom right
            p2 = new RectangleParticle(px + w / 2, py + h / 2, 1, 1);
            // bottom left
            p3 = new RectangleParticle(px - w / 2, py + h / 2, 1, 1);

            p0.Visible = false;
            p1.Visible = false;
            p2.Visible = false;
            p3.Visible = false;

            objs = new PhysicsObject[10];
            objs[0] = p0;
            objs[1] = p1;
            objs[2] = p2;
            objs[3] = p3;

            // edges
            objs[4] = new SpringConstraint(p0, p1);
            objs[5] = new SpringConstraint(p1, p2);
            objs[6] = new SpringConstraint(p2, p3);
            objs[7] = new SpringConstraint(p3, p0);

            // crossing braces
            objs[8] = new SpringConstraint(p0, p2);
            objs[9] = new SpringConstraint(p1, p3);
        }
Ejemplo n.º 2
0
        protected void Create(double x, double y)
        {
            // create the bicycle
            double leftX = x - 18;
            double rightX = x + 18;
            double widthX = rightX - leftX;
            double midX = leftX + (widthX / 2);
            double topY = y + 0;

            // wheels
            wheelA = new Wheel(leftX, topY, 12);
            Add(wheelA, "wheelA");

            wheelB = new Wheel(rightX, topY, 12);
            Add(wheelB, "wheelB");

            // body
            PhysicsObject[] objs;
            SpringBox rectA = new SpringBox(midX, topY, widthX, 15, out objs);
            foreach (PhysicsObject o in objs)
            {
                Add(o);
            }

            // wheel struts
            SpringConstraint conn1 = new SpringConstraint(wheelA, rectA.P3);
            Add(conn1);

            SpringConstraint conn2 = new SpringConstraint(wheelB, rectA.P2);
            Add(conn2);

            SpringConstraint conn1a = new SpringConstraint(wheelA, rectA.P0);
            Add(conn1a);

            SpringConstraint conn2a = new SpringConstraint(wheelB, rectA.P1);
            Add(conn2a);

            // triangle top of car
            personHead = new CircleParticle(midX, topY - 30, 5);
            Add(personHead);

            personHead.Contact += delegate(object sender, EventArgs e)
            {
                Kill();
            };

            sHeadToWheelA = new SpringConstraint(personHead, wheelA);
            Add(sHeadToWheelA);

            sHeadToWheelB = new SpringConstraint(personHead, wheelB);
            Add(sHeadToWheelB);

            // angular constraint for triangle top
            sBikeAngular = new AngularConstraint(wheelA, personHead, wheelB);
            Add(sBikeAngular);

            angDefault = sBikeAngular.TargetTheta;

            personBody = new CircleParticle(midX - 5, topY - 20, 5);
            personLegs = new CircleParticle(midX, topY - 5, 5);
            aPose = new AngularConstraint(personHead, personBody, personLegs);

            sHeadToBody = new SpringConstraint(personHead, personBody);
            sHeadToBody.RestLength = 12;
            Add(sHeadToBody);
            sBodyToLegs = new SpringConstraint(personBody, personLegs);
            sBodyToLegs.RestLength = 12;
            Add(sBodyToLegs);

            Add(personBody);
            Add(personLegs);

            sLegsToWheelB = new SpringConstraint(personLegs, wheelB);
            sLegsToWheelB.RestLength = 20;
            Add(sLegsToWheelB);

            sLegsToWheelA = new SpringConstraint(personLegs, wheelA);
            sLegsToWheelA.RestLength = 20;
            Add(sLegsToWheelA);
        }