Example #1
0
        public Motor(AbstractParticle attach, float radius, int color)
        {
            wheel = new WheelParticle(attach.PX, attach.PY - .01f, radius);
            wheel.SetStyle(0, 0, Color.FromArgb(255 / 2, 255, 0, 0).ToArgb());
            SpringConstraint axle = new SpringConstraint(wheel, attach);

            _rimA = new CircleParticle(0, 0, 2, true);
            _rimB = new CircleParticle(0, 0, 2, true);
            _rimC = new CircleParticle(0, 0, 2, true);

            wheel.Collidable = false;
            _rimA.Collidable = false;
            _rimB.Collidable = false;
            _rimC.Collidable = false;

            this.Particles.Add(_rimA);
            this.Particles.Add(_rimB);
            this.Particles.Add(_rimC);
            this.Particles.Add(wheel);
            this.Constraints.Add(axle);

            this.color = color;
            this.radius = radius;

            // run it once to make sure the rim particles are in the right place
            run();
        }
Example #2
0
        public Rotator(int colA, int colB)
            : base(false)
        {
            this.CollideInternal = true;

            ctr = new Vector(555, 175);
            rectComposite = new RectComposite(ctr, colA, colB);
            addComposite(rectComposite);

            circA = new CircleParticle(ctr.X, ctr.Y, 5, false, 1, 0.3f, 0);
            circA.SetStyle(1, colA, colB);
            this.Particles.Add(circA);

            rectA = new RectangleParticle(555, 160, 10, 10, 0, false, 3, 0.3f, 0);
            rectA.SetStyle(1, colA, colB);
            this.Particles.Add(rectA);

            connectorA = new SpringConstraint(rectComposite.PA, rectA, 1, false, 1, 1, false);
            connectorA.SetStyle(2, colB);
            this.Constraints.Add(connectorA);

            rectB = new RectangleParticle(555, 190, 10, 10, 0, false, 3, 0.3f, 0);
            rectB.SetStyle(1, colA, colB);
            this.Particles.Add(rectB);

            connectorB = new SpringConstraint(rectComposite.PC, rectB, 1, false, 1, 1, false);
            connectorB.SetStyle(2, colB);
            this.Constraints.Add(connectorB);
        }
Example #3
0
        public Capsule(int colC)
            : base(false)
        {
            CircleParticle capsuleP1 = new CircleParticle(300, 10, 14, false, 1.3f, 0.4f, 0);
            capsuleP1.SetStyle(0, colC, colC);
            this.Particles.Add(capsuleP1);

            CircleParticle capsuleP2 = new CircleParticle(325, 35, 14, false, 1.3f, 0.4f, 0);
            capsuleP2.SetStyle(0, colC, colC);
            this.Particles.Add(capsuleP2);

            SpringConstraint capsule = new SpringConstraint(capsuleP1, capsuleP2, 1, true, 24, 1, false);
            capsule.SetStyle(0, colC, colC);
            this.Constraints.Add(capsule);
        }
Example #4
0
        public Car(int colC, int colE)
            : base(false)
        {
            wheelParticleA = new WheelParticle(140, 10, 14, false, 2, 0.3f, 0, 1);
            wheelParticleA.SetStyle(1, colC, colE);
            this.Particles.Add(wheelParticleA);

            wheelParticleB = new WheelParticle(200, 10, 14, false, 2, 0.3f, 0, 1);
            wheelParticleB.SetStyle(1, colC, colE);
            this.Particles.Add(wheelParticleB);

            SpringConstraint wheelConnector = new SpringConstraint(wheelParticleA, wheelParticleB,
                    0.5f, true, 8, 1, false);
            wheelConnector.SetStyle(1, colC, colE);
            this.Constraints.Add(wheelConnector);
        }
        public SpringConstraintParticle(AbstractParticle p1, AbstractParticle p2, SpringConstraint p,
				float rectHeight, float rectScale, bool scaleToLength)
            : base(0, 0, 0, 0, 0, false, 1, 0.3f, 0)
        {
            this.p1 = p1;
            this.p2 = p2;

            lambda = new Vector(0, 0);
            avgVelocity = new Vector(0, 0);

            parent = p;
            this.RectScale = rectScale;
            this.RectHeight = rectHeight;
            this.scaleToLength = scaleToLength;

            this.FixedEndLimit = 0;
            rca = new Vector(0, 0);
            rcb = new Vector(0, 0);
        }
