Serious bug in btOptimizedBvh.cpp
Posted: Fri Aug 08, 2008 3:58 am
This is added to the google code issue tracker as well.
These lines:
807 rayDirection[0] = btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = btScalar(1.0) / rayDirection[2];
Were changed to this:
807 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[2];
This code is invalied for any ray direction that is along an axis. (for example (0, -1, 0), it ends up changing the ray direction badly.
This causes many raytest or convexsweeptest to fail (miss or report an incorrect hit).
In my code I changed the lines to this:
807 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[2];
And this resolved the problem for me. Perhaps there is another way to accomplish what is desired that would be more correct than my solution?
Anyway, can this change be made in the meantime?
These lines:
807 rayDirection[0] = btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = btScalar(1.0) / rayDirection[2];
Were changed to this:
807 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[2];
This code is invalied for any ray direction that is along an axis. (for example (0, -1, 0), it ends up changing the ray direction badly.
This causes many raytest or convexsweeptest to fail (miss or report an incorrect hit).
In my code I changed the lines to this:
807 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[2];
And this resolved the problem for me. Perhaps there is another way to accomplish what is desired that would be more correct than my solution?
Anyway, can this change be made in the meantime?