Beispiel #1
0
//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;
	}
}
Beispiel #2
0
__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);

}
Beispiel #3
0
void update_friction(int n)
{
	// kill lateral velocity
	const cpFloat max_lateral_impulse = 300;
	cpVect impulse = cpvmult(cpvneg(lateral_velocity(n)), cpBodyGetMass(tire[n]));
	//printf("%f\n", cpvlength(impulse));
	if(cpvlength(impulse) > max_lateral_impulse)
		impulse = cpvmult(impulse, max_lateral_impulse / cpvlength(impulse));
	cpBodyApplyImpulse(tire[n], impulse, cpvzero);


	// TODO - kill angular velocity?
	cpFloat inertia = cpBodyGetMoment(tire[n]);
	cpFloat av = cpBodyGetAngVel(tire[n]);
	if(av != 0)
		cpBodySetAngVel(tire[n], av / 1.2);
	
	// apply drag
	cpVect forward_normal = forward_velocity(n);
	cpFloat forward_speed = cpvlength(forward_normal);
	if(forward_speed < 1) {
		cpBodySetVel(tire[n], cpvzero);
	} else {
		forward_normal = cpvnormalize(forward_normal);
		cpFloat drag = -1 * forward_speed;
		cpBodyApplyImpulse(tire[n], cpvmult(forward_normal, drag), cpvzero);
	}
}
Beispiel #4
0
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 );

}
Beispiel #5
0
static void
ClipPoly(cpSpace *space, cpShape *shape, cpVect n, cpFloat dist)
{
	cpBody *body = cpShapeGetBody(shape);
	
	int count = cpPolyShapeGetNumVerts(shape);
	int clippedCount = 0;
	
	cpVect *clipped = (cpVect *)alloca((count + 1)*sizeof(cpVect));
	
	for(int i=0, j=count-1; i<count; j=i, i++){
		cpVect a = cpBodyLocal2World(body, cpPolyShapeGetVert(shape, j));
		cpFloat a_dist = cpvdot(a, n) - dist;
		
		if(a_dist < 0.0){
			clipped[clippedCount] = a;
			clippedCount++;
		}
		
		cpVect b = cpBodyLocal2World(body, cpPolyShapeGetVert(shape, i));
		cpFloat b_dist = cpvdot(b, n) - dist;
		
		if(a_dist*b_dist < 0.0f){
			cpFloat t = cpfabs(a_dist)/(cpfabs(a_dist) + cpfabs(b_dist));
			
			clipped[clippedCount] = cpvlerp(a, b, t);
			clippedCount++;
		}
	}
	
	cpVect centroid = cpCentroidForPoly(clippedCount, clipped);
	cpFloat mass = cpAreaForPoly(clippedCount, clipped)*DENSITY;
	cpFloat moment = cpMomentForPoly(mass, clippedCount, clipped, cpvneg(centroid));
	
	cpBody *new_body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
	cpBodySetPos(new_body, centroid);
	cpBodySetVel(new_body, cpBodyGetVelAtWorldPoint(body, centroid));
	cpBodySetAngVel(new_body, cpBodyGetAngVel(body));
	
	cpShape *new_shape = cpSpaceAddShape(space, cpPolyShapeNew(new_body, clippedCount, clipped, cpvneg(centroid)));
	// Copy whatever properties you have set on the original shape that are important
	cpShapeSetFriction(new_shape, cpShapeGetFriction(shape));
}
Beispiel #6
0
// 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);
}
Beispiel #7
0
cpFloat cBody::AngVel() const {
	return cpBodyGetAngVel( mBody );
}
float PhysicsBody::getAngularVelocity()
{
    return PhysicsHelper::cpfloat2float(cpBodyGetAngVel(_info->getBody()));
}
Beispiel #9
0
Scalar physics_get_angular_velocity(Entity ent)
{
    PhysicsInfo *info = entitypool_get(pool, ent);
    error_assert(info);
    return cpBodyGetAngVel(info->body);
}
Beispiel #10
0
cpFloat Body::getAngVel(void)
{
		return cpBodyGetAngVel(body);
}