本文整理汇总了C++中cpBodyNew函数的典型用法代码示例。如果您正苦于以下问题:C++ cpBodyNew函数的具体用法?C++ cpBodyNew怎么用?C++ cpBodyNew使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpBodyNew函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: 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
示例3: init
// Init is called by the demo code to set up the demo.
static cpSpace *
init(void)
{
// Create an infinite mass body to attach ground segments and other static geometry to.
// We won't be adding this body to the space, because we don't want it to be simulated at all.
// Adding bodies to the space simulates them. (fall under the influence of gravity, etc)
// We want the static body to stay right where it is at all times.
staticBody = cpBodyNew(INFINITY, INFINITY);
// Create a space, a space is a simulation world. It simulates the motions of rigid bodies,
// handles collisions between them, and simulates the joints between them.
space = cpSpaceNew();
// Lets set some parameters of the space:
// More iterations make the simulation more accurate but slower
space->iterations = 10;
// These parameters tune the efficiency of the collision detection.
// For more info: http://code.google.com/p/chipmunk-physics/wiki/cpSpace
cpSpaceResizeStaticHash(space, 30.0f, 1000);
cpSpaceResizeActiveHash(space, 30.0f, 1000);
// Give it some gravity
space->gravity = cpv(0, -100);
// Create A ground segment along the bottom of the screen
cpShape *ground = cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f);
// Set some parameters of the shape.
// For more info: http://code.google.com/p/chipmunk-physics/wiki/cpShape
ground->e = 1.0f; ground->u = 1.0f;
ground->layers = NOT_GRABABLE_MASK; // Used by the Demo mouse grabbing code
// Add the shape to the space as a static shape
// If a shape never changes position, add it as static so Chipmunk knows it only needs to
// calculate collision information for it once when it is added.
// Do not change the postion of a static shape after adding it.
cpSpaceAddStaticShape(space, ground);
// Add a moving circle object.
cpFloat radius = 15.0f;
cpFloat mass = 10.0f;
// This time we need to give a mass and moment of inertia when creating the circle.
cpBody *ballBody = cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, radius, cpvzero));
// Set some parameters of the body:
// For more info: http://code.google.com/p/chipmunk-physics/wiki/cpBody
ballBody->p = cpv(0, -240 + radius+5);
// Add the body to the space so it will be simulated and move around.
cpSpaceAddBody(space, ballBody);
// Add a circle shape for the ball.
// Shapes are always defined relative to the center of gravity of the body they are attached to.
// When the body moves or rotates, the shape will move with it.
// Additionally, all of the cpSpaceAdd*() functions return the thing they added so you can create and add in one go.
cpShape *ballShape = cpSpaceAddShape(space, cpCircleShapeNew(ballBody, radius, cpvzero));
ballShape->e = 0.0f; ballShape->u = 0.9f;
return space;
}
开发者ID:18702515007xjy,项目名称:cocos2d,代码行数:57,代码来源:Simple.c
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: 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
示例9: mkparticle
int mkparticle(particle_kind_t kind, cpVect pos, cpVect impulse, double energy)
{
particle_t* p = malloc(sizeof *p);
if(p == NULL) {
return -1; // bad malloc
}
cpSpace* space = current_space();
cpBody* body = cpBodyNew(energy / 1000.0, particle_moi);
cpShape* shape = cpCircleShapeNew(body, particle_r, cpvzero);
cpBodySetUserData(body, p);
cpShapeSetUserData(shape, p);
cpSpaceAddBody(space, body);
cpSpaceAddShape(space, shape);
*p = (particle_t){
.id = id,
.kind = kind,
.energy = energy,
.life = energy,
.body = body
};
HASH_ADD_INT(particles, id, p);
return id++;
}
开发者ID:niksaak,项目名称:dame,代码行数:25,代码来源:particle.c
示例10: Shell
Shell(cpVect pos, cpVect vel, float angle)
{
cpVect vl[4] = {cpv(0, 0), cpv(0.1, 0), cpv(0.07, 0.3), cpv(0.03, 0.3)};
int vn = sizeof(vl)/sizeof(cpVect);
float mass = cpAreaForPoly(vn, vl, 0) * shell_density;
float moi = cpMomentForPoly(mass, vn, vl, cpv(0, 0), 0);
body = cpBodyNew(mass, moi);
cpshape = cpPolyShapeNew(body, vn, vl, cpTransformIdentity, 0);
cpShapeSetFriction(cpshape, 0.9);
cpVect centroid = cpCentroidForPoly(vn, vl);
shape.setPointCount(vn);
for (int i = 0; i < vn; i++)
{
shape.setPoint(i, sf::Vector2f(vl[i].x, vl[i].y));
}
cpBodySetCenterOfGravity(body, centroid);
cpBodySetPosition(body, pos-centroid);
cpBodySetVelocity(body, vel);
cpBodySetAngle(body, angle);
cpShapeSetCollisionType(cpshape, 2);
cpShapeSetUserData(cpshape, this);
}
开发者ID:cyclohexanamine,项目名称:shipbrain,代码行数:28,代码来源:main.cpp
示例11: physics_add
void physics_add(Entity ent)
{
PhysicsInfo *info;
if (entitypool_get(pool, ent))
return; /* already has physics */
transform_add(ent);
info = entitypool_add(pool, ent);
info->mass = 1.0;
info->type = PB_DYNAMIC;
/* create, init cpBody */
info->body = cpSpaceAddBody(space, cpBodyNew(info->mass, 1.0));
cpBodySetUserData(info->body, ent); /* for cpBody -> Entity mapping */
cpBodySetPos(info->body, cpv_of_vec2(transform_get_position(ent)));
cpBodySetAngle(info->body, transform_get_rotation(ent));
info->last_dirty_count = transform_get_dirty_count(ent);
/* initially no shapes */
info->shapes = array_new(ShapeInfo);
/* initialize last_pos/last_ang info for kinematic bodies */
info->last_pos = cpBodyGetPos(info->body);
info->last_ang = cpBodyGetAngle(info->body);
info->collisions = NULL;
}
开发者ID:andi2,项目名称:cgame,代码行数:30,代码来源:physics.c
示例12: add_box
static void
add_box(cpSpace *space)
{
const cpFloat size = 10.0f;
const cpFloat mass = 1.0f;
cpVect verts[] = {
cpv(-size,-size),
cpv(-size, size),
cpv( size, size),
cpv( size,-size),
};
cpFloat radius = cpvlength(cpv(size, size));
cpVect pos = rand_pos(radius);
cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, 4, verts, cpvzero, 0.0f)));
body->velocity_func = planetGravityVelocityFunc;
cpBodySetPosition(body, pos);
// Set the box's velocity to put it into a circular orbit from its
// starting position.
cpFloat r = cpvlength(pos);
cpFloat v = cpfsqrt(gravityStrength / r) / r;
cpBodySetVelocity(body, cpvmult(cpvperp(pos), v));
// Set the box's angular velocity to match its orbital period and
// align its initial angle with its position.
cpBodySetAngularVelocity(body, v);
cpBodySetAngle(body, cpfatan2(pos.y, pos.x));
cpShape *shape = cpSpaceAddShape(space, cpPolyShapeNew(body, 4, verts, cpTransformIdentity, 0.0));
cpShapeSetElasticity(shape, 0.0f);
cpShapeSetFriction(shape, 0.7f);
}
开发者ID:Ben-G,项目名称:spritebuilder-angrybirds,代码行数:35,代码来源:Planet.c
示例13: main
int
main(int argc, const char **argv)
{
cpInitChipmunk();
cp_collision_slop = 0.2f;
#ifdef TIME_TRIAL
sleep(1);
for(int i=0; i<demoCount; i++){
if(i == 'l' - 'a') continue;
time_trial(i, 1000);
}
// time_trial(0, 1000);
exit(0);
#endif
mouseBody = cpBodyNew(INFINITY, INFINITY);
glutStuff(argc, argv);
runDemo(demos[firstDemoIndex]);
glutMainLoop();
return 0;
}
开发者ID:JulianSpillane,项目名称:moai-dev,代码行数:25,代码来源:ChipmunkDemo.c
示例14: erl_element
ETERM *space_add_body(ETERM *fromp, ETERM *argp) {
// get the args
ETERM *space_refp = erl_element(1, argp);
ETERM *idp = erl_element(2, argp);
ETERM *massp = erl_element(3, argp);
// ETERM *inertiap = erl_element(4, argp);
erlmunk_space *s;
int space_id = ERL_REF_NUMBER(space_refp);
HASH_FIND_INT(erlmunk_spaces, &space_id, s);
int object_id = ERL_INT_VALUE(idp);
cpBody *body = cpSpaceAddBody(s->space,
cpBodyNew(ERL_FLOAT_VALUE(massp),
INFINITY));
// the body is created inactive, it is explicitly activated
// when all it's values have been set.
cpBodySleep(body);
erlmunk_body_data *data = malloc(sizeof(erlmunk_body_data));
data->id = object_id;
data->term = NULL;
cpBodySetUserData(body, (cpDataPointer) data);
space_add_body_hash(s, object_id, body);
return NULL;
}
开发者ID:lrascao,项目名称:erlmunk,代码行数:28,代码来源:erlmunk_space.c
示例15: 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
示例16: 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
示例17: do_logic
static void
do_logic(game_state *state)
{
switch_state_data *data = state->data->switch_data;
if (data->mouse_down_last_step && state->game->mouse_down == false)
{
/* clicked and released; create a circle */
cpFloat radius = 15;
cpFloat mass = 10;
cpFloat moment = cpMomentForCircle(mass, 0, radius, cpvzero);
cpBody *ball = cpSpaceAddBody(data->space, cpBodyNew(mass, moment));
cpBodySetPos(ball, state->game->mouse_pos);
cpShape *ball_shape = cpSpaceAddShape(data->space,
cpCircleShapeNew(ball, radius, cpvzero));
cpShapeSetElasticity(ball_shape, 0.7);
cpShapeSetFriction(ball_shape, 0.7);
cpShapeSetLayers(ball_shape, L_PLAYER);
}
cpSpaceStep(data->space, TARGET_SEC_PER_FRAME);
data->mouse_down_last_step = state->game->mouse_down;
if (ent_switch_get_state(data->sw))
debug_puts("switch is on");
else
debug_puts("switch is off");
}
开发者ID:hdgarrood,项目名称:swinging-game,代码行数:31,代码来源:switch_state.c
示例18: cpSpaceRemoveShape
void WordTreeScene::updatePhysics(Word* word) {
cpShape* shape = word->getShape();
if( shape!=NULL ) {
cpSpaceRemoveShape(ChipmunkManager::getInstance()->getSpace(), shape);
cpShapeDestroy(shape);
word->setShape(NULL);
}
cpBody* body = word->getBody();
if( body!=NULL ) {
cpSpaceRemoveBody(ChipmunkManager::getInstance()->getSpace(), body);
cpBodyDestroy(body);
word->setBody(NULL);
}
CCLabelTTF* targetLabel = word->getLabel();
CCPoint pos = targetLabel->getPosition();
CCSize contentSize = targetLabel->getContentSize();
// init body
body = cpBodyNew(1, INFINITY);
body->p = cpv(targetLabel->getPosition().x, targetLabel->getPosition().y);
cpSpaceAddBody(ChipmunkManager::getInstance()->getSpace(), body);
float size = MAX(targetLabel->getContentSize().width, targetLabel->getContentSize().height);
shape = cpBoxShapeNew(body, size+size*0.3f, size+size*0.3f);
cpSpaceAddShape(ChipmunkManager::getInstance()->getSpace(), shape);
word->setBody(body);
word->setShape(shape);
}
开发者ID:GoodMorningCody,项目名称:WordTree,代码行数:32,代码来源:WordTreeScene.cpp
示例19: cpSpaceNew
void TestColliderDetector::initWorld()
{
//! create physic space
space = cpSpaceNew();
//! set space gravity as no gravity
space->gravity = cpv(0, 0);
//! Physics debug layer
CCPhysicsDebugNode *debugLayer = CCPhysicsDebugNode::create(space);
this->addChild(debugLayer, INT_MAX);
//! get size of bullet
CCSize size = bullet->getContentSize();
//! define bullet's collider body
int num = 4;
cpVect verts[] = {
cpv(-size.width/2,-size.height/2),
cpv(-size.width/2,size.height/2),
cpv(size.width/2,size.height/2),
cpv(size.width/2,-size.height/2),
};
//! build body as verts' shape
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
cpSpaceAddBody(space, body);
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
shape->collision_type = eBulletTag;
cpSpaceAddShape(space, shape);
bullet->setCPBody(body);
//! define armature2's body,get shape from armature data
body = cpBodyNew(INFINITY, INFINITY);
cpSpaceAddBody(space, body);
armature2->setCPBody(body);
shape = body->shapeList_private;
while(shape){
cpShape *next = shape->next_private;
shape->collision_type = eEnemyTag;
shape = next;
}
cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL);
}
开发者ID:chengstory,项目名称:CocoStudioSamples,代码行数:47,代码来源:TestColliderDetector.cpp
示例20: createNewBodyFrom
cpBody* createNewBodyFrom(cpSpace* space, cpFloat xPos, cpFloat yPos, cpFloat mass, cpFloat moment, JSObject* outterJsObj)
{
cpBody* circularBody = cpSpaceAddBody(space, cpBodyNew(mass, moment));
cpBodySetPos(circularBody, cpv(xPos, yPos));
cpBodySetUserData(circularBody, outterJsObj);
return circularBody;
}
开发者ID:dumganhar,项目名称:sugs_spiderMonkey,代码行数:8,代码来源:body.cpp
注:本文中的cpBodyNew函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论