コード例 #1
0
ファイル: cbchipmunk.c プロジェクト: Latexi95/cbChipmunk
__declspec( dllexport ) void pullall( const void * _in, int in_size, void * _out, int out_sz )
{
	
	int i;
	cpBody *body;
	Variable *var;
	//int bodyCount = 0;
	int index = 0;

	for (i = 0;i != mVariableHandler.mSize;i++)
	{
		var = mVariableHandler.mPtrArray[i];
		if (var == NULL)continue;
		
		//Varmistetaan, että haetaan vain runkojen tiedot
		if (var->mType != VarTypeBody)continue;
		body = (cpBody*)var->mPtr;

		//Eikä staattisen tietoja
		if (cpBodyIsStatic(body))continue;

		//Alkuun cb:n muistipalan osoite
		POKEINT(OUTPUT_MEMBLOCK,index,var->mCBPtr);
		POKEFLOAT(OUTPUT_MEMBLOCK,index+4,radToDeg(cpBodyGetAngle(body)));
		POKEVECT(OUTPUT_MEMBLOCK,index+8,cpBodyGetPos(body));
		POKEFLOAT(OUTPUT_MEMBLOCK,index+16,radToDeg(cpBodyGetAngVel(body)));
		POKEVECT(OUTPUT_MEMBLOCK,index+20,cpBodyGetVel(body));
		index += 28;
		//bodyCount++;
	}
	//POKEINT(OUTPUT_MEMBLOCK,0,bodyCount);

}
コード例 #2
0
ファイル: cbchipmunk.c プロジェクト: Latexi95/cbChipmunk
//Hakee yhden muuttujan uudet arvot 
__declspec( dllexport ) void pull( const void * _in, int in_size, void * _out, int out_sz )
{
	int index;
	Variable *var;
	cpBody *body;
	cpShape *shape;

	index = PEEKINT(INPUT_MEMBLOCK,0);
	var = vhGetVariable(&mVariableHandler,index);
	switch (var->mType)
	{
	case VarTypeBody:
		body = (cpBody*)var->mPtr;
		
		POKEFLOAT(OUTPUT_MEMBLOCK,0,radToDeg(cpBodyGetAngle(body)));
		POKEVECT(OUTPUT_MEMBLOCK,4,cpBodyGetPos(body));
		POKEFLOAT(OUTPUT_MEMBLOCK,12,radToDeg(cpBodyGetAngVel(body)));
		POKEVECT(OUTPUT_MEMBLOCK,16,cpBodyGetVel(body));
		break;

	case VarTypeShape:
		shape = (cpShape*)var->mPtr;
		POKEINT(OUTPUT_MEMBLOCK,0,VarTypeShape);
		
	default:
		MessageBoxA(NULL,"cpPull: Invalid variable type","cpChipmunk error",MB_OK);
		exit(0);
		break;
	}
}
コード例 #3
0
ファイル: bubble.c プロジェクト: tjhsstgeek/MultiBT
/**
 * Pop the bubble splitting it into two bubbles.
 * No children are created if the bubble was too small.
 */
