Impulse Based Methode
Posted: Mon Jan 29, 2007 12:13 am
Hi,
at the moment i'm working on an simple Phyisk engine. I decided to use the Impuls Base Methode for solving constraints.
http://www.impulse-based.de
For testing i have implementet a simple Demo which is just a single pendular mountet on a fix point.
The Problem is that there is an error which slows the pendular over time so that after a long period it stands.
Here is the relevant part of my code may be somebody see an mistake.
This is the code to calculate the correct impuls
Here is the code that is used to apply the impuls to a body
and finaly the code is used for look ahead and also to update position and velocity
in frame_force is stored the gravity.
PS:
sorry for my bad english i am german.
at the moment i'm working on an simple Phyisk engine. I decided to use the Impuls Base Methode for solving constraints.
http://www.impulse-based.de
For testing i have implementet a simple Demo which is just a single pendular mountet on a fix point.
The Problem is that there is an error which slows the pendular over time so that after a long period it stands.
Here is the relevant part of my code may be somebody see an mistake.
This is the code to calculate the correct impuls
Code: Select all
bool MultiBodySystem::check_fix_constraint(STRUCT_JOINT* joint,float time)
{
VECTOR3 p;
VECTOR3 vec;
float dist;
float delta;
VECTOR3 imp;
p = joint->att_body1->look_ahead_world(joint->ref_point1,time);
vec = p-joint->ref_point2; //joint->ref_point2 == fix point pendular is mounted
dist = vec.Length();
delta = joint->float_arr[0]-dist; //joint->float_arr[0] == length of pendular
if(abs(delta) < DIS_DELTA)
return true;
imp =(joint->att_body1->get_mass())*((delta/dist)*vec);
imp = 1.0/time*imp;
joint->att_body1->add_impulse_force(imp);
return false;
}Here is the code that is used to apply the impuls to a body
Code: Select all
void RigidBody::add_impulse_force(VECTOR3 force)
{
this->center_velocity += 1.0/this->body_mass*force;
}
Code: Select all
VECTOR3 RigidBody::integrate(bool look_ahead,float time)
{
this->new_center_position = this->center_position + this->center_velocity*time+0.5*1.0/this->body_mass*time*time*this->frame_force;
this->new_center_velocity = this->center_velocity + 1.0/this->body_mass*time*this->frame_force;
return this->new_center_position;
}
PS:
sorry for my bad english i am german.
