I'm trying to render particles that bounce of surfaces defined in the physics world using rayTest(). It is more or less working, but I always have the feeling that I don't correctly reposition a particle when I detect that it will hit a surface this frame.
Am I using rayTest() correctly?
Code: Select all
/*
rayOrg is where the ray starts
rayDir is the normalized direction of the ray
t will tell me where on the ray I hit a surface
pos will tell me where I hit a surface, rayOrg + t * rayDir == pos ???
norm will tell me the normal of the surface I hit
*/
bool PhysicsSimulation::rayTest(const Vector3 &rayOrg, const Vector3 &rayDir, float &t, Vector3 &pos, Vector3 &norm) const
{
btCollisionWorld::ClosestRayResultCallback resultCallback(btVector3(rayOrg.x, rayOrg.y, rayOrg.z), btVector3(rayDir.x, rayDir.y, rayDir.z));
m_dynamicsWorld->rayTest(btVector3(rayOrg.x, rayOrg.y, rayOrg.z), btVector3(rayDir.x, rayDir.y, rayDir.z), resultCallback);
pos = Vector3(resultCallback.m_hitPointWorld[0], resultCallback.m_hitPointWorld[1], resultCallback.m_hitPointWorld[2]);
norm = normalized(Vector3(resultCallback.m_hitNormalWorld[0], resultCallback.m_hitNormalWorld[1], resultCallback.m_hitNormalWorld[2]));
t = resultCallback.m_closestHitFraction;
return resultCallback.hasHit();
}