Esempio n. 1
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);
        }
Esempio n. 2
0
        private static Vector closestVertexOnOBB(Vector p, RectangleParticle r)
        {
            Vector d = p - r.samp;
            Vector q = new Vector(r.samp.X, r.samp.Y);

            for (int i = 0; i < 2; i++)
            {
                float dist = d.Dot(r.axes[i]);

                if (dist >= 0) dist = r.extents(i);
                else if (dist < 0) dist = -r.extents(i);

                q += (r.axes[i] * dist);
            }
            return q;
        }
        private void setCorners(RectangleParticle r, int i)
        {
            float rx = r.curr.X;
            float ry = r.curr.Y;

            float ae0_x = r.axes[0].X * r.extents(0);
            float ae0_y = r.axes[0].Y * r.extents(0);
            float ae1_x = r.axes[1].X * r.extents(1);
            float ae1_y = r.axes[1].Y * r.extents(1);

            float emx = ae0_x - ae1_x;
            float emy = ae0_y - ae1_y;
            float epx = ae0_x + ae1_x;
            float epy = ae0_y + ae1_y;

            if (i == 0)
            {
                // 0 and 1
                rca.X = rx - epx;
                rca.Y = ry - epy;
                rcb.X = rx + emx;
                rcb.Y = ry + emy;

            }
            else if (i == 1)
            {
                // 1 and 2
                rca.X = rx + emx;
                rca.Y = ry + emy;
                rcb.X = rx + epx;
                rcb.Y = ry + epy;

            }
            else if (i == 2)
            {
                // 2 and 3
                rca.X = rx + epx;
                rca.Y = ry + epy;
                rcb.X = rx - emx;
                rcb.Y = ry - emy;

            }
            else if (i == 3)
            {
                // 3 and 0
                rca.X = rx - emx;
                rca.Y = ry - emy;
                rcb.X = rx - epx;
                rcb.Y = ry - epy;
            }
        }
Esempio n. 4
0
        private static bool testOBBvsOBB(RectangleParticle ra, RectangleParticle rb)
        {
            Vector collisionNormal = new Vector();
            float collisionDepth = float.PositiveInfinity;

            for (int i = 0; i < 2; i++)
            {
                Vector axisA = ra.axes[i];
                float depthA = testIntervals(ra.getProjection(axisA), rb.getProjection(axisA));
                if (depthA == 0) return false;

                Vector axisB = rb.axes[i];
                float depthB = testIntervals(ra.getProjection(axisB), rb.getProjection(axisB));
                if (depthB == 0) return false;

                float absA = Math.Abs(depthA);
                float absB = Math.Abs(depthB);

                if (absA < Math.Abs(collisionDepth) || absB < Math.Abs(collisionDepth))
                {
                    bool altb = absA < absB;
                    collisionNormal = altb ? axisA : axisB;
                    collisionDepth = altb ? depthA : depthB;
                }
            }
            CollisionResolver.resolveParticleParticle(ra, rb, collisionNormal, collisionDepth);
            return true;
        }
Esempio n. 5
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;
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public RobotDemo()
        {
            APEngine.init(1 / 4);
            //APEngine.container = this;
            APEngine.addMasslessForce(new Vector(0, 4));

            APEngine.Damping = .99f;
            APEngine.ConstraintCollisionCycles = 10;

            robot = new Robot(1250, 260, 1.6f, 0.02f);

            Group terrainA = new Group();
            Group terrainB = new Group(true);
            Group terrainC = new Group();

            RectangleParticle floor = new RectangleParticle(600, 390, 1700, 100, 0, true, 1, 0, 1);
            floor.SetStyle(0, 0, 0x999999);
            terrainA.Particles.Add(floor);

            // pyramid of boxes
            RectangleParticle box0 = new RectangleParticle(600, 337, 600, 7, 0, true, 10, 0, 1);
            box0.SetStyle(1, 0x999999, 0x336699);
            terrainA.Particles.Add(box0);

            RectangleParticle box1 = new RectangleParticle(600, 330, 500, 7, 0, true, 10, 0, 1);
            box1.SetStyle(1, 0x999999, 0x336699);
            terrainA.Particles.Add(box1);

            RectangleParticle box2 = new RectangleParticle(600, 323, 400, 7, 0, true, 10, 0, 1);
            box2.SetStyle(1, 0x999999, 0x336699);
            terrainA.Particles.Add(box2);

            RectangleParticle box3 = new RectangleParticle(600, 316, 300, 7, 0, true, 10, 0, 1);
            box3.SetStyle(1, 0x999999, 0x336699);
            terrainA.Particles.Add(box3);

            RectangleParticle box4 = new RectangleParticle(600, 309, 200, 7, 0, true, 10, 0, 1);
            box4.SetStyle(1, 0x999999, 0x336699);
            terrainA.Particles.Add(box4);

            RectangleParticle box5 = new RectangleParticle(600, 302, 100, 7, 0, true, 10, 0, 1);
            box5.SetStyle(1, 0x999999, 0x336699);
            terrainA.Particles.Add(box5);

            // left side floor
            RectangleParticle floor2 = new RectangleParticle(-100, 390, 1100, 100, 0.3f, true, 1, 0, 1);
            floor2.SetStyle(0, 0, 0x999999);
            terrainB.Particles.Add(floor2);

            RectangleParticle floor3 = new RectangleParticle(-959, 232, 700, 100, 0, true, 1, 0, 1);
            floor3.SetStyle(0, 0, 0x999999);
            terrainB.Particles.Add(floor3);

            RectangleParticle box6 = new RectangleParticle(-990, 12, 50, 25, 0);
            box6.SetStyle(1, 0x999999, 0x336699);
            terrainB.Particles.Add(box6);

            RectangleParticle floor5 = new RectangleParticle(-1284, 170, 50, 100, 0, true);
            floor5.SetStyle(0, 0, 0x999999);
            terrainB.Particles.Add(floor5);

            // right side floor
            RectangleParticle floor6 = new RectangleParticle(1430, 320, 50, 60, 0, true);
            floor6.SetStyle(0, 0, 0x00999999);
            terrainC.Particles.Add(floor6);

            APEngine.addGroup(robot);
            APEngine.addGroup(terrainA);
            APEngine.addGroup(terrainB);
            APEngine.addGroup(terrainC);

            robot.addCollidable(terrainA);
            robot.addCollidable(terrainB);
            robot.addCollidable(terrainC);

            robot.togglePower();
        }