Epimetheus
25-02-2006 20:08:16
Vector3 pull_pos = (*itPull).second.position;
Real pull_mass = (*itPull).second.mass;
Vector3 dir;
Real dist;
Vector3 pos;
Quaternion q;
body->getPositionOrientation(pos, q);
dir = pull_pos - pos;
dist = dir.length();
//body->addForce(dir*(solidBody::sGravity_const*((pull_mass*mass)/(dist*dist))));
body->addForce(dir*((pull_mass*mass)/(dist*dist)));
I use this code as one of my force callbacks and i have a map with some vectors and masses that are supposed to pull the object towards it using the almighty gravity equation:

the thing i noticed is that when it seems like the distance is 0 or very close the object just shoots of. Can anyone give me a idea of the reason, i mean when the distance is zero shouldn't it give division by zero error or something?
Kerion
25-02-2006 20:55:19
Vector3 pull_pos = (*itPull).second.position;
Real pull_mass = (*itPull).second.mass;
Vector3 dir;
Real dist;
Vector3 pos;
Quaternion q;
body->getPositionOrientation(pos, q);
dir = pull_pos - pos;
dist = dir.length();
//body->addForce(dir*(solidBody::sGravity_const*((pull_mass*mass)/(dist*dist))));
body->addForce(dir*((pull_mass*mass)/(dist*dist)));
I use this code as one of my force callbacks and i have a map with some vectors and masses that are supposed to pull the object towards it using the almighty gravity equation: 
the thing i noticed is that when it seems like the distance is 0 or very close the object just shoots of. Can anyone give me a idea of the reason, i mean when the distance is zero shouldn't it give division by zero error or something?
You are more than likely running in to a floating pointer error. Remember, floats on computers have a certain degree of error. Try clamping the values to epsilon as a 0 check before you do the computation.
walaber
25-02-2006 21:46:42
well.. obviously the smaller r gets, the larger the force gets... so you are probably getting GIANT forces for 1 or 2 simulation loops. if you have collison between the 2 objects that will help, because r will never get so small.