int bubble_pop(struct bubble *b, struct game *g) {
	if (b->l <= 1) {
		bubble_destroy(b);
		return 0;
	}
	double radius = cpCircleShapeGetRadius(&b->shape);
	cpVect pos = cpBodyGetPos(&b->body);
	cpVect vel = cpBodyGetVel(&b->body);
	bubble_remove(b, g);
	bubble_destroy(b);
	b = bubble_init(b, pos.x, pos.y, vel.x + 5, vel.y + 5,
	                radius / 2, b->l - 1);
	if (!b) {
		ERR_TRACE();
		return -1;
	}
	//b->events = b->events;
	if (bubble_add(b, g)) {
		ERR_TRACE();
		return -1;
	}
	struct bubble *c = bubble_create(pos.x, pos.y, vel.x - 5, vel.y + 5,
	                          radius / 2, b->l - 1);
	if (!c) {
		ERR_TRACE();
		return -1;
	}
	//c->events = b->events;
	if (bubble_add(c, g)) {
		ERR_TRACE();
		return -1;
	}
	return 0;
}
コード例 #4
0
ファイル: Gro.cpp プロジェクト: fmenol/gro
Value * tumble ( std::list<Value *> * args, Scope * s ) {

  World * world = current_gro_program->get_world();
  std::list<Value *>::iterator i = args->begin();

  float vel = (*i)->num_value(); 

  if ( current_cell != NULL ) {

    float a = current_cell->get_theta();
    cpBody * body = current_cell->get_body();
    cpVect v = cpBodyGetVel ( body );
    cpFloat adot = cpBodyGetAngVel ( body );

    cpBodySetTorque ( body, vel - adot ); // apply torque

    cpBodyApplyForce ( // damp translation
      current_cell->get_shape()->body, 
      cpv ( 
        - v.x * world->get_sim_dt(),
        - v.y * world->get_sim_dt()
      ), 
      cpv ( 0, 0 ) );

  } else

    printf ( "Warning: Tried to emit signal from outside a cell program. No action taken\n" );

  return new Value ( Value::UNIT );

}
コード例 #5
0
ファイル: move.c プロジェクト: sudoman/SpaceDolphin
// calculates and adds forces triggered by holding the movement keys down.
// it also has to stop the forces applied by the prev call to this function
void blastengines(struct objnode *player)
{
    struct movement *thrust;
    cpFloat force, tforce;
    struct forces newf;
    cpVect rotv;
    cpFloat angvel;

    thrust = &player->pinfo->thrust;
    rotv = cpBodyGetRot(player->b);

    force = 0;
    // these test cases are to enforce soft limits on the rate of movement
    if (thrust->up && !thrust->down) {
	if (cpvunrotate(cpBodyGetVel(player->b), rotv).y < MAXVEL)
	    force = FORCE;
    } else if (!thrust->up && thrust->down) {
	if (cpvunrotate(cpBodyGetVel(player->b), rotv).y > -MAXVEL)
	    force = -FORCE;
    }

    tforce = 0;
    angvel = cpBodyGetAngVel(player->b);
    if (thrust->ccw && !thrust->cw) {
	if (angvel < MAXANGVEL)
	    tforce += TFORCE;
    } else if (thrust->cw && !thrust->ccw) {
	if (angvel > -MAXANGVEL)
	    tforce += -TFORCE;
    }

    newf.force = cpvrotate(cpv(0, force), rotv);
    newf.tforce = cpv(0, tforce);

    applyforces(player, thrust->prevf);
    applyforces(player, newf);

    thrust->prevf.force = cpvneg(newf.force);
    thrust->prevf.tforce = cpvneg(newf.tforce);
}
コード例 #6
0
ファイル: kitty.cpp プロジェクト: teritriano/ftf
void fff::kitty::applyImpulse(float impulse){
    cpVect vel = cpBodyGetVel(body);
    if (impulse < 0.f && vel.y > 0.f){
        vel.y = impulse;
    }else if (impulse < 0.f && vel.y < 0.f){
        vel.y += impulse;
    }else if (impulse > 0.f && vel.y < 0.f){
        vel.y = impulse;
    }else if (impulse > 0.f && vel.y > 0.f){
        vel.y += impulse;
    }
    cpBodySetVel(body, vel);
}
コード例 #7
0
ファイル: main.c プロジェクト: Hakall/LetterBouleGame
void affichage(){
    
       
    cpFloat timeStep = 1.0/60.0;
      SDL_Color white={255,255,255};
          for(cpFloat time = 0; time < 25; time += timeStep){
              SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,0,0,0));
              for(int i=0;i<50;i++){
                  if(lesBoules[i].del==FALSE){
                 cpVect pos = cpBodyGetPos(lesBoules[i].body);
                 cpVect vel = cpBodyGetVel(lesBoules[i].body);
    
                 rectangleColor(ecran,10, 0, 630, 420,SDL_MapRGB(ecran->format,255,255,255));
                 circleRGBA(ecran, pos.y, pos.x, lesBoules[i].radius, lesBoules[i].r,lesBoules[i].g,lesBoules[i].b,lesBoules[i].a); 
                 filledCircleRGBA(ecran,pos.y,pos.x,lesBoules[i].radius, lesBoules[i].r,lesBoules[i].g,lesBoules[i].b,lesBoules[i].a);
                 
                 //lettre
                 
                 SDL_Surface *lettre= TTF_RenderText_Solid(police, lesBoules[i].lettre, white);
                 SDL_Rect position;
                 position.y=pos.x;
                 position.x=pos.y;
                 lesBoules[i].x=pos.x;
                 lesBoules[i].y=pos.y;
                 SDL_BlitSurface(lettre, NULL, ecran, &position);
                  }
                 
 
               }

              SDL_Surface *pointsTexte=TTF_RenderText_Solid(police,"Score:" , white);
                 SDL_Rect position_pointsTexte;
                 position_pointsTexte.y=435;
                 position_pointsTexte.x=10;
                 SDL_BlitSurface(pointsTexte, NULL, ecran, &position_pointsTexte);
                 char scoreChar[15]={"0"};
                 snprintf(scoreChar, 15, "%d", score);
                 SDL_Surface *points=TTF_RenderText_Solid(police,scoreChar, white);
                 SDL_Rect position_points;
                 position_points.y=435;
                 position_points.x=100;
                 SDL_BlitSurface(points, NULL, ecran, &position_points);
                 
                 
              cpSpaceStep(espace, timeStep);
              SDL_Flip(ecran);
          }
                      //affichage points
                 
 SDL_Flip(ecran);
}
コード例 #8
0
ファイル: kitty.cpp プロジェクト: teritriano/ftf
void fff::kitty::Update(){
    cpVect pos = cpBodyGetPos(body);
    lastpos = pos;
    sprite.SetPosition(pos.x, pos.y);
    flames[0].SetPosition(pos.x, pos.y);
    flames[1].SetPosition(pos.x, pos.y);
    cpVect vel = cpBodyGetVel(body);
    if (vel.y > KMH_TO_PXS(500.f) && !burstinflames){
        burst.Play();
        burstinflames = true;
    }else if (vel.y <= KMH_TO_PXS(500.f) ){
        burstinflames = false;
    }
    iflames += 1;
    if (iflames > 1){
        iflames = 0;
    }
}
コード例 #9
0
ファイル: physics.c プロジェクト: outgame/CrayonPhysics
int main (int argc, char **argv) {
    cpSpace *space = cpSpaceNew();
    cpSpaceSetGravity(space, cpv(0, GRAVITY));
    cpEnableSegmentToSegmentCollisions();
    
    cpShape *ground = cpSpaceAddShape(space, cpSegmentShapeNew(space->staticBody, cpv(0, 5), cpv(10, -5), 0));
    cpShapeSetFriction(ground, 0.3);
    
    cpBody *drawing = drawing_new(2, 7, 0);
    drawing = drawing_update(space, drawing, 3, 8);
    drawing = drawing_update(space, drawing, 3, 9);
    drawing = drawing_update(space, drawing, 2, 9);
    //cpBody *drawing = drawing_new(0, 0, 0);
    //drawing = drawing_update(space, drawing, 2, 0);
    //drawing = drawing_update(space, drawing, 2, 2);
    //drawing = drawing_update(space, drawing, 0, 2);
    print_positions(drawing);
    
    //drawing_activate(drawing);
    //print_positions(drawing);
    
    cpVect vel, pos;
    int i = 0;
    for(cpFloat time = 0; time < 2; time += TIMESTEP){
        pos = cpBodyGetPos(drawing);
        vel = cpBodyGetVel(drawing);
        
        printf( "Time = %2.2f Position = (%2.2f, %2.2f) Velocity = (%2.2f, %2.2f)\n",
            time, pos.x, pos.y, vel.x, vel.y);
        cpSpaceStep(space, TIMESTEP);
        
        i++;
        if (i == 20) {
            drawing_activate(space, drawing);
            print_positions(drawing);
        }
    }
    print_positions(drawing);
    
    free_body_full(drawing);
    cpShapeFree(ground);
    cpSpaceFree(space);
    return EXIT_SUCCESS;
}
コード例 #10
0
ファイル: body.cpp プロジェクト: dumganhar/sugs_spiderMonkey
static JSBool body_getVelocity(JSContext* cx, uintN argc, jsval* vp)
{
  JSObject* bodyObj = JS_THIS_OBJECT(cx, vp);

  cpBody* body = (cpBody*)JS_GetPrivate(cx, bodyObj);

  cpVect velocity = cpBodyGetVel(body);
  jsval xVelVal = DOUBLE_TO_JSVAL(velocity.x);
  jsval yVelVal = DOUBLE_TO_JSVAL(velocity.y);
  JSObject* velocityObj = JS_NewObject(cx, NULL, NULL, NULL);
  if(!JS_SetProperty(cx, velocityObj, "x", &xVelVal)) {
    JS_ReportError(cx, "Failure to set x property of velocity for Body");
  }
  if(!JS_SetProperty(cx, velocityObj, "y", &yVelVal)) {
    JS_ReportError(cx, "Failure to set y property of velocity for Body");
  }
  jsval rVal = OBJECT_TO_JSVAL(velocityObj);
  JS_SET_RVAL(cx, vp, rVal);
  return JS_TRUE;
}
コード例 #11
0
ファイル: body.c プロジェクト: sixian/lunatic-chipmunk
int lc_body_index(lua_State *vm){
    //userdata, key
    const char *key = lua_tostring(vm, 2);
    cpBody *body = (lc_GetBody(1, vm))->body;
    if (strcmp("pos", key) == 0){
        lc_cpVectToTable(cpBodyGetPos(body), vm);
        return 1;
    }
    else if (strcmp("vel", key) == 0){
        lc_cpVectToTable(cpBodyGetVel(body), vm);
        return 1;
    }
    else if (strcmp("angle", key) == 0 || strcmp("radangle", key) == 0){
        lua_pushnumber(vm, (lua_Number)cpBodyGetAngle(body));
        return 1;
    }
    else if (strcmp("degangle", key) == 0){
        lua_pushnumber(vm, (lua_Number)( cpBodyGetAngle(body)*(cpFloat)180.f/(cpFloat)M_PI) );
        return 1;
    }
    lua_getfield(vm, LUA_REGISTRYINDEX, "chipmunk.body:");
    lua_getfield(vm, -1, key);
    return 1;
}
コード例 #12
0
ファイル: Body.cpp プロジェクト: Marwes/CppChipmunk
cp::Vect Body::getVel(void)
{
		return cpBodyGetVel(body);
}
コード例 #13
0
ファイル: CCPhysicsBody.cpp プロジェクト: chling/artemis
Point PhysicsBody::getVelocity()
{
    return PhysicsHelper::cpv2point(cpBodyGetVel(_info->body));
}
コード例 #14
0
ファイル: cbody.cpp プロジェクト: dogtwelve/eepp
cVect cBody::Vel() const {
	return tovect( cpBodyGetVel( mBody ) );
}
コード例 #15
0
ファイル: hello.c プロジェクト: morganecf/haptech-demo
int main(void){
  // cpVect is a 2D vector and cpv() is a shortcut for initializing them.
  cpVect gravity = cpv(0, -100);
  
  // Create an empty space.
  cpSpace *space = cpSpaceNew();
  cpSpaceSetGravity(space, gravity);
  
  // Add a static line segment shape for the ground.
  // We'll make it slightly tilted so the ball will roll off.
  // We attach it to space->staticBody to tell Chipmunk it shouldn't be movable.
  cpShape *ground = cpSegmentShapeNew(space->staticBody, cpv(-20, 5), cpv(20, -5), 0);
  cpShapeSetFriction(ground, 1);
  cpSpaceAddShape(space, ground);
  
  // Now let's make a ball that falls onto the line and rolls off.
  // First we need to make a cpBody to hold the physical properties of the object.
  // These include the mass, position, velocity, angle, etc. of the object.
  // Then we attach collision shapes to the cpBody to give it a size and shape.
  
  cpFloat radius = 5;
  cpFloat mass = 1;
  
  // The moment of inertia is like mass for rotation
  // Use the cpMomentFor*() functions to help you approximate it.
  cpFloat moment = cpMomentForCircle(mass, 0, radius, cpvzero);
  
  // The cpSpaceAdd*() functions return the thing that you are adding.
  // It's convenient to create and add an object in one line.
  cpBody *ballBody = cpSpaceAddBody(space, cpBodyNew(mass, moment));
  cpBodySetPos(ballBody, cpv(0, 15));
  
  // Now we create the collision shape for the ball.
  // You can create multiple collision shapes that point to the same body.
  // They will all be attached to the body and move around to follow it.
  cpShape *ballShape = cpSpaceAddShape(space, cpCircleShapeNew(ballBody, radius, cpvzero));
  cpShapeSetFriction(ballShape, 0.7);
  
  // Now that it's all set up, we simulate all the objects in the space by
  // stepping forward through time in small increments called steps.
  // It is *highly* recommended to use a fixed size time step.
  cpFloat timeStep = 1.0/60.0;
  for(cpFloat time = 0; time < 2; time += timeStep){
    cpVect pos = cpBodyGetPos(ballBody);
    cpVect vel = cpBodyGetVel(ballBody);
    printf(
      "Time is %5.2f. ballBody is at (%5.2f, %5.2f). It's velocity is (%5.2f, %5.2f)\n",
      time, pos.x, pos.y, vel.x, vel.y
    );
    
    cpSpaceStep(space, timeStep);
  }
  
  // Clean up our objects and exit!
  cpShapeFree(ballShape);
  cpBodyFree(ballBody);
  cpShapeFree(ground);
  cpSpaceFree(space);
  
  return 0;
}
コード例 #16
0
Vec2 PhysicsBody::getVelocity()
{
    return PhysicsHelper::cpv2point(cpBodyGetVel(_info->getBody()));
}
コード例 #17
0
ファイル: world.c プロジェクト: fjolnir/Dynamo
vec2_t worldEnt_velocity(WorldEntity_t *aEntity)
{
    cpVect vel = cpBodyGetVel(aEntity->cpBody);
    return CPV_TO_VEC2(vel);
}
コード例 #18
0
ファイル: testwheel.c プロジェクト: andrenho/newhope
cpVect lateral_velocity(int n)
{
	cpVect normal = cpvforangle(cpBodyGetAngle(tire[n]));
	return cpvmult(normal, cpvdot(normal, cpBodyGetVel(tire[n])));
}
コード例 #19
0
ファイル: physics.c プロジェクト: andi2/cgame
Vec2 physics_get_velocity(Entity ent)
{
    PhysicsInfo *info = entitypool_get(pool, ent);
    error_assert(info);
    return vec2_of_cpv(cpBodyGetVel(info->body));
}
コード例 #20
0
ファイル: kitty.cpp プロジェクト: teritriano/ftf
bool fff::kitty::isFalling(){
    cpVect vel = cpBodyGetVel(body);
    if( vel.y > 0.f){
        return true;}
    return false;
}
コード例 #21
0
ファイル: kitty.cpp プロジェクト: teritriano/ftf
bool fff::kitty::isAscending(){
    cpVect vel = cpBodyGetVel(body);
    if( vel.y < 0.f){
        return true;}
    return false;
}
コード例 #22
0
ファイル: kitty.cpp プロジェクト: teritriano/ftf
float fff::kitty::getVerticalSpeedPxls(){
    cpVect vel = cpBodyGetVel(body);
    return vel.y;
}
コード例 #23
0
ファイル: kitty.cpp プロジェクト: teritriano/ftf
float fff::kitty::getVerticalSpeed(){
    cpVect vel = cpBodyGetVel(body);
    return PXS_TO_KMH(vel.y);
}
コード例 #24
0
ファイル: testwheel.c プロジェクト: andrenho/newhope
cpVect forward_velocity(int n)
{
	cpVect normal = cpvperp(cpvforangle(cpBodyGetAngle(tire[n])));
	return cpvmult(normal, cpvdot(normal, cpBodyGetVel(tire[n])));
}
コード例 #25
0
Vec2 PhysicsBody::getVelocity()
{
    return PhysicsHelper::cpv2point(cpBodyGetVel(_cpBody));
}
コード例 #26
0
ファイル: DynamicObject.cpp プロジェクト: jluqu/fugue
float DynamicObject::getYVel()
{
	cpVect v = cpBodyGetVel(m_pBody);
	return (float)v.y;
}