static public cpSpace BouncyTerrainCircles_500(cpSpace space) { //cpSpace space = BENCH_SPACE_NEW(); SetSubTitle("BouncyTerrainCircles 500"); space.SetIterations(10); cpVect offset = new cpVect(-320, -240); for (int i = 0; i < (bouncy_terrain_verts.Length - 1); i++) { cpVect a = bouncy_terrain_verts[i], b = bouncy_terrain_verts[i + 1]; cpShape shape = space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f)); shape.SetElasticity(1.0f); } for (int i = 0; i < 500; 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(), 130.0f), cpVect.Zero)); body.SetVelocity(cpVect.cpvmult(cp.frand_unit_circle(), 50.0f)); cpShape shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero)); shape.SetElasticity(1.0f); } return(space); }
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); }
static cpSpace NoCollide(cpSpace space) { space.SetIterations(10); var handler = space.AddCollisionHandler(2, 2); //, (a, s, o) => NoCollide_begin(a, s, o), null, null, null); handler.beginFunc = NoCollide_begin; float radius = 4.5f; var staticBody = space.GetStaticBody(); space.AddShape(new cpSegmentShape(staticBody, new cpVect(-330 - radius, -250 - radius), new cpVect(330 + radius, -250 - radius), 0.0f)).SetElasticity(1.0f); space.AddShape(new cpSegmentShape(staticBody, new cpVect(330 + radius, 250 + radius), new cpVect(330 + radius, -250 - radius), 0.0f)).SetElasticity(1.0f); space.AddShape(new cpSegmentShape(staticBody, new cpVect(330 + radius, 250 + radius), new cpVect(-330 - radius, 250 + radius), 0.0f)).SetElasticity(1.0f); space.AddShape(new cpSegmentShape(staticBody, new cpVect(-330 - radius, -250 - radius), new cpVect(-330 - radius, 250 + radius), 0.0f)).SetElasticity(1.0f); for (int x = -320; x <= 320; x += 20) { for (int y = -240; y <= 240; y += 20) { space.AddShape(new cpCircleShape(staticBody, radius, new cpVect(x, y))); } } for (int y = 10 - 240; y <= 240; y += 40) { float mass = 7.0f; cpBody body = space.AddBody(new cpBody(mass, cp.MomentForCircle(mass, 0.0f, radius, cpVect.Zero))); body.SetPosition(new cpVect(-320.0f, y)); body.SetVelocity(new cpVect(100.0f, 0.0f)); cpShape shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero)); shape.SetElasticity(1.0f); shape.SetCollisionType(2); } for (int x = 30 - 320; x <= 320; x += 40) { float mass = 7.0f; cpBody body = space.AddBody(new cpBody(mass, cp.MomentForCircle(mass, 0.0f, radius, cpVect.Zero))); body.SetPosition(new cpVect(x, -240.0f)); body.SetVelocity(new cpVect(0.0f, 100.0f)); cpShape shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero)); shape.SetElasticity(1.0f); shape.SetCollisionType(2); } return(space); }
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); }
static public cpSpace BouncyTerrainHexagons_500(cpSpace space) { SetSubTitle("BouncyTerrainHexagons 500"); //cpSpace space = BENCH_SPACE_NEW(); space.SetIterations(10); cpVect offset = new cpVect(-320, -240); for (int i = 0; i < (bouncy_terrain_verts.Length - 1); i++) { cpVect a = bouncy_terrain_verts[i], b = bouncy_terrain_verts[i + 1]; cpShape shape = space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f)); shape.SetElasticity(1.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 < 500; 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(), 130.0f), cpVect.Zero)); body.SetVelocity(cpVect.cpvmult(cp.frand_unit_circle(), 50.0f)); cpShape shape = space.AddShape(new cpPolyShape(body, 6, hexagon, cpTransform.Identity, bevel)); shape.SetElasticity(1.0f); } return(space); }
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); }