Example #6
0
        public RectComposite(Vector ctr, int colA, int colB)
            : base()
        {
            float rw = 75;
            float rh = 18;
            float rad = 4;

            // going clockwise from left top..
            cpA = new CircleParticle(ctr.X - rw / 2, ctr.Y - rh / 2, rad, true, 1, 0.3f, 0);
            cpB = new CircleParticle(ctr.X + rw / 2, ctr.Y - rh / 2, rad, true, 1, 0.3f, 0);
            cpC = new CircleParticle(ctr.X + rw / 2, ctr.Y + rh / 2, rad, true, 1, 0.3f, 0);
            cpD = new CircleParticle(ctr.X - rw / 2, ctr.Y + rh / 2, rad, true, 1, 0.3f, 0);

            cpA.SetStyle(0, 0, colA);
            cpB.SetStyle(0, 0, colA);
            cpC.SetStyle(0, 0, colA);
            cpD.SetStyle(0, 0, colA);

            sprA = new SpringConstraint(cpA, cpB, 0.5f, true, rad * 2, 1, false);
            sprB = new SpringConstraint(cpB, cpC, 0.5f, true, rad * 2, 1, false);
            sprC = new SpringConstraint(cpC, cpD, 0.5f, true, rad * 2, 1, false);
            sprD = new SpringConstraint(cpD, cpA, 0.5f, true, rad * 2, 1, false);

            sprA.SetStyle(0, 0, colA);
            sprB.SetStyle(0, 0, colA);
            sprC.SetStyle(0, 0, colA);
            sprD.SetStyle(0, 0, colA);

            this.Particles.Add(cpA);
            this.Particles.Add(cpB);
            this.Particles.Add(cpC);
            this.Particles.Add(cpD);

            this.Constraints.Add(sprA);
            this.Constraints.Add(sprB);
            this.Constraints.Add(sprC);
            this.Constraints.Add(sprD);
        }
Example #7
0
        public Leg(
			float px,
			float py,
			int orientation,
			float scale,
			float lineWeight,
			int lineColor,
			int fillColor)
        {
            this.lineColor = lineColor;
            this.lineWeight = lineWeight;

            this.fillColor = fillColor;

            // top triangle -- pa is the attach point to the body
            float os = orientation * scale;
            pa = new CircleParticle(px + 31 * os, py - 8 * scale, 1);
            pb = new CircleParticle(px + 25 * os, py - 37 * scale, 1);
            pc = new CircleParticle(px + 60 * os, py - 15 * scale, 1);

            // bottom triangle particles -- pf is the foot
            pd = new CircleParticle(px + 72 * os, py + 12 * scale,  1);
            pe = new CircleParticle(px + 43 * os, py + 19 * scale,  1);
            pf = new CircleParticle(px + 54 * os, py + 61 * scale,  2);

            // strut attach point particle
            ph = new CircleParticle(px, py, 3);

            // top triangle constraints
            SpringConstraint cAB = new SpringConstraint(pa,pb,1);
            SpringConstraint cBC = new SpringConstraint(pb,pc,1);
            SpringConstraint cCA = new SpringConstraint(pc,pa,1);

            // middle leg constraints
            SpringConstraint cCD = new SpringConstraint(pc,pd,1);
            SpringConstraint cAE = new SpringConstraint(pa,pe,1);

            // bottom leg constraints
            SpringConstraint cDE = new SpringConstraint(pd,pe,1);
            SpringConstraint cDF = new SpringConstraint(pd,pf,1);
            SpringConstraint cEF = new SpringConstraint(pe,pf,1);

            // cam constraints
            SpringConstraint cBH = new SpringConstraint(pb,ph,1);
            SpringConstraint cEH = new SpringConstraint(pe,ph,1);

            this.Particles.Add(pa);
            this.Particles.Add(pb);
            this.Particles.Add(pc);
            this.Particles.Add(pd);
            this.Particles.Add(pe);
            this.Particles.Add(pf);
            this.Particles.Add(ph);

            this.Constraints.Add(cAB);
            this.Constraints.Add(cBC);
            this.Constraints.Add(cCA);
            this.Constraints.Add(cCD);
            this.Constraints.Add(cAE);
            this.Constraints.Add(cDE);
            this.Constraints.Add(cDF);
            this.Constraints.Add(cEF);
            this.Constraints.Add(cBH);
            this.Constraints.Add(cEH);

            // for added efficiency, only test the feet (pf) for collision. these
            // selective tweaks should always be considered for best performance.
            pa.Collidable = false;
            pb.Collidable = false;
            pc.Collidable = false;
            pd.Collidable = false;
            pe.Collidable = false;
            ph.Collidable = false;

            _visible = true;
        }
