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 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 #5
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 #6
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 #7
0
        private static bool testOBBvsCircle(RectangleParticle ra, CircleParticle ca)
        {
            Vector collisionNormal = new Vector();
            float collisionDepth = float.PositiveInfinity;
            float[] depths = new float[2];

            // first go through the axes of the rectangle
            for (int i = 0; i < 2; i++)
            {
                Vector boxAxis = ra.axes[i];
                float depth = testIntervals(ra.getProjection(boxAxis), ca.getProjection(boxAxis));
                if (depth == 0) return false;

                if (Math.Abs(depth) < Math.Abs(collisionDepth))
                {
                    collisionNormal = boxAxis;
                    collisionDepth = depth;
                }
                depths[i] = depth;
            }

            // determine if the circle's center is in a vertex region
            float r = ca.Radius;
            if (Math.Abs(depths[0]) < r && Math.Abs(depths[1]) < r)
            {
                Vector vertex = closestVertexOnOBB(ca.samp, ra);

                // get the distance from the closest vertex on rect to circle center
                collisionNormal = vertex - ca.samp;
                float mag = collisionNormal.magnitude();
                collisionDepth = r - mag;

                if (collisionDepth > 0)
                {
                    // there is a collision in one of the vertex regions
                    collisionNormal /= mag;
                }
                else
                {
                    // ra is in vertex region, but is not colliding
                    return false;
                }
            }
            CollisionResolver.resolveParticleParticle(ra, ca, collisionNormal, collisionDepth);
            return true;
        }
Example #8
0
        private static bool testCirclevsCircle(CircleParticle ca, CircleParticle cb)
        {
            float depthX = testIntervals(ca.getIntervalX(), cb.getIntervalX());
            if (depthX == 0) return false;

            float depthY = testIntervals(ca.getIntervalY(), cb.getIntervalY());
            if (depthY == 0) return false;

            Vector collisionNormal = ca.samp - cb.samp;
            float mag = collisionNormal.magnitude();
            float collisionDepth = (ca.Radius + cb.Radius) - mag;

            if (collisionDepth > 0)
            {
                collisionNormal /= mag;
                CollisionResolver.resolveParticleParticle(ca, cb, collisionNormal, collisionDepth);
                return true;
            }
            return false;
        }
Example #9
0
        public Surfaces(int colA, int colB, int colC, int colD, int colE, int colBouncePad)
            : base(false)
        {
            floor = new RectangleParticle(340, 327, 550, 50, 0, true, 1.0f, 0.3f, 0);
            floor.SetStyle(0, colD, colD);
            this.Particles.Add(floor);

            ceil = new RectangleParticle(325, -33, 649, 80, 0, true, 1.0f, 0.3f, 0);
            ceil.SetStyle(0, colD, colD);
            this.Particles.Add(ceil);

            rampRight = new RectangleParticle(375, 220, 390, 20, 0.405f, true, 1.0f, 0.3f, 0);
            rampRight.SetStyle(0, colD, colD);
            this.Particles.Add(rampRight);

            rampLeft = new RectangleParticle(90, 200, 102, 20, -.7f, true, 1.0f, 0.3f, 0);
            rampLeft.SetStyle(0, colD, colD);
            this.Particles.Add(rampLeft);

            rampLeft2 = new RectangleParticle(96, 129, 102, 20, -.7f, true, 1.0f, 0.3f, 0);
            rampLeft2.SetStyle(0, colD, colD);
            this.Particles.Add(rampLeft2);

            rampCircle = new CircleParticle(175, 190, 60, true, 1.0f, 0.3f, 0);
            rampCircle.SetStyle(1, colD, colB);
            this.Particles.Add(rampCircle);

            floorBump = new CircleParticle(600, 660, 400, true, 1.0f, 0.3f, 0);
            floorBump.SetStyle(1, colD, colB);
            this.Particles.Add(floorBump);

            bouncePad = new RectangleParticle(30, 370, 32, 60, 0, true, 1.0f, 0.3f, 0);
            bouncePad.SetStyle(1, colD, colBouncePad);
            bouncePad.Elasticity = 4;
            this.Particles.Add(bouncePad);

            leftWall = new RectangleParticle(1, 99, 30, 500, 0, true, 1.0f, 0.3f, 0);
            leftWall.SetStyle(0, colD, colD);
            this.Particles.Add(leftWall);

            leftWallChannelInner = new RectangleParticle(54, 300, 20, 150, 0, true, 1.0f, 0.3f, 0);
            leftWallChannelInner.SetStyle(0, colD, colD);
            this.Particles.Add(leftWallChannelInner);

            leftWallChannel = new RectangleParticle(54, 122, 20, 94, 0, true, 1.0f, 0.3f, 0);
            leftWallChannel.SetStyle(0, colD, colD);
            this.Particles.Add(leftWallChannel);

            leftWallChannelAng = new RectangleParticle(75, 65, 60, 25, -0.7f, true, 1.0f, 0.3f, 0);
            leftWallChannelAng.SetStyle(0, colD, colD);
            this.Particles.Add(leftWallChannelAng);

            topLeftAng = new RectangleParticle(23, 11, 65, 40, -0.7f, true, 1.0f, 0.3f, 0);
            topLeftAng.SetStyle(0, colD, colD);
            this.Particles.Add(topLeftAng);

            rightWall = new RectangleParticle(654, 230, 50, 500, 0, true, 1.0f, 0.3f, 0);
            rightWall.SetStyle(0, colD, colD);
            this.Particles.Add(rightWall);

            bridgeStart = new RectangleParticle(127, 49, 75, 25, 0, true, 1.0f, 0.3f, 0);
            bridgeStart.SetStyle(0, colD, colD);
            this.Particles.Add(bridgeStart);

            bridgeEnd = new RectangleParticle(483, 55, 100, 15, 0, true, 1.0f, 0.3f, 0);
            bridgeEnd.SetStyle(0, colD, colD);
            this.Particles.Add(bridgeEnd);
        }