[ODE] Optimization suggestion for dxHashSpace::collide

Michal Bacik michal at lonelycatgames.com
Fri Feb 14 08:07:02 2003


Small suggestion for improving the collision testing performance:

In dxHashSpace::collide, there's this statement:
for(i=0; i < 6; i++)
   aabb->dbounds[i] =
      (int)floor(geom->aabb[i]/cellsize);

1) 6 * division could be changed to multiplication with 1/cellsize

2) (not so obvious) - conversion from float to int is damn slow on some
compilers (MSVC being one), because it calls _ftol, which changes FPU
rounding mode and is real pain.

Suggested approach: making a float-to-int conversion function like this:

#ifdef _MSC_VER
inline int FloatToInt(float f){
   __asm{
      fld f
      fistp f
   }
   return *(int*)&f;
}

#else

inline int FloatToInt(float f){
   return (int)f;
}

#endif

- michal