예제 #1
0
void
cpDampedSpring(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt)
{
	// Calculate the world space anchor coordinates.
	cpVect r1 = cpvrotate(anchr1, a->rot);
	cpVect r2 = cpvrotate(anchr2, b->rot);
	
	cpVect delta = cpvsub(cpvadd(b->p, r2), cpvadd(a->p, r1));
	cpFloat dist = cpvlength(delta);
	cpVect n = dist ? cpvmult(delta, 1.0f/dist) : cpvzero;
	
	cpFloat f_spring = (dist - rlen)*k;

	// Calculate the world relative velocities of the anchor points.
	cpVect v1 = cpvadd(a->v, cpvmult(cpvperp(r1), a->w));
	cpVect v2 = cpvadd(b->v, cpvmult(cpvperp(r2), b->w));
	
	// Calculate the damping force.
	// This really should be in the impulse solver and can produce problems when using large damping values.
	cpFloat vrn = cpvdot(cpvsub(v2, v1), n);
	cpFloat f_damp = vrn*cpfmin(dmp, 1.0f/(dt*(a->m_inv + b->m_inv)));
	
	// Apply!
	cpVect f = cpvmult(n, f_spring + f_damp);
	cpBodyApplyForce(a, f, r1);
	cpBodyApplyForce(b, cpvneg(f), r2);
}
예제 #2
0
static int cpBody_applyForce (lua_State *L){
  cpBody *b = check_cpBody(L, 1);
  cpVect f = check_cpVect(L, 2);
  cpVect r = check_cpVect(L, 4);
  cpBodyApplyForce(b, f, r);
  return 0;
}
예제 #3
0
void PhysicsBody::applyForce(const Vect& force, const Vec2& offset)
{
    if (_dynamic && _mass != PHYSICS_INFINITY)
    {
        cpBodyApplyForce(_info->getBody(), PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset));
    }
}
예제 #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
파일: cbody.cpp 프로젝트: dogtwelve/eepp
void cBody::ApplyForce( const cVect f, const cVect r ) {
	cpBodyApplyForce( mBody, tocpv( f ), tocpv( r ) );
}
예제 #6
0
파일: move.c 프로젝트: sudoman/SpaceDolphin
// apply a lasting external force to the center of gravity.
// also apply lasting forces perpendicluar to vectors from the c.o.g.
// (in other words, push and rotate the object)
// these need to be subtracted later to stop their effect
void applyforces(struct objnode *player, struct forces f)
{
    cpBodyApplyForce(player->b, f.force, cpvzero);
    cpBodyApplyForce(player->b, f.tforce, cpv(RLEN, 0));
    cpBodyApplyForce(player->b, cpvneg(f.tforce), cpv(-RLEN, 0));
}
예제 #7
0
void bmx_cpbody_applyforce(cpBody * body, cpVect * force, cpVect * offset) {
	cpBodyApplyForce(body, *force, *offset);
}
예제 #8
0
void PhysicsBody::applyForce(Point force, Point offset)
{
    cpBodyApplyForce(_info->body, PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset));
}
예제 #9
0
파일: wrapper.c 프로젝트: Et999/Hipmunk
void wrBodyApplyForce(cpBody *b, cpVect *f, cpVect *p) {
    cpBodyApplyForce(b, *f, *p);
}
예제 #10
0
파일: rb_cpBody.c 프로젝트: Anaxim/chipmunk
static VALUE
rb_cpBodyApplyForce(VALUE self, VALUE f, VALUE r) {
  cpBodyApplyForce(BODY(self), *VGET(f), *VGET(r));
  return self;
}
예제 #11
0
void PhysicsBody::applyForce(const Vect& force, const Point& offset)
{
    cpBodyApplyForce(_info->getBody(), PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset));
}
예제 #12
0
파일: physics.c 프로젝트: andi2/cgame
void physics_apply_force_at(Entity ent, Vec2 force, Vec2 at)
{
    PhysicsInfo *info = entitypool_get(pool, ent);
    error_assert(info);
    cpBodyApplyForce(info->body, cpv_of_vec2(force), cpv_of_vec2(at));
}
예제 #13
0
파일: world.c 프로젝트: fjolnir/Dynamo
void worldEnt_applyForce(WorldEntity_t *aEntity, vec2_t aForce, vec2_t aOffset)
{
    cpBodyApplyForce(aEntity->cpBody, VEC2_TO_CPV(aForce), VEC2_TO_CPV(aOffset));
}
예제 #14
0
파일: Body.cpp 프로젝트: Marwes/CppChipmunk
void Body::applyForce(const cp::Vect& f,const cp::Vect& r)
{
		cpBodyApplyForce(body,f,r);
}