本文整理汇总了C++中cpSegmentShapeNew函数的典型用法代码示例。如果您正苦于以下问题:C++ cpSegmentShapeNew函数的具体用法?C++ cpSegmentShapeNew怎么用?C++ cpSegmentShapeNew使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpSegmentShapeNew函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parts
MachineSystem::MachineSystem(int width, int height, int hPegs, int vPegs, cpVect position)
: parts(hPegs*vPegs),
attachments((hPegs*vPegs), std::vector<Attachment *>(hPegs*vPegs, NULL)),
space(cpSpaceNew()),
nMachines(0),
nAttachments(0)
{
cpSpaceSetIterations(space, 20);
gridSpacing = cpv((float)width/(hPegs + 1), (float)height/(vPegs + 1));
size = cpv(hPegs, vPegs);
body = cpBodyNewStatic();
cpBodySetPos(body, position);
cpShape *wallShape = cpSegmentShapeNew(body, cpv(-width/2, height/2), cpv(width/2, height/2), .5);
cpShapeSetLayers(wallShape, WALL_LAYER);
cpSpaceAddStaticShape(space, wallShape);
wallShape = cpSegmentShapeNew(body, cpv(-width/2, -height/2), cpv(+width/2, -height/2), 0.5);
cpShapeSetLayers(wallShape, WALL_LAYER);
cpSpaceAddStaticShape(space, wallShape);
wallShape = cpSegmentShapeNew(body, cpv(-width/2, +height/2), cpv(-width/2, -height/2), 0.5);
cpShapeSetLayers(wallShape, WALL_LAYER);
cpSpaceAddStaticShape(space, wallShape);
wallShape = cpSegmentShapeNew(body, cpv(+width/2, +height/2), cpv(+width/2, -height/2), 0.5);
cpShapeSetLayers(wallShape, WALL_LAYER);
cpSpaceAddStaticShape(space, wallShape);
inputMachinePosition = cpv(-1,-1);
outputMachinePosition = cpv(-1,-1);
}
开发者ID:thecodemaiden,项目名称:machine-generator,代码行数:33,代码来源:MachineSystem.cpp
示例2: cpBodyNewStatic
void LevelGrid::InitializeLevelPhysics(void)
{
// Fetch the physics space
cpSpace *space = this->m_Engine->GetWorld()->GetSpace();
// Add the physics body
this->m_Body = cpBodyNewStatic();
// Add the physics shapes
for (int i = 0 ; i < this->m_NumY - 1 ; ++i)
{
hgeVector *vec = this->m_LeftLevelVertices[i];
hgeVector *nvec = this->m_LeftLevelVertices[i + 1];
cpShape *shape = cpSegmentShapeNew(this->m_Body, cpv(vec->x, vec->y), cpv(nvec->x, nvec->y), 0.0f);
shape->e = 1.0; shape->u = 1.0;
shape->collision_type = COLLISION_TYPE_LEVEL;
cpSpaceAddStaticShape(space, shape);
cpBodyActivateStatic(this->m_Body, shape);
this->m_Shapes.push_back(shape);
}
for (int i = 0 ; i < this->m_NumY - 1 ; ++i)
{
hgeVector *vec = this->m_RightLevelVertices[i];
hgeVector *nvec = this->m_RightLevelVertices[i + 1];
cpShape *shape = cpSegmentShapeNew(this->m_Body, cpv(vec->x, vec->y), cpv(nvec->x, nvec->y), 0.0f);
shape->e = 1.0; shape->u = 1.0;
shape->collision_type = COLLISION_TYPE_LEVEL;
cpSpaceAddStaticShape(space, shape);
cpBodyActivateStatic(this->m_Body, shape);
this->m_Shapes.push_back(shape);
}
// Create the activator physics shapes
for (int i = 0 ; i < this->m_NumActivators ; ++i)
{
Activator *activator = this->m_Activators[i];
// Create the cpVects
cpVect *verts = (cpVect*) malloc(sizeof(cpVect) * 4);
verts[3].x = activator->Vertices[0].x; verts[3].y = activator->Vertices[0].y;
verts[2].x = activator->Vertices[1].x; verts[2].y = activator->Vertices[1].y;
verts[1].x = activator->Vertices[2].x; verts[1].y = activator->Vertices[2].y;
verts[0].x = activator->Vertices[3].x; verts[0].y = activator->Vertices[3].y;
// Create and add the poly shape
cpShape *shape = cpPolyShapeNew(this->m_Body, 4, verts, cpvzero);
shape->e = 1.0; shape->u = 1.0;
shape->sensor = true;
shape->collision_type = COLLISION_TYPE_ACTIVATOR;
shape->data = activator;
cpSpaceAddStaticShape(space, shape);
cpBodyActivateStatic(this->m_Body, shape);
this->m_Shapes.push_back(shape);
free(verts);
}
}
开发者ID:ofx,项目名称:dr,代码行数:59,代码来源:LevelGrid.cpp
示例3: 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
示例4: init
static cpSpace *
init(void)
{
staticBody = cpBodyNew(INFINITY, INFINITY);
cpResetShapeIdCounter();
space = cpSpaceNew();
cpSpaceResizeActiveHash(space, 30.0f, 1000);
space->iterations = 10;
cpShape *shape;
// Create segments around the edge of the screen.
shape = cpSpaceAddStaticShape(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 = cpSpaceAddStaticShape(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 = cpSpaceAddStaticShape(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 = cpSpaceAddStaticShape(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.0, 1.0);
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.0, 10.0);
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:0w,项目名称:moai-dev,代码行数:57,代码来源:Tank.c
示例5: 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
示例6: init
static cpSpace *
init(void)
{
cpSpace *space = cpSpaceNew();
space->iterations = 10;
space->gravity = cpv(0, -GRAVITY);
// space->sleepTimeThreshold = 1000;
space->enableContactGraph = cpTrue;
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;
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;
// Set up the player
cpFloat radius = 25.0f;
body = cpSpaceAddBody(space, cpBodyNew(1.0f, INFINITY));
body->p = cpv(0, -200);
body->velocity_func = playerUpdateVelocity;
playerBody = body;
shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
shape->e = 0.0f; shape->u = 0.0f;
shape->collision_type = 1;
playerShape = shape;
// Add some boxes to jump on
for(int i=0; i<6; i++){
for(int j=0; j<3; j++){
body = cpSpaceAddBody(space, cpBodyNew(4.0f, INFINITY));
body->p = cpv(100 + j*60, -200 + i*60);
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 50, 50));
shape->e = 0.0f; shape->u = 0.7f;
}
}
return space;
}
开发者ID:1103785815,项目名称:wizardwar,代码行数:54,代码来源:Player.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)
{
cpSpace *space = cpSpaceNew();
space->iterations = 10;
space->gravity = cpv(0, -GRAVITY);
// space->sleepTimeThreshold = 1000;
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));
shape->e = 1.0f; shape->u = 1.0f;
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,240), cpv(320,240), 0.0f));
shape->e = 1.0f; shape->u = 1.0f;
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
// Set up the player
body = cpSpaceAddBody(space, cpBodyNew(1.0f, INFINITY));
body->p = cpv(0, -200);
body->velocity_func = playerUpdateVelocity;
playerBody = body;
shape = cpSpaceAddShape(space, cpBoxShapeNew2(body, cpBBNew(-15.0, -27.5, 15.0, 27.5), 10.0));
// shape = cpSpaceAddShape(space, cpSegmentShapeNew(playerBody, cpvzero, cpv(0, radius), radius));
shape->e = 0.0f; shape->u = 0.0f;
shape->type = 1;
playerShape = shape;
// Add some boxes to jump on
for(int i=0; i<6; i++){
for(int j=0; j<3; j++){
body = cpSpaceAddBody(space, cpBodyNew(4.0f, INFINITY));
body->p = cpv(100 + j*60, -200 + i*60);
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 50, 50, 0.0));
shape->e = 0.0f; shape->u = 0.7f;
}
}
return space;
}
开发者ID:00dazam,项目名称:FlappyBird-SpriteBuilder,代码行数:53,代码来源:Player.c
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: CC_BREAK_IF
bool PhysicsShapeEdgeSegment::init(const Point& a, const Point& b, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::EDGESEGMENT));
cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(),
PhysicsHelper::point2cpv(a),
PhysicsHelper::point2cpv(b),
PhysicsHelper::float2cpfloat(border));
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
_mass = PHYSICS_INFINITY;
_moment = PHYSICS_INFINITY;
_center = a.getMidpoint(b);
setMaterial(material);
return true;
} while (false);
return false;
}
开发者ID:12white,项目名称:CocoStudioSamples,代码行数:27,代码来源:CCPhysicsShape.cpp
示例15: obj_create_autoreleased
WorldShape_t *worldShape_createSegment(vec2_t a, vec2_t b, GLMFloat aThickness)
{
WorldShape_t *out = obj_create_autoreleased(&Class_WorldShape);
out->cpShape = cpSegmentShapeNew(NULL, VEC2_TO_CPV(a), VEC2_TO_CPV(b), aThickness);
out->cpShape->data = out;
return out;
}
开发者ID:fjolnir,项目名称:Dynamo,代码行数:7,代码来源:world.c
示例16: new
bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
{
cpVect* vec = nullptr;
do
{
_type = Type::EDGECHAIN;
vec = new (std::nothrow) cpVect[count];
PhysicsHelper::points2cpvs(points, vec, count);
int i = 0;
for (; i < count - 1; ++i)
{
auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[i + 1], border);
CC_BREAK_IF(shape == nullptr);
cpShapeSetUserData(shape, this);
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
addShape(shape);
}
CC_SAFE_DELETE_ARRAY(vec);
CC_BREAK_IF(i < count - 1);
_mass = PHYSICS_INFINITY;
_moment = PHYSICS_INFINITY;
setMaterial(material);
return true;
} while (false);
CC_SAFE_DELETE_ARRAY(vec);
return false;
}
开发者ID:114393824,项目名称:Cocos2dxShader,代码行数:35,代码来源:CCPhysicsShape.cpp
示例17: post_step_body_replace_shapes
static void post_step_body_replace_shapes(cpSpace *space, cpBody *body, void *data) {
Body_data *pa = cpBodyGetUserData(body);
int length = pa->x_values->len;
cpBodyEachShape(body, (cpBodyShapeIteratorFunc) free_shape, NULL);
cpSpaceReindexShapesForBody(space, body);
//fprintf(stderr, "0Made it this far.\n");
for (int index = 1; index < length; index++) {
cpFloat x = g_array_index(pa->x_values, cpFloat, index);
cpFloat y = g_array_index(pa->y_values, cpFloat, index);
cpShape *seg = cpSegmentShapeNew(body, cpv(x,y), cpv(g_array_index(pa->x_values, cpFloat, index - 1), g_array_index(pa->y_values, cpFloat, index - 1)), CRAYON_RADIUS);
//fprintf(stderr, "1Made it this far.\n");
cpShapeSetFriction(seg, CRAYON_FRICTION);
//fprintf(stderr, "2Made it this far.\n");
//cpShapeSetElasticity(cpShape *shape, cpFloat value)?
cpSpaceAddShape(space, seg);
//fprintf(stderr, "3Made it this far.\n");
}
cpSpaceReindexShapesForBody(space, body);
}
开发者ID:outgame,项目名称:CrayonPhysics,代码行数:25,代码来源:physics.c
示例18: 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
示例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: Point
bool PhysicsShapeEdgeBox::init(const Size& size, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/, const Point& offset/*= Point(0, 0)*/)
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::EDGEBOX));
cpVect vec[4] = {};
vec[0] = PhysicsHelper::point2cpv(Point(-size.width/2+offset.x, -size.height/2+offset.y));
vec[1] = PhysicsHelper::point2cpv(Point(+size.width/2+offset.x, -size.height/2+offset.y));
vec[2] = PhysicsHelper::point2cpv(Point(+size.width/2+offset.x, +size.height/2+offset.y));
vec[3] = PhysicsHelper::point2cpv(Point(-size.width/2+offset.x, +size.height/2+offset.y));
int i = 0;
for (; i < 4; ++i)
{
cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(), vec[i], vec[(i+1)%4],
PhysicsHelper::float2cpfloat(border));
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
}
CC_BREAK_IF(i < 4);
_offset = offset;
_mass = PHYSICS_INFINITY;
_moment = PHYSICS_INFINITY;
setMaterial(material);
return true;
} while (false);
return false;
}
开发者ID:12white,项目名称:CocoStudioSamples,代码行数:33,代码来源:CCPhysicsShape.cpp
注:本文中的cpSegmentShapeNew函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论