static VALUE rb_cpBodyInitialize(VALUE self, VALUE m, VALUE i) { cpBody *body = BODY(self); cpBodyInit(body, NUM2DBL(m), NUM2DBL(i)); body->data = (void *)self; return self; }
cpSpace* cpSpaceInit(cpSpace *space) { #ifndef NDEBUG static cpBool done = cpFalse; if(!done){ printf("Initializing cpSpace - Chipmunk v%s (Debug Enabled)\n", cpVersionString); printf("Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks\n"); done = cpTrue; } #endif space->iterations = 10; space->gravity = cpvzero; space->damping = 1.0f; space->collisionSlop = 0.1f; space->collisionBias = cpfpow(1.0f - 0.1f, 60.0f); space->collisionPersistence = 3; space->locked = 0; space->stamp = 0; space->shapeIDCounter = 0; space->staticShapes = cpBBTreeNew((cpSpatialIndexBBFunc)cpShapeGetBB, NULL); space->dynamicShapes = cpBBTreeNew((cpSpatialIndexBBFunc)cpShapeGetBB, space->staticShapes); cpBBTreeSetVelocityFunc(space->dynamicShapes, (cpBBTreeVelocityFunc)ShapeVelocityFunc); space->allocatedBuffers = cpArrayNew(0); space->dynamicBodies = cpArrayNew(0); space->staticBodies = cpArrayNew(0); space->sleepingComponents = cpArrayNew(0); space->rousedBodies = cpArrayNew(0); space->sleepTimeThreshold = INFINITY; space->idleSpeedThreshold = 0.0f; space->arbiters = cpArrayNew(0); space->pooledArbiters = cpArrayNew(0); space->contactBuffersHead = NULL; space->cachedArbiters = cpHashSetNew(0, (cpHashSetEqlFunc)arbiterSetEql); space->constraints = cpArrayNew(0); space->usesWildcards = cpFalse; space->defaultHandler = cpCollisionHandlerDoNothing; space->collisionHandlers = cpHashSetNew(0, (cpHashSetEqlFunc)handlerSetEql); space->postStepCallbacks = cpArrayNew(0); space->skipPostStep = cpFalse; cpBody *staticBody = cpBodyInit(&space->_staticBody, 0.0f, 0.0f); cpBodySetType(staticBody, CP_BODY_TYPE_STATIC); cpSpaceSetStaticBody(space, staticBody); return space; }
static int cpBody_new (lua_State *L) { cpFloat m = (cpFloat)luaL_checknumber (L, 1); cpFloat i = (cpFloat)luaL_checknumber (L, 2); cpBody *b = push_cpBody(L); cpBodyInit(b, m, i); return 1; }
/** * Initializes a new player. * The player is placed in the queue of available players. */ struct player *player_init(struct player *p, struct game *g, double x, double y, double w, double h, uint32_t score, uint8_t data) { cpVect all[4] = {cpv(0,0), cpv(0,h), cpv(w,h), cpv(w,0)}; cpBody *body = cpBodyInit(&p->body, 10, cpMomentForBox(10, w, h)); if (!body) { ERR_ERRNO(); return 0; } cpBodySetPos(body, cpv(x,y)); //cpShape *shape = cpPolyShapeNew(body,4,all,cpv((p->l+p->r)/2.0,(p->b+p->t)/2.0)); cpShape *shape = cpPolyShapeInit(&p->shape, body, 4, all, cpv(0, 0)); if (!shape) { ERR_ERRNO(); cpBodyDestroy(body); return 0; } shape->data = p; shape->collision_type = PLAYER; if (linkedlist_add_last(g->p_q, p)) { ERR_TRACE(); cpBodyDestroy(body); cpShapeDestroy(shape); return 0; } p->x = x; p->y = y; p->node = g->p_q->last; return p; }
cpBody * cpBodyInitStatic(cpBody *body) { cpBodyInit(body, (cpFloat)INFINITY, (cpFloat)INFINITY); body->node.idleTime = (cpFloat)INFINITY; return body; }
fff::kitty::kitty(){ body = cpBodyNew(1.f, INFINITY); cpBodySetUserData(body, this); forecastspace = cpSpaceNew(); cpSpaceSetIterations(forecastspace, 100); cpBodyInit(&forecastbody, 1.f, INFINITY); cpSpaceSetGravity(forecastspace, (cpVect){0.f, METERSTOPIXELS(10.f)} ); cpSpaceAddBody(forecastspace, &forecastbody); iflames = 0; burstinflames = false; leftimpulse = false; rightimpulse = false; }
cpSpace* cpSpaceInit(cpSpace *space) { space->iterations = DEFAULT_ITERATIONS; space->elasticIterations = DEFAULT_ELASTIC_ITERATIONS; // space->sleepTicks = 300; space->gravity = cpvzero; space->damping = 1.0f; space->locked = 0; space->stamp = 0; space->staticShapes = cpSpaceHashNew(DEFAULT_DIM_SIZE, DEFAULT_COUNT, (cpSpaceHashBBFunc)shapeBBFunc); space->activeShapes = cpSpaceHashNew(DEFAULT_DIM_SIZE, DEFAULT_COUNT, (cpSpaceHashBBFunc)shapeBBFunc); space->allocatedBuffers = cpArrayNew(0); space->bodies = cpArrayNew(0); space->sleepingComponents = cpArrayNew(0); space->sleepTimeThreshold = INFINITY; space->idleSpeedThreshold = 0.0f; space->arbiters = cpArrayNew(0); space->pooledArbiters = cpArrayNew(0); cpContactBufferHeader *header = cpContactBufferHeaderInit(cpSpaceAllocContactBuffer(space), space); space->contactBuffersHead = header; space->contactBuffersTail = header; header->next = header; // Buffers will form a ring, start the ring explicitly space->contactSet = cpHashSetNew(0, (cpHashSetEqlFunc)contactSetEql, (cpHashSetTransFunc)contactSetTrans); space->constraints = cpArrayNew(0); space->defaultHandler = defaultHandler; space->collFuncSet = cpHashSetNew(0, (cpHashSetEqlFunc)collFuncSetEql, (cpHashSetTransFunc)collFuncSetTrans); space->collFuncSet->default_value = &space->defaultHandler; space->postStepCallbacks = cpHashSetNew(0, (cpHashSetEqlFunc)postStepFuncSetEql, (cpHashSetTransFunc)postStepFuncSetTrans); cpBodyInit(&space->staticBody, INFINITY, INFINITY); space->staticBody.space = space; return space; }
/** * Initialize a bubble that will bounce around. * \param b The bubble to initialize. * \param x The x location of the bubble. * \param y The y location of the bubble. * \param v_x The x velocity of the bubble. * \param v_y The y velocity of the bubble. * \param r The radius of the bubble. * \param l The bubble's life. */ struct bubble *bubble_init(struct bubble *b, double x, double y, double v_x, double v_y, double r, uint8_t l) { cpBody *body = cpBodyInit(&b->body, r, cpMomentForCircle(r, 0, r, cpv(0, 0))); if (!body) { ERR_ERRNO(); return 0; } cpShape *shape = cpCircleShapeInit(&b->shape, body, r, cpv(0,0)); if (!shape) { cpBodyDestroy(body); ERR_ERRNO(); return 0; } cpBodySetVel(body, cpv(v_x, v_y)); cpBodySetPos(body, cpv(x, y)); shape->e = 1.0; shape->data = b; shape->collision_type = BUBBLE; b->l = l; return b; }
cpBody* cpBodyNew(cpFloat m, cpFloat i) { return cpBodyInit(cpBodyAlloc(), m, i); }
static int cpBody_newStatic (lua_State *L) { cpBody *b = push_cpBody(L); cpBodyInit(b, INFINITY, INFINITY); return 1; }