[ODE] Object speed
Tim Rightnour
root at garbled.net
Fri Nov 26 23:36:51 MST 2004
On 27-Nov-2004 Alexandre Ribeiro de Sá wrote:
> Speed = ((BodyPos.posX + BodyPos.posY + BodyPos.posZ)/3 - OldPos);
> OldPos = (( BodyPos.posX) + ( BodyPos.posY) + ( BodyPos.posZ)) / 3;
This is one way of doing it, there are others:
obj->cli.prevc = obj->cli.coord;
pos = dBodyGetPosition(obj->body);
obj->cli.coord.x = pos[0];
obj->cli.coord.y = pos[1];
obj->cli.coord.z = pos[2];
obj->cli.velocity = dist_between(obj->cli.prevc, obj->cli.coord);
where dist_between() is:
float dist_between(vertex_t ca, vertex_t cb)
{
float xd, yd, zd;
xd = cb.x - ca.x;
yd = cb.y - ca.y;
zd = cb.z - ca.z;
return(sqrt(xd*xd + yd*yd + zd*zd));
}
vertex_t is just a struct of three floats, x, y and z.
I don't use the code anymore, so I don't have a working example, but I seem to
recall I also got a resonable result by adding up the three dReals returned
from dBodyGetLinearVelocity(). You might try both and if you get the same
results, dBodyGetLinearVelocity() will definately be faster than sqrt().
---
Tim Rightnour <root at garbled.net>
NetBSD: Free multi-architecture OS http://www.netbsd.org/
Genecys: Open Source 3D MMORPG: http://www.genecys.org/
More information about the ODE
mailing list