Example #8
0
        public Robot(float px, float py, float scale, float power)
        {
            // legs
            legLA = new Leg(px, py, -1, scale, 2, unchecked((int) 0xFF444444), unchecked((int) 0xFF222222));
            legRA = new Leg(px, py, 1, scale, 2, 0x444444, 0x222222);
            legLB = new Leg(px, py, -1, scale, 2, 0x666666, 0x444444);
            legRB = new Leg(px, py, 1, scale, 2, 0x666666, 0x444444);
            legLC = new Leg(px, py, -1, scale, 2, 0x888888, 0x666666);
            legRC = new Leg(px, py, 1, scale, 2, 0x888888, 0x666666);

            // body
            body = new Body(legLA.Fix, legRA.Fix, (int) (30 * scale), 2, 0x336699);

            // motor
            motor = new Motor(body.Center, 8 * scale, 0x336699);

            // connect the body to the legs
            SpringConstraint connLA = new SpringConstraint(body.Left, legLA.Fix, 1);
            SpringConstraint connRA = new SpringConstraint(body.Right, legRA.Fix, 1);
            SpringConstraint connLB = new SpringConstraint(body.Left, legLB.Fix, 1);
            SpringConstraint connRB = new SpringConstraint(body.Right, legRB.Fix, 1);
            SpringConstraint connLC = new SpringConstraint(body.Left, legLC.Fix, 1);
            SpringConstraint connRC = new SpringConstraint(body.Right, legRC.Fix, 1);

            // connect the legs to the motor
            legLA.Cam.Position = motor.RimA.Position;
            legRA.Cam.Position = motor.RimA.Position;
            SpringConstraint connLAA = new SpringConstraint(legLA.Cam, motor.RimA, 1);
            SpringConstraint connRAA = new SpringConstraint(legRA.Cam, motor.RimA, 1);

            legLB.Cam.Position = motor.RimB.Position;
            legRB.Cam.Position = motor.RimB.Position;
            SpringConstraint connLBB = new SpringConstraint(legLB.Cam, motor.RimB, 1);
            SpringConstraint connRBB = new SpringConstraint(legRB.Cam, motor.RimB, 1);

            legLC.Cam.Position = motor.RimC.Position;
            legRC.Cam.Position = motor.RimC.Position;
            SpringConstraint connLCC = new SpringConstraint(legLC.Cam, motor.RimC, 1);
            SpringConstraint connRCC = new SpringConstraint(legRC.Cam, motor.RimC, 1);

            connLAA.SetLine(2, 0x999999);
            connRAA.SetLine(2, 0x999999);
            connLBB.SetLine(2, 0x999999);
            connRBB.SetLine(2, 0x999999);
            connLCC.SetLine(2, 0x999999);
            connRCC.SetLine(2, 0x999999);

            // add to the engine
            this.Composites.Add(legLA);
            this.Composites.Add(legRA);
            this.Composites.Add(legLB);
            this.Composites.Add(legRB);
            this.Composites.Add(legLC);
            this.Composites.Add(legRC);

            this.Composites.Add(body);
            this.Composites.Add(motor);

            this.Constraints.Add(connLA);
            this.Constraints.Add(connRA);
            this.Constraints.Add(connLB);
            this.Constraints.Add(connRB);
            this.Constraints.Add(connLC);
            this.Constraints.Add(connRC);

            this.Constraints.Add(connLAA);
            this.Constraints.Add(connRAA);
            this.Constraints.Add(connLBB);
            this.Constraints.Add(connRBB);
            this.Constraints.Add(connLCC);
            this.Constraints.Add(connRCC);

            direction = -1;
            powerLevel = power;

            powered = true;
            legsVisible = true;
        }
