コード例 #1
0
        static public cpSpace ComplexTerrainCircles_1000(cpSpace space)
        {
            space.SetIterations(10);
            space.SetGravity(new cpVect(0, -100));
            space.SetCollisionSlop(0.5f);

            cpVect offset = new cpVect(-320, -240);

            for (int i = 0; i < (complex_terrain_verts.Length - 1); i++)
            {
                cpVect a = complex_terrain_verts[i], b = complex_terrain_verts[i + 1];
                space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f));
            }

            for (int i = 0; i < 1000; i++)
            {
                float  radius = 5.0f;
                float  mass   = radius * radius;
                cpBody body   = space.AddBody(new cpBody(mass, cp.MomentForCircle(mass, 0.0f, radius, cpVect.Zero)));
                body.SetPosition(cpVect.cpvadd(cpVect.cpvmult(cp.frand_unit_circle(), 180.0f), new cpVect(0.0f, 300.0f)));
                cpShape shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero));
                shape.SetElasticity(0.0f); shape.SetFriction(0.0f);
            }

            return(space);
        }
コード例 #2
0
        static public cpSpace SetupSpace_simpleTerrain(cpSpace space)
        {
            SetSubTitle("SetupSpace_simpleTerrain");
            space.SetIterations(10);
            space.SetGravity(new cpVect(0, -100));
            space.SetCollisionSlop(0.5f);

            cpVect offset = new cpVect(-320, -240);

            for (int i = 0; i < (simple_terrain_verts.Length - 1); i++)
            {
                cpVect a = simple_terrain_verts[i], b = simple_terrain_verts[i + 1];
                space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f));
            }
            return(space);
        }
コード例 #3
0
        static public cpSpace ComplexTerrainHexagons_1000(cpSpace space)
        {
            SetSubTitle("ComplexTerrainHexagons_1000");
            space.SetIterations(10);
            space.SetGravity(new cpVect(0, -100));
            space.SetCollisionSlop(0.5f);

            cpVect offset = new cpVect(-320, -240);

            for (int i = 0; i < (complex_terrain_verts.Length - 1); i++)
            {
                cpVect a = complex_terrain_verts[i], b = complex_terrain_verts[i + 1];
                space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f));
            }

            float radius = 5.0f;

            cpVect[] hexagon = new cpVect[6];
            for (int i = 0; i < 6; i++)
            {
                float angle = -(float)Math.PI * 2.0f * i / 6.0f;
                hexagon[i] = cpVect.cpvmult(cpVect.cpv(cp.cpfcos(angle), cp.cpfsin(angle)), radius - bevel);
            }

            for (int i = 0; i < 1000; i++)
            {
                float  mass = radius * radius;
                cpBody body = space.AddBody(new cpBody(mass, cp.MomentForPoly(mass, 6, hexagon, cpVect.Zero, 0.0f)));
                body.SetPosition(cpVect.cpvadd(cpVect.cpvmult(cp.frand_unit_circle(), 180.0f), new cpVect(0.0f, 300.0f)));

                cpShape shape = space.AddShape(new cpPolyShape(body, 6, hexagon, cpTransform.Identity, bevel));
                shape.SetElasticity(0.0f); shape.SetFriction(0.0f);
            }

            return(space);
        }