コード例 #1
0
ファイル: RigidComposite.cs プロジェクト: darwin/silverstunts
        public RigidComposite( Engine engine, params Particle[] particles )
        {
            this.particles = particles;

            foreach ( Particle particle in particles )
            {
                engine.Add( particle );
            }

            for ( int index = 0; index < particles.Length; index += 2 )
            {
                int index1 = ( index + 1 < particles.Length ) ? index + 1 : 0;
                int index2 = ( index1 + 1 < particles.Length ) ? index1 + 1 : 0;

                AngularConstraint constraint = new AngularConstraint(
                    particles[ index ], particles[ index1 ], particles[ index2 ] );

                engine.Add( constraint );
            }
        }
コード例 #2
0
ファイル: Bike.cs プロジェクト: darwin/silverstunts
        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);
        }