当前位置: 首页>>代码示例>>C++>>正文


C++ cpSpaceAddBody函数代码示例

本文整理汇总了C++中cpSpaceAddBody函数的典型用法代码示例。如果您正苦于以下问题:C++ cpSpaceAddBody函数的具体用法?C++ cpSpaceAddBody怎么用?C++ cpSpaceAddBody使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cpSpaceAddBody函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: _set_type

static void _set_type(PhysicsInfo *info, PhysicsBody type)
{
    if (info->type == type)
        return; /* already set */

    info->type = type;
    switch (type)
    {
        case PB_KINEMATIC:
            info->last_pos = cpBodyGetPos(info->body);
            info->last_ang = cpBodyGetAngle(info->body);
            /* fall through */

        case PB_STATIC:
            if (!cpBodyIsStatic(info->body))
            {
                cpSpaceRemoveBody(space, info->body);
                cpSpaceConvertBodyToStatic(space, info->body);
            }
            break;

        case PB_DYNAMIC:
            cpSpaceConvertBodyToDynamic(space, info->body, info->mass, 1.0);
            cpSpaceAddBody(space, info->body);
            _recalculate_moment(info);
            break;
    }
}
开发者ID:andi2,项目名称:cgame,代码行数:28,代码来源:physics.c

示例8: world_addEntity

void world_addEntity(World_t *aWorld, WorldEntity_t *aEntity)
{
    dynamo_assert(aEntity != aWorld->staticEntity, "You cannot re-add static entity to world");
    cpSpaceAddBody(aWorld->cpSpace, aEntity->cpBody);
    llist_apply(aEntity->shapes, (LinkedListApplier_t)&_addShapeToSpace, aWorld);
    llist_pushValue(aWorld->entities, aEntity);
}
开发者ID:fjolnir,项目名称:Dynamo,代码行数:7,代码来源:world.c

示例9: 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

示例10: 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

示例11: lc_space_AddBody

int lc_space_AddBody(lua_State *vm){
    //space, body
    lc_space *space = lc_GetSpace(1, vm);
    if (space == NULL){
        printf("chipmunk: Object can't call :AddBody\n");
        return 0;
    }
    lc_body *body = lc_GetBody(2, vm);
    if (body == NULL){
        printf("space:AddBody(): Can't add a object that isn't a body.\n");
        return 0;
    }
        
    char pbody[32] = {0};
    snprintf(pbody, 32, "%p", body);
    
    //Check if the body exists in bodies table. If not exists then add to the table
    lua_rawgeti(vm, LUA_REGISTRYINDEX, space->bodies);
    lua_getfield(vm, -1, pbody);
    if (!lua_isnil(vm, -1)){
        //The body already exists. Then return.
        return 0;
    }
    lua_pop(vm, 1);
    lua_pushvalue(vm, 2);
    lua_setfield(vm, -2, pbody);
    lua_pop(vm, 1);//bodies table
    //---
    
    cpSpaceAddBody(space->space, body->body);
    return 0;
}
开发者ID:sixian,项目名称:lunatic-chipmunk,代码行数:32,代码来源:space.c

示例12: cpSpaceConvertBodyToDynamic

void PhysicsBody::setDynamic(bool dynamic)
{
    if (dynamic != _dynamic)
    {
        _dynamic = dynamic;
        if (dynamic)
        {
            if (_world && _cpBody->CP_PRIVATE(space))
            {
                cpSpaceConvertBodyToDynamic(_world->_cpSpace, _cpBody, _mass, _moment);
                cpSpaceAddBody(_world->_cpSpace, _cpBody);
            }
            else
            {
                cpBodySetMass(_cpBody, _mass);
                cpBodySetMoment(_cpBody, _moment);
            }
        }
        else
        {
            if (_world && _cpBody->CP_PRIVATE(space))
            {
                cpSpaceRemoveBody(_world->_cpSpace, _cpBody);
                cpSpaceConvertBodyToStatic(_world->_cpSpace, _cpBody);
            }
            else
            {
                cpBodySetMass(_cpBody, PHYSICS_INFINITY);
                cpBodySetMoment(_cpBody, PHYSICS_INFINITY);
                cpBodySetVel(_cpBody, cpvzero);
                cpBodySetAngVel(_cpBody, 0.0);
            }
        }
    }
}
开发者ID:Realtrick-Games,项目名称:DeadForest,代码行数:35,代码来源:CCPhysicsBody.cpp

示例13: 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

示例14: 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

示例15: 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


注:本文中的cpSpaceAddBody函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。