[ODE] Presentation and question

Ricard Pillosu ricard at netlands-project.net
Sun Jul 6 06:25:02 2003


Hi all,

I'm not usign Direct3D, instead using OpenGL :( After some investigations I
found the code that makes the simulation inestable:

To simulate friction, every step I apply a force to objects that are moving
to stop them. If I disable this the simulation is OK. The code for objects
that are not moving seems to do nothing, but it does .... I don't know why
but it does ... check it (it's pretty simple, I know):

void physics_model::apply_friction(const vector &force_friction, const
vector &torque_friction) {
	const float *f;
	vector friction_value = vector(0.0f, 0.0f, 0.0f);

	// adjust linear velocity
	f = (dReal *) dBodyGetLinearVel(body_id);

	friction_value = vector(
		-(f[0] * force_friction.x),
		-(f[1] * force_friction.y),
		-(f[2] * force_friction.z));

	if(friction_value != 0.0f) {
		add_impulse_force(friction_value, false);
	}

	// adjust angular velocity
	friction_value.zero();
	f = (dReal *) dBodyGetAngularVel(body_id);
	friction_value = vector(
		-(f[0] * torque_friction.x),
		-(f[1] * torque_friction.y),
		-(f[2] * torque_friction.z));
	if(friction_value != 0.0f) {
		add_impulse_torque(friction_value, false);
	}
}

The other functions are only support functions:

void physics_model::add_impulse_force(vector &v, bool object) {
	dVector3 force;

	dWorldImpulseToForce(
		mengine->mphysics->world_id,
		(dReal) mengine->frame_elapsed,
		v.x, v.y, v.z,
		force);
	add_force(vector(force[0], force[1], force[2]), object);
}

void physics_model::add_force(vector &v, bool object) {
	if(object == true) {
		dBodyAddRelForce(body_id, v.x, v.y, v.z);
	} else {
		dBodyAddForce(body_id, v.x, v.y, v.z);
	}
}

My opinion is that the problem can be from the "dWorldImpulseToForce" ... in
the second argument, where I specify "(dReal) mengine->frame_elapsed" ...
maybe mi code are not doing steps with this "mengine->frame_elapsed" ...
what is the behavior expected if this value does not correspont exactly with
the next simulation step size ?

Thanks for the answers,
riacrd

> -----Mensaje original-----
> De: DjArcas [mailto:djarcas@hotmail.com]
> Enviado el: sábado, 05 de julio de 2003 20:05
> Para: Shaul Kedem; Ricard Pillosu; ode@q12.org
> Asunto: Re: [ODE] Presentation and question - READ THIS
>
>
> That's IT! you STAR! I owe you a beer if you're ever in the UK... and I'm
> sure this has to become part of the FAQ :)
> >