本文整理汇总了C++中cpSpaceAddShape函数的典型用法代码示例。如果您正苦于以下问题:C++ cpSpaceAddShape函数的具体用法?C++ cpSpaceAddShape怎么用?C++ cpSpaceAddShape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpSpaceAddShape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: init
static cpSpace *
init(void)
{
ChipmunkDemoMessageString = "Right click and drag to change the blocks's shape.";
cpSpace *space = cpSpaceNew();
cpSpaceSetIterations(space, 30);
cpSpaceSetGravity(space, cpv(0, -500));
cpSpaceSetSleepTimeThreshold(space, 0.5f);
cpSpaceSetCollisionSlop(space, 0.5f);
cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
cpFloat width = 50.0f;
cpFloat height = 70.0f;
cpFloat mass = width*height*DENSITY;
cpFloat moment = cpMomentForBox(mass, width, height);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, width, height));
cpShapeSetFriction(shape, 0.6f);
return space;
}
开发者ID:1103785815,项目名称:wizardwar,代码行数:31,代码来源:Convex.c
示例2: cpSpaceAddShape
Bumper::Bumper(Actor * actor, int facing_direction, float thickness) {
//cout << "New bumper on " << actor->actorName << " " << actor->width << " " << actor->height << " " << facing_direction << "\n";
cpBody * body = actor->body;
this->actor = actor;
this->facing_direction = facing_direction;
if(facing_direction == Facing::Left) {
shape = cpSpaceAddShape(
game_map->physSpace,
boxWithOffset(body, thickness, actor->height, cpv(-actor->width/2 - 1, 0))
);
} else if(facing_direction == Facing::Right) {
shape = cpSpaceAddShape(
game_map->physSpace,
boxWithOffset(body, thickness, actor->height, cpv(actor->width/2 + 1, 0))
);
} else if(facing_direction == Facing::Down) {
shape = cpSpaceAddShape(
game_map->physSpace,
boxWithOffset(body, actor->width, thickness, cpv(0, -actor->height/2 - 1))
);
} else if(facing_direction == Facing::Up) {
shape = cpSpaceAddShape(
game_map->physSpace,
boxWithOffset(body, actor->width, thickness, cpv(0, actor->height/2 + 1))
);
}
shape->data = (void *) this;
shape->sensor = true;
shape->layers = PhysicsLayer::Map|PhysicsLayer::Enemy;
shape->collision_type = PhysicsType::Bumper;
shape->group = PhysicsGroup::Bumpers;
grounded = 0;
}
开发者ID:harad,项目名称:Last-Escape,代码行数:35,代码来源:Bumper.cpp
示例3: cpSpaceNew
cpSpace *Slice::Init()
{
ChipmunkDemo::Init();
message = "Hold right bottom corner and slice with touch.";
space = cpSpaceNew();
cpSpaceSetIterations(space, 30);
cpSpaceSetGravity(space, cpv(0, -500));
cpSpaceSetSleepTimeThreshold(space, 0.5f);
cpSpaceSetCollisionSlop(space, 0.5f);
cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-1000,-240), cpv(1000,-240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
cpFloat width = 200.0f;
cpFloat height = 300.0f;
cpFloat mass = width*height*DENSITY;
cpFloat moment = cpMomentForBox(mass, width, height);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, width, height, 0.0));
cpShapeSetFriction(shape, 0.6f);
return space;
}
开发者ID:damucz,项目名称:chipmunk2d,代码行数:33,代码来源:Slice.cpp
示例4: init
static cpSpace *
init(void)
{
space = cpSpaceNew();
cpSpaceSetGravity(space, cpv(0, -600));
cpBody *body;
cpShape *shape;
// We create an infinite mass rogue body to attach the line segments too
// This way we can control the rotation however we want.
rogueBoxBody = cpBodyNew(INFINITY, INFINITY);
cpBodySetAngVel(rogueBoxBody, 0.4f);
// Set up the static box.
cpVect a = cpv(-200, -200);
cpVect b = cpv(-200, 200);
cpVect c = cpv( 200, 200);
cpVect d = cpv( 200, -200);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(rogueBoxBody, a, b, 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(rogueBoxBody, b, c, 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(rogueBoxBody, c, d, 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(rogueBoxBody, d, a, 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
cpFloat mass = 1;
cpFloat width = 60;
cpFloat height = 30;
// Add the bricks.
for(int i=0; i<3; i++){
for(int j=0; j<7; j++){
body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForBox(mass, width, height)));
cpBodySetPos(body, cpv(i*60 - 150, j*30 - 150));
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, width, height));
cpShapeSetElasticity(shape, 0.0f);
cpShapeSetFriction(shape, 0.7f);
}
}
return space;
}
开发者ID:meiyunyang,项目名称:chipmunk-physics,代码行数:58,代码来源:Tumble.c
示例5: init
static cpSpace *
init(void)
{
cpResetShapeIdCounter();
space = cpSpaceNew();
cpSpaceResizeActiveHash(space, 30.0f, 1000);
space->iterations = 10;
space->sleepTimeThreshold = 0.5f;
cpBody *staticBody = &space->staticBody;
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,240), cpv(320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
for(int i=0; i<50; i++){
cpBody *body = add_box(10.0f, 1.0f);
cpConstraint *pivot = cpSpaceAddConstraint(space, cpPivotJointNew2(staticBody, body, cpvzero, cpvzero));
pivot->biasCoef = 0.0f; // disable joint correction
pivot->maxForce = 1000.0f; // emulate linear friction
cpConstraint *gear = cpSpaceAddConstraint(space, cpGearJointNew(staticBody, body, 0.0f, 1.0f));
gear->biasCoef = 0.0f; // disable joint correction
gear->maxForce = 5000.0f; // emulate angular friction
}
// We joint the tank to the control body and control the tank indirectly by modifying the control body.
tankControlBody = cpBodyNew(INFINITY, INFINITY);
tankBody = add_box(15.0f, 10.0f);
cpConstraint *pivot = cpSpaceAddConstraint(space, cpPivotJointNew2(tankControlBody, tankBody, cpvzero, cpvzero));
pivot->biasCoef = 0.0f; // disable joint correction
pivot->maxForce = 10000.0f; // emulate linear friction
cpConstraint *gear = cpSpaceAddConstraint(space, cpGearJointNew(tankControlBody, tankBody, 0.0f, 1.0f));
gear->biasCoef = 1.0f; // limit angular correction rate
gear->maxBias = 1.0f; // limit angular correction rate
gear->maxForce = 500000.0f; // emulate angular friction
return space;
}
开发者ID:hit1983,项目名称:cocos2d-iphone,代码行数:57,代码来源:Tank.c
示例6: init
static cpSpace *
init(void)
{
ChipmunkDemoMessageString = "One way platforms are trivial in Chipmunk using a very simple collision callback.";
cpSpace *space = cpSpaceNew();
cpSpaceSetIterations(space, 10);
cpSpaceSetGravity(space, cpv(0, -100));
cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
// Add our one way segment
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-160,-100), cpv(160,-100), 10.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetCollisionType(shape, COLLISION_TYPE_ONE_WAY);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
// We'll use the data pointer for the OneWayPlatform struct
platformInstance.n = cpv(0, 1); // let objects pass upwards
cpShapeSetUserData(shape, &platformInstance);
// Add a ball to test it out
cpFloat radius = 15.0f;
body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero)));
cpBodySetPosition(body, cpv(0, -200));
cpBodySetVelocity(body, cpv(0, 170));
shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
cpShapeSetElasticity(shape, 0.0f);
cpShapeSetFriction(shape, 0.9f);
cpShapeSetCollisionType(shape, 2);
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, COLLISION_TYPE_ONE_WAY);
handler->preSolveFunc = PreSolve;
return space;
}
开发者ID:00dazam,项目名称:FlappyBird-SpriteBuilder,代码行数:56,代码来源:OneWay.c
示例7: init
static cpSpace *
init(void)
{
ChipmunkDemoMessageString = "Sticky collisions using the cpArbiter data pointer.";
cpSpace *space = cpSpaceNew();
cpSpaceSetIterations(space, 10);
cpSpaceSetGravity(space, cpv(0, -1000));
cpSpaceSetCollisionSlop(space, 2.0);
cpBody *staticBody = cpSpaceGetStaticBody(space);
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-340,-260), cpv(-340, 260), 20.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetCollisionType(shape, COLLIDE_STICK_SENSOR);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv( 340,-260), cpv( 340, 260), 20.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetCollisionType(shape, COLLIDE_STICK_SENSOR);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-340,-260), cpv( 340,-260), 20.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetCollisionType(shape, COLLIDE_STICK_SENSOR);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-340, 260), cpv( 340, 260), 20.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetCollisionType(shape, COLLIDE_STICK_SENSOR);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
for(int i=0; i<200; i++){
cpFloat mass = 0.15f;
cpFloat radius = 10.0f;
cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, radius, cpvzero)));
cpBodySetPos(body, cpv(cpflerp(-150.0f, 150.0f, frand()), cpflerp(-150.0f, 150.0f, frand())));
cpShape *shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius + STICK_SENSOR_THICKNESS, cpvzero));
cpShapeSetFriction(shape, 0.9f);
cpShapeSetCollisionType(shape, COLLIDE_STICK_SENSOR);
}
cpSpaceAddCollisionHandler(space, COLLIDE_STICK_SENSOR, COLLIDE_STICK_SENSOR, NULL, StickyPreSolve, NULL, StickySeparate, NULL);
return space;
}
开发者ID:Adefy,项目名称:AdefyiOS,代码行数:54,代码来源:Sticky.c
示例8: init
static cpSpace *
init(void)
{
ChipmunkDemoMessageString = "Right click to make pentagons static/dynamic.";
cpSpace *space = cpSpaceNew();
cpSpaceSetIterations(space, 5);
cpSpaceSetGravity(space, cpv(0, -100));
cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
cpShape *shape;
// Vertexes for a triangle shape.
cpVect tris[] = {
cpv(-15,-15),
cpv( 0, 10),
cpv( 15,-15),
};
// Create the static triangles.
for(int i=0; i<9; i++){
for(int j=0; j<6; j++){
cpFloat stagger = (j%2)*40;
cpVect offset = cpv(i*80 - 320 + stagger, j*70 - 240);
shape = cpSpaceAddShape(space, cpPolyShapeNew(staticBody, 3, tris, offset));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
}
}
// Create vertexes for a pentagon shape.
cpVect verts[NUM_VERTS];
for(int i=0; i<NUM_VERTS; i++){
cpFloat angle = -2*M_PI*i/((cpFloat) NUM_VERTS);
verts[i] = cpv(10*cos(angle), 10*sin(angle));
}
pentagon_mass = 1.0;
pentagon_moment = cpMomentForPoly(1.0f, NUM_VERTS, verts, cpvzero);
// Add lots of pentagons.
for(int i=0; i<300; i++){
body = cpSpaceAddBody(space, cpBodyNew(pentagon_mass, pentagon_moment));
cpFloat x = rand()/(cpFloat)RAND_MAX*640 - 320;
cpBodySetPos(body, cpv(x, 350));
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
cpShapeSetElasticity(shape, 0.0f);
cpShapeSetFriction(shape, 0.4f);
}
return space;
}
开发者ID:Adefy,项目名称:AdefyiOS,代码行数:54,代码来源:Plink.c
示例9: init
static cpSpace *
init(void)
{
cpResetShapeIdCounter();
space = cpSpaceNew();
space->iterations = 5;
space->gravity = cpv(0, -100);
cpSpaceResizeStaticHash(space, 40.0f, 999);
cpSpaceResizeActiveHash(space, 30.0f, 2999);
cpBody *body, *staticBody = &space->staticBody;
cpShape *shape;
// Create vertexes for a pentagon shape.
cpVect verts[NUM_VERTS];
for(int i=0; i<NUM_VERTS; i++){
cpFloat angle = -2*M_PI*i/((cpFloat) NUM_VERTS);
verts[i] = cpv(10*cos(angle), 10*sin(angle));
}
// Vertexes for a triangle shape.
cpVect tris[] = {
cpv(-15,-15),
cpv( 0, 10),
cpv( 15,-15),
};
// Create the static triangles.
for(int i=0; i<9; i++){
for(int j=0; j<6; j++){
cpFloat stagger = (j%2)*40;
cpVect offset = cpv(i*80 - 320 + stagger, j*70 - 240);
shape = cpSpaceAddShape(space, cpPolyShapeNew(staticBody, 3, tris, offset));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
}
}
// Add lots of pentagons.
for(int i=0; i<300; i++){
body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForPoly(1.0f, NUM_VERTS, verts, cpvzero)));
cpFloat x = rand()/(cpFloat)RAND_MAX*640 - 320;
body->p = cpv(x, 350);
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
shape->e = 0.0f; shape->u = 0.4f;
}
return space;
}
开发者ID:artifacts,项目名称:ste,代码行数:52,代码来源:Plink.c
示例10: init
static cpSpace *
init(void)
{
cpSpace *space = cpSpaceNew();
cpSpaceSetIterations(space, 30);
cpSpaceSetGravity(space, cpv(0, -100));
cpSpaceSetSleepTimeThreshold(space, 0.5f);
cpSpaceSetCollisionSlop(space, 0.5f);
cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
// Add lots of boxes.
for(int i=0; i<14; i++){
for(int j=0; j<=i; j++){
body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForBox(1.0f, 30.0f, 30.0f)));
cpBodySetPosition(body, cpv(j*32 - i*16, 300 - i*32));
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 30.0f, 30.0f, 0.5f));
cpShapeSetElasticity(shape, 0.0f);
cpShapeSetFriction(shape, 0.8f);
}
}
// Add a ball to make things more interesting
cpFloat radius = 15.0f;
body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero)));
cpBodySetPosition(body, cpv(0, -240 + radius+5));
shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
cpShapeSetElasticity(shape, 0.0f);
cpShapeSetFriction(shape, 0.9f);
return space;
}
开发者ID:ConfusedReality,项目名称:pkg_game-engine_chipmunk,代码行数:51,代码来源:PyramidStack.c
示例11: init
static cpSpace *
init(void)
{
QUERY_START = cpvzero;
space = cpSpaceNew();
cpSpaceSetIterations(space, 5);
{ // add a fat segment
cpFloat mass = 1.0f;
cpFloat length = 100.0f;
cpVect a = cpv(-length/2.0f, 0.0f), b = cpv(length/2.0f, 0.0f);
cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForSegment(mass, a, b)));
cpBodySetPos(body, cpv(0.0f, 100.0f));
cpSpaceAddShape(space, cpSegmentShapeNew(body, a, b, 20.0f));
}
{ // add a static segment
cpSpaceAddShape(space, cpSegmentShapeNew(cpSpaceGetStaticBody(space), cpv(0, 300), cpv(300, 0), 0.0f));
}
{ // add a pentagon
cpFloat mass = 1.0f;
const int NUM_VERTS = 5;
cpVect verts[NUM_VERTS];
for(int i=0; i<NUM_VERTS; i++){
cpFloat angle = -2*M_PI*i/((cpFloat) NUM_VERTS);
verts[i] = cpv(30*cos(angle), 30*sin(angle));
}
cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, NUM_VERTS, verts, cpvzero)));
cpBodySetPos(body, cpv(50.0f, 50.0f));
cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
}
{ // add a circle
cpFloat mass = 1.0f;
cpFloat r = 20.0f;
cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, r, cpvzero)));
cpBodySetPos(body, cpv(100.0f, 100.0f));
cpSpaceAddShape(space, cpCircleShapeNew(body, r, cpvzero));
}
return space;
}
开发者ID:50Cubes,项目名称:ClusterFear,代码行数:51,代码来源:Query.c
示例12: init
static cpSpace *
init(void)
{
cpResetShapeIdCounter();
space = cpSpaceNew();
space->iterations = 10;
space->gravity = cpv(0, -100);
cpBody *body, *staticBody = &space->staticBody;
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
// Add our one way segment
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-160,-100), cpv(160,-100), 10.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->collision_type = 1;
shape->layers = NOT_GRABABLE_MASK;
// We'll use the data pointer for the OneWayPlatform struct
platformInstance.n = cpv(0, 1); // let objects pass upwards
platformInstance.passThruList = cpArrayNew(0);
shape->data = &platformInstance;
// Add a ball to make things more interesting
cpFloat radius = 15.0f;
body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero)));
body->p = cpv(0, -200);
body->v = cpv(0, 170);
shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
shape->e = 0.0f; shape->u = 0.9f;
shape->collision_type = 2;
cpSpaceAddCollisionHandler(space, 1, 2, NULL, preSolve, NULL, NULL, NULL);
return space;
}
开发者ID:9miao,项目名称:cocos2dx-win8,代码行数:51,代码来源:OneWay.cpp
示例13: erl_element
ETERM *space_add_boundaries(ETERM *fromp, ETERM *argp) {
// get the args
ETERM *space_refp = erl_element(1, argp);
ETERM *lower_leftp = erl_element(2, argp);
ETERM *lower_rightp = erl_element(3, argp);
ETERM *upper_leftp = erl_element(4, argp);
ETERM *upper_rightp = erl_element(5, argp);
ETERM *collision_categoryp = erl_element(6, argp);
ETERM *datap = erl_element(7, argp);
erlmunk_space *s;
int space_id = ERL_REF_NUMBER(space_refp);
HASH_FIND_INT(erlmunk_spaces, &space_id, s);
cpVect lowerLeft = cpv(ERL_FLOAT_VALUE(erl_element(1, lower_leftp)),
ERL_FLOAT_VALUE(erl_element(2, lower_leftp)));
cpVect lowerRight = cpv(ERL_FLOAT_VALUE(erl_element(1, lower_rightp)),
ERL_FLOAT_VALUE(erl_element(2, lower_rightp)));
cpVect upperLeft = cpv(ERL_FLOAT_VALUE(erl_element(1, upper_leftp)),
ERL_FLOAT_VALUE(erl_element(2, upper_leftp)));
cpVect upperRight = cpv(ERL_FLOAT_VALUE(erl_element(1, upper_rightp)),
ERL_FLOAT_VALUE(erl_element(2, upper_rightp)));
// get the static body that comes with the space
cpBody *static_body = cpSpaceGetStaticBody(s->space);
erlmunk_body_data *data = malloc(sizeof(erlmunk_body_data));
data->id = BOUNDARY_BODY_ID;
data->term = erl_copy_term(datap);
cpBodySetUserData(static_body, (cpDataPointer) data);
// bottom
cpShape *bottomBoundaryShape = cpSegmentShapeNew(static_body, lowerLeft, lowerRight, 0.0f);
cpShapeSetCollisionType(bottomBoundaryShape, ERL_INT_VALUE(collision_categoryp));
cpSpaceAddShape(s->space, bottomBoundaryShape);
// top
cpShape *topBoundaryShape = cpSegmentShapeNew(static_body, upperLeft, upperRight, 0.0f);
cpShapeSetCollisionType(topBoundaryShape, ERL_INT_VALUE(collision_categoryp));
cpSpaceAddShape(s->space, topBoundaryShape);
// left
cpShape *leftBoundaryShape = cpSegmentShapeNew(static_body, lowerLeft, upperLeft, 0.0f);
cpShapeSetCollisionType(leftBoundaryShape, ERL_INT_VALUE(collision_categoryp));
cpSpaceAddShape(s->space, leftBoundaryShape);
// right
cpShape *rightBoundaryShape = cpSegmentShapeNew(static_body, lowerRight, upperRight, 0.0f);
cpShapeSetCollisionType(rightBoundaryShape, ERL_INT_VALUE(collision_categoryp));
cpSpaceAddShape(s->space, rightBoundaryShape);
return NULL;
}
开发者ID:lrascao,项目名称:erlmunk,代码行数:50,代码来源:erlmunk_space.c
示例14: init
static cpSpace *
init(void)
{
cpResetShapeIdCounter();
space = cpSpaceNew();
space->iterations = 30;
cpSpaceResizeStaticHash(space, 40.0f, 1000);
cpSpaceResizeActiveHash(space, 40.0f, 1000);
space->gravity = cpv(0, -100);
space->sleepTimeThreshold = 0.5f;
cpBody *body, *staticBody = &space->staticBody;
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
shape->layers = NOT_GRABABLE_MASK;
// Add lots of boxes.
for(int i=0; i<14; i++){
for(int j=0; j<=i; j++){
body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForBox(1.0f, 30.0f, 30.0f)));
body->p = cpv(j*32 - i*16, 300 - i*32);
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 30.0f, 30.0f));
shape->e = 0.0f; shape->u = 0.8f;
}
}
// Add a ball to make things more interesting
cpFloat radius = 15.0f;
body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero)));
body->p = cpv(0, -240 + radius+5);
shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
shape->e = 0.0f; shape->u = 0.9f;
return space;
}
开发者ID:9miao,项目名称:cocos2dx-win8,代码行数:49,代码来源:PyramidStack.cpp
示例15: l_physics_newShape
int l_physics_newShape(lua_State* state)
{
l_tools_checkUserDataPlusErrMsg(state, 1, "You must provide a space");
l_tools_checkUserDataPlusErrMsg(state, 2, "You must provide a body");
l_physics_PhysicsData* physics = (l_physics_PhysicsData*)lua_touserdata(state, 1);
l_physics_Body* body = (l_physics_Body*)lua_touserdata(state, 2);
float x1 = l_tools_toNumberOrError(state, 3);
float y1 = l_tools_toNumberOrError(state, 4);
float x2 = l_tools_toNumberOrError(state, 5);
float y2 = l_tools_toNumberOrError(state, 6);
float radius = l_tools_toNumberOrError(state, 7);
moduleData.shape = (l_physics_Shape*)lua_newuserdata(state, sizeof(l_physics_Shape));
moduleData.shape->physics = malloc(sizeof(physics_PhysicsData));
moduleData.shape->physics = physics->physics;
moduleData.shape->shape = cpSpaceAddShape(physics->physics->space, cpSegmentShapeNew(body->body, cpv(x1, y1), cpv(x2, y2), radius));
lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.shapeMT);
lua_setmetatable(state, -2);
return 1;
}
开发者ID:dns,项目名称:CLove,代码行数:27,代码来源:physics.c
示例16: l_physics_newCircleShape
int l_physics_newCircleShape(lua_State* state)
{
l_tools_checkUserDataPlusErrMsg(state, 1, "You must provide a space!");
l_physics_PhysicsData* physics = (l_physics_PhysicsData*)lua_touserdata(state, 1);
l_tools_checkUserDataPlusErrMsg(state, 2, "You must provide a body");
l_physics_Body* body = (l_physics_Body*)lua_touserdata(state, 2);
float radius = l_tools_toNumberOrError(state, 3);
cpVect offset = cpvzero;
offset.x = l_tools_toNumberOrError(state, 4);
offset.y = l_tools_toNumberOrError(state, 5);
moduleData.shape = (l_physics_Shape*)lua_newuserdata(state, sizeof(l_physics_Shape));
moduleData.shape->physics = malloc(sizeof(physics_PhysicsData));
moduleData.shape->physics = physics->physics;
moduleData.shape->shape = cpSpaceAddShape(physics->physics->space, cpCircleShapeNew(body->body, radius, offset));
lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.shapeMT);
lua_setmetatable(state, -2);
return 1;
}
开发者ID:dns,项目名称:CLove,代码行数:25,代码来源:physics.c
示例17: lc_space_AddShape
int lc_space_AddShape(lua_State *vm){
//space, shape
lc_space *space = lc_GetSpace(1, vm);
if (space == NULL){
printf("chipmunk: Object can't call :AddShape\n");
return 0;
}
lc_shape *shape = lc_GetShape(2, vm);
if (shape == NULL){
printf("space:AddShape(): Can't add a shape\n");
return 0;
}
char pshape[32] = {0};
snprintf(pshape, 32, "%p", shape);
//If the shape doesn't exists in shapes table then add it
lua_rawgeti(vm, LUA_REGISTRYINDEX, space->shapes);
lua_getfield(vm, -1, pshape);
if (!lua_isnil(vm, -1)){
//The shape alreadye exists
return 0;
}
lua_pop(vm, 1);
lua_pushvalue(vm, 2);
lua_setfield(vm, -2, pshape);
lua_pop(vm, 1);//shapes table
//---
cpSpaceAddShape(space->space, shape->shape);
return 0;
}
开发者ID:sixian,项目名称:lunatic-chipmunk,代码行数:32,代码来源:space.c
示例18: atlFindImageFile
static palette_object_t *createPaletteObject(cpVect p, char *file, int dam, float m) {
image_t *img;
palette_object_t *obj;
int numVerts = 4;
cpVect verts[] = {
{-16, -16},
{-16, 16},
{ 16, 16},
{ 16, -16}
};
obj = (palette_object_t *)malloc(sizeof(palette_object_t));
obj->maxDamage = dam;
obj->m = m;
if (file) {
img = atlFindImageFile(file, false, GL_CLAMP);
strncpy(obj->texfile, img->name, PATH_MAX);
obj->texnum = img->texnum;
} else {
obj->texnum = -1;
}
obj->body = cpBodyNewStatic();
obj->body->p = p;
obj->shape = cpPolyShapeNew(obj->body, numVerts, verts, cpvzero);
obj->shape->data = obj;
obj->shape->collision_type = PALETTE_TYPE;
cpSpaceAddShape(g_Space, obj->shape);
return obj;
}
开发者ID:davidreynolds,项目名称:Atlas2D,代码行数:33,代码来源:editor.c
示例19: cpResetShapeIdCounter
static cpSpace *initSpace(void) {
int i;
cpBody *staticBody;
cpShape *shape;
cpVect cannonPos;
cpResetShapeIdCounter();
g_Space = cpSpaceNew();
g_Space->iterations = 30;
g_Space->gravity = cpv(0, -300);
staticBody = &g_Space->staticBody;
shape = cpSpaceAddShape(g_Space, cpSegmentShapeNew(staticBody, cpv(-400,-290), cpv(-400,300), 0.0f));
shape->e = 1.0f; shape->u = 0.0f;
shape->collision_type = PLATFORM_TYPE;
cannonPos = cpv(-350, -215);
g_Cannon = createCannon(cannonPos, 30.0f, 6.0f);
g_Cannon->ai = 0;
for (i = 0; i < MAX_PROJECTILES; ++i) {
g_Cannon->ammo[i] = createProjectile(6.0f, 1.0f);
}
platforms[0] = createPlatform(staticBody, cpv(-390, -240), cpv(1600, -240), 10.0f);
fprintf(stderr, "Loading dominoes disabled\n");
InitializeDominoes();
cpSpaceAddCollisionHandler(g_Space, PROJECTILE_TYPE, DOMINO_OBJECT_TYPE,
NULL, NULL, postSolveProjectileDomino, NULL, NULL);
return g_Space;
}
开发者ID:davidreynolds,项目名称:Atlas2D,代码行数:34,代码来源:main.c
示例20: cpPolyShapeNew
void ColliderDetector::setBody(cpBody *pBody)
{
_body = pBody;
for(auto& object : _colliderBodyList)
{
ColliderBody *colliderBody = (ColliderBody *)object;
ContourData *contourData = colliderBody->getContourData();
ssize_t num = contourData->vertexList.size();
auto vs = contourData->vertexList;
cpVect *verts = new cpVect[num];
for (int i = 0; i < num; i++)
{
verts[num - 1 - i].x = vs.at(i).x;
verts[num - 1 - i].y = vs.at(i).y;
}
cpShape *shape = cpPolyShapeNew(_body, (int)num, verts, cpvzero);
shape->sensor = true;
shape->data = _bone;
if (_active)
{
cpSpaceAddShape(_body->space_private, shape);
}
colliderBody->setShape(shape);
colliderBody->getColliderFilter()->updateShape(shape);
delete []verts;
}
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:35,代码来源:CCColliderDetector.cpp
注:本文中的cpSpaceAddShape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论