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); }
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; }
void PhysicsBody::applyForce(const Vect& force, const Vec2& offset) { if (_dynamic && _mass != PHYSICS_INFINITY) { cpBodyApplyForce(_info->getBody(), PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset)); } }
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 ); }
void cBody::ApplyForce( const cVect f, const cVect r ) { cpBodyApplyForce( mBody, tocpv( f ), tocpv( r ) ); }
// 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)); }
void bmx_cpbody_applyforce(cpBody * body, cpVect * force, cpVect * offset) { cpBodyApplyForce(body, *force, *offset); }
void PhysicsBody::applyForce(Point force, Point offset) { cpBodyApplyForce(_info->body, PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset)); }
void wrBodyApplyForce(cpBody *b, cpVect *f, cpVect *p) { cpBodyApplyForce(b, *f, *p); }
static VALUE rb_cpBodyApplyForce(VALUE self, VALUE f, VALUE r) { cpBodyApplyForce(BODY(self), *VGET(f), *VGET(r)); return self; }
void PhysicsBody::applyForce(const Vect& force, const Point& offset) { cpBodyApplyForce(_info->getBody(), PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset)); }
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)); }
void worldEnt_applyForce(WorldEntity_t *aEntity, vec2_t aForce, vec2_t aOffset) { cpBodyApplyForce(aEntity->cpBody, VEC2_TO_CPV(aForce), VEC2_TO_CPV(aOffset)); }
void Body::applyForce(const cp::Vect& f,const cp::Vect& r) { cpBodyApplyForce(body,f,r); }