本文整理汇总了C++中cpSpaceNew函数的典型用法代码示例。如果您正苦于以下问题:C++ cpSpaceNew函数的具体用法?C++ cpSpaceNew怎么用?C++ cpSpaceNew使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpSpaceNew函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: physics_thread
static void physics_thread()
{
/* Now initialize the physics engine. */
cpInitChipmunk();
space = cpSpaceNew();
do
{
/* But here we do care about the elapsed time. */
synchronize(&oldtime /*,&server_elapsed*/);
simple_lock(&physics_lock);
physics(world, space);
cpSpaceHashEach(space->activeShapes, &draw_player, NULL);
//cpSpaceHashEach(space->staticShapes, &draw_static, NULL);
simple_unlock(&physics_lock);
if(to_remove_array.length > 0)
lDestroy(&to_remove_array, remove_unused);
}
while(!physics_exit_time);
lFree(&to_remove_array);
cpSpaceFreeChildren(space);
cpSpaceFree(space);
}
示例2: obj_create_autoreleased
World_t *world_create(void)
{
World_t *out = obj_create_autoreleased(&Class_World);
out->cpSpace = cpSpaceNew();
out->cpSpace->data = out;
cpSpaceAddCollisionHandler(out->cpSpace, 0, 0,
collisionWillBegin,
NULL,
collisionDidBegin,
collisionDidEnd, NULL);
out->entities = obj_retain(llist_create((InsertionCallback_t)&obj_retain, &obj_release));
// Create the static entity
out->staticEntity = obj_create(&Class_WorldEntity);
out->staticEntity->world = out;
out->staticEntity->owner = out;
out->staticEntity->cpBody = out->cpSpace->staticBody;
out->staticEntity->luaUpdateHandler = -1;
out->staticEntity->luaPreCollisionHandler = -1;
out->staticEntity->luaCollisionHandler = -1;
out->staticEntity->luaPostCollisionHandler = -1;
out->cpSpace->staticBody->data = out->staticEntity;
out->staticEntity->shapes = obj_retain(llist_create((InsertionCallback_t)&obj_retain, &obj_release));
return out;
}
示例3: fflush
World::World(cpVect size) {
space=cpSpaceNew();
static_body=cpBodyNewStatic();
printf("new space\n"); fflush(stdout);
cpVect s2=cpvmult(size,0.5);
cpVect c1=s2;
cpVect c2=cpv(s2.x,-s2.y);
cpVect c3=cpv(-s2.x,-s2.y);
cpVect c4=cpv(-s2.x,s2.y);
printf("foo space\n"); fflush(stdout);
cpBodyInitStatic(space->staticBody);
addStaticLine(c1,c2);
addStaticLine(c2,c3);
addStaticLine(c3,c4);
addStaticLine(c4,c1);
printf("space done\n"); fflush(stdout);
}
示例4: 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;
}
示例5: 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;
}
示例6: l_physics_newSpace
int l_physics_newSpace(lua_State* state)
{
moduleData.onBegin = false;
moduleData.onPostSolve = false;
moduleData.onPreSolve = false;
moduleData.onSeparate = false;
//moduleData.letBeginCollide = true;
//moduleData.letPreSolveCollide = true;
float x = l_tools_toNumberOrError(state, 1);
float y = l_tools_toNumberOrError(state, 2);
moduleData.physics = (l_physics_PhysicsData*)lua_newuserdata(state, sizeof(l_physics_PhysicsData));
moduleData.physics->physics = malloc(sizeof(physics_PhysicsData));
moduleData.physics->physics->space = cpSpaceNew();
moduleData.physics->physics->gravity = cpv(x, y);
cpSpaceSetGravity(moduleData.physics->physics->space, moduleData.physics->physics->gravity);
lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.physicsMT);
lua_setmetatable(state, -2);
return 1;
}
示例7: cpSpaceNew
bool PhysicsWorld::init()
{
do
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
_cpSpace = cpSpaceNew();
#else
_cpSpace = cpHastySpaceNew();
cpHastySpaceSetThreads(_cpSpace, 0);
#endif
CC_BREAK_IF(_cpSpace == nullptr);
cpSpaceSetGravity(_cpSpace, PhysicsHelper::point2cpv(_gravity));
cpCollisionHandler *handler = cpSpaceAddDefaultCollisionHandler(_cpSpace);
handler->userData = this;
handler->beginFunc = (cpCollisionBeginFunc)PhysicsWorldCallback::collisionBeginCallbackFunc;
handler->preSolveFunc = (cpCollisionPreSolveFunc)PhysicsWorldCallback::collisionPreSolveCallbackFunc;
handler->postSolveFunc = (cpCollisionPostSolveFunc)PhysicsWorldCallback::collisionPostSolveCallbackFunc;
handler->separateFunc = (cpCollisionSeparateFunc)PhysicsWorldCallback::collisionSeparateCallbackFunc;
return true;
} while (false);
return false;
}
示例8: 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;
}
示例9: eol_level_clear_layer_space
void eol_level_clear_layer_space(eolLevelLayer *layer)
{
if (!layer)
{
return;
}
if (layer->space != NULL)
{
cpSpaceFree(layer->space);
}
layer->space = cpSpaceNew();
if (layer->space == NULL)
{
eol_logger_message(
EOL_LOG_ERROR,
"Unable to create a physics space for new layer!");
eol_level_delete_layer(layer);
return;
}
layer->space->iterations = _eol_level_clip_iterations;
layer->space->sleepTimeThreshold = 999999;
cpSpaceSetEnableContactGraph(layer->space,eolTrue);
cpSpaceSetCollisionSlop(layer->space, _eol_level_slop);
cpSpaceSetCollisionBias(layer->space, _eol_level_bias);
}
示例10: 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);
}
示例11: make_rp_space
VALUE
make_rp_space(VALUE mod) {
cpSpace *space = cpSpaceNew();
// printf("rpm: integrations: %d\n", space->iterations);
return (VALUE)space;
}
示例12: space_allocate
static VALUE
space_allocate(VALUE cls) {
cpSpace *space = cpSpaceNew();
// printf("new called: %d, %p\n", space->iterations, space);
// printf("rpm: integrations: %d\n", space->iterations);
return Data_Wrap_Struct(cls, space_mark, space_free, space);
}
示例13: cpSpaceNew
Physics::Physics(uint32 timeStep) {
// Create an empty space.
mSpace = cpSpaceNew();
cpSpaceSetGravity(mSpace, cpv(0, 0));
cpSpaceSetDamping(mSpace, 0.5);
mTimeStep = timeStep;
mAccumulator = 0;
}
示例14: cpSpaceNew
PhysicsWorld::PhysicsWorld()
{
mySpace = cpSpaceNew();
// Set default gravity
cpVect gravity = cpv(0, -10);
cpSpaceSetGravity(mySpace, gravity);
}
示例15: space
Space::Space(void)
: space(cpSpaceNew()),
data(0),
body(new cp::Body(cpSpaceGetStaticBody(space)))
{
space->data = this;
cpBodySetUserData(cpSpaceGetStaticBody(space), body);
}