void odeSpringApplyForce( dBodyID b0, dBodyID b1, FVec3 off0, FVec3 off1, FVec3 forceVec, float damping ) { dReal zero[3] = { 0.0, 0.0, 0.0 }; const dReal *vel0 = (const dReal *)&zero; const dReal *vel1 = (const dReal *)&zero; if( b0 ) { vel0 = dBodyGetLinearVel( b0 ); } if( b1 ) { vel1 = dBodyGetLinearVel( b1 ); } FVec3 relVel( (float)vel0[0]-(float)vel1[0], (float)vel0[1]-(float)vel1[1], (float)vel0[2]-(float)vel1[2] ); float a = relVel.dot( forceVec ); float b = forceVec.dot( forceVec ); FVec3 dampingVec = forceVec; if( fabsf(b) > 1e-5f ) { dampingVec.mul( -damping * a / b ); } forceVec.add( dampingVec ); if( b0 ) { dBodyAddForceAtRelPos( b0, forceVec.x, forceVec.y, forceVec.z, off0.x, off0.y, off0.z ); } if( b1 ) { dBodyAddForceAtRelPos( b1, -forceVec.x, -forceVec.y, -forceVec.z, off1.x, off1.y, off1.z ); } }
void odSpring::run(){ double deltaLength; odPoint d, F, loc1, loc2; if (fb1){ loc1=body1->globalPosition(end1); }else{ loc1=end1; } if (fb2){ loc2=body2->globalPosition(end2); }else{ loc2=end2; } d=loc2-loc1; if (d.mag()<TOLERANCE) return; deltaLength=d.mag()-initialLength; // printf("deltaLength=%lf\n", deltaLength); F=d/d.mag()*(deltaLength*(k/initialLength)); tension=deltaLength*k; if (tensionOnly && tension<0) F=odPoint(); force1=F; force2=-F; // fprintf(forcesFile,"%lf\t",*simTime); fprintf(forcesFile,"%lf\t",tension); fprintf(forcesFile,"%lf\t%lf\t%lf\t%lf\t",F.x, F.y, F.z, F.mag()); fprintf(forcesFile,"%lf\t%lf\t%lf\t%lf\n",-F.x, -F.y, -F.z, F.mag()); // fprintf(positionFile,"%lf\t",*simTime); fprintf(positionFile,"%lf\t%lf\t%lf\t", loc1.x, loc1.y, loc1.z); fprintf(positionFile,"%lf\t%lf\t%lf\n", loc2.x, loc2.y, loc2.z); if (fb1){ dBodyAddForceAtRelPos(body1->odeBody, F.x, F.y, F.z, end1.x, end1.y, end1.z); // printf("Applying force %lf\t%lf\t%lf to body 1\n",F.x, F.y, F.z); } if (fb2){ dBodyAddForceAtRelPos(body2->odeBody, -F.x, -F.y, -F.z, end2.x, end2.y, end2.z); // printf("Applying force %lf\t%lf\t%lf to body 2\n",-F.x, -F.y, -F.z); } }
void RigidBody::addForceAtRelativePosition(const ngl::Vec3 &_f,const ngl::Vec3 &_p) { dBodyAddForceAtRelPos(m_id,_f.m_x,_f.m_y,_f.m_z,_p.m_x,_p.m_y,_p.m_z); }
void SParts::addForceAtRelPos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) { dBodyAddForceAtRelPos(m_odeobj->body(), fx, fy, fz, px, py, pz); }
void PhysicsBody::addForceAtRelPos(const Vec3f &v, const Vec3f &p) { dBodyAddForceAtRelPos(_BodyID, v.x(), v.y(), v.z(), p.x(), p.y(), p.z()); }
void LocalForceHook::Step(Real dt) { dBodyAddForceAtRelPos(body,f.x,f.y,f.z,localpt.x,localpt.y,localpt.z); }