Example #9
0
        public Bridge(int colB, int colC, int colD)
            : base(false)
        {
            float bx = 170;
            float by = 40;
            float bsize = 51.5f;
            float yslope = 2.4f;
            float particleSize = 4;

            bridgePAA = new CircleParticle(bx, by, particleSize, true, 1, 0.3f, 0);
            bridgePAA.SetStyle(1, colC, colB);
            this.Particles.Add(bridgePAA);

            bx += bsize;
            by += yslope;
            bridgePA = new CircleParticle(bx, by, particleSize, false, 1, 0.3f, 0);
            bridgePA.SetStyle(1, colC, colB);
            this.Particles.Add(bridgePA);

            bx += bsize;
            by += yslope;
            bridgePB = new CircleParticle(bx, by, particleSize, false, 1, 0.3f, 0);
            bridgePB.SetStyle(1, colC, colB);
            this.Particles.Add(bridgePB);

            bx += bsize;
            by += yslope;
            bridgePC = new CircleParticle(bx, by, particleSize, false, 1, 0.3f, 0);
            bridgePC.SetStyle(1, colC, colB);
            this.Particles.Add(bridgePC);

            bx += bsize;
            by += yslope;
            bridgePD = new CircleParticle(bx, by, particleSize, false, 1, 0.3f, 0);
            bridgePD.SetStyle(1, colC, colB);
            this.Particles.Add(bridgePD);

            bx += bsize;
            by += yslope;
            bridgePDD = new CircleParticle(bx, by, particleSize, true, 1, 0.3f, 0);
            bridgePDD.SetStyle(1, colC, colB);
            this.Particles.Add(bridgePDD);

            bridgeConnA = new SpringConstraint(bridgePAA, bridgePA,
                    0.9f, true, 10, 0.8f, false);

            // collision response on the bridgeConnA will be ignored on
            // on the first 1/4 of the constraint. this avoids blow ups
            // particular to springcontraints that have 1 fixed particle.
            bridgeConnA.FixedEndLimit = 0.25f;
            bridgeConnA.SetStyle(1, colC, colB);
            this.Constraints.Add(bridgeConnA);

            bridgeConnB = new SpringConstraint(bridgePA, bridgePB,
                    0.9f, true, 10, 0.8f, false);
            bridgeConnB.SetStyle(1, colC, colB);
            this.Constraints.Add(bridgeConnB);

            bridgeConnC = new SpringConstraint(bridgePB, bridgePC,
                    0.9f, true, 10, 0.8f, false);
            bridgeConnC.SetStyle(1, colC, colB);
            this.Constraints.Add(bridgeConnC);

            bridgeConnD = new SpringConstraint(bridgePC, bridgePD,
                    0.9f, true, 10, 0.8f, false);
            bridgeConnD.SetStyle(1, colC, colB);
            this.Constraints.Add(bridgeConnD);

            bridgeConnE = new SpringConstraint(bridgePD, bridgePDD,
                    0.9f, true, 10, 0.8f, false);
            bridgeConnE.FixedEndLimit = 0.25f;
            bridgeConnE.SetStyle(1, colC, colB);
            this.Constraints.Add(bridgeConnE);
        }
Example #10
0
        public Body(
				AbstractParticle left,
				AbstractParticle right,
				int height,
				float lineWeight,
				int lineColor)
        {
            float cpx = (right.PX + left.PX) / 2;
            float cpy = right.PY;

            rgt = new CircleParticle(right.PX, right.PY, 1);
            rgt.SetStyle(3, lineColor, lineColor);
            lft = new CircleParticle(left.PX, left.PY, 1);
            lft.SetStyle(3, lineColor, lineColor);

            ctr = new CircleParticle(cpx, cpy, 1);
            ctr.Visible = false;
            top = new CircleParticle(cpx, cpy - height / 2, 1);
            top.Visible = false;
            bot = new CircleParticle(cpx, cpy + height / 2, 1);
            bot.Visible = false;

            // outer constraints
            SpringConstraint tr = new SpringConstraint(top, rgt, 1);
            tr.Visible = false;
            SpringConstraint rb = new SpringConstraint(rgt, bot, 1);
            rb.Visible = false;
            SpringConstraint bl = new SpringConstraint(bot, lft, 1);
            bl.Visible = false;
            SpringConstraint lt = new SpringConstraint(lft, top, 1);
            lt.Visible = false;

            // inner constrainst
            SpringConstraint ct = new SpringConstraint(top, this.Center, 1);
            ct.Visible = false;
            SpringConstraint cr = new SpringConstraint(rgt, this.Center, 1);
            cr.SetLine(lineWeight, lineColor);
            SpringConstraint cb = new SpringConstraint(bot, this.Center, 1);
            cb.Visible = false;
            SpringConstraint cl = new SpringConstraint(lft, this.Center, 1);
            cl.SetLine(lineWeight, lineColor);

            ctr.Collidable = false;
            top.Collidable = false;
            rgt.Collidable = false;
            bot.Collidable = false;
            lft.Collidable = false;

            this.Particles.Add(ctr);
            this.Particles.Add(top);
            this.Particles.Add(rgt);
            this.Particles.Add(bot);
            this.Particles.Add(lft);

            this.Constraints.Add(tr);
            this.Constraints.Add(rb);
            this.Constraints.Add(bl);
            this.Constraints.Add(lt);

            this.Constraints.Add(ct);
            this.Constraints.Add(cr);
            this.Constraints.Add(cb);
            this.Constraints.Add(cl);
        }