The odd thing is; if I cast a ray straight down, I get what seems to be a valid fraction and a very good intersection point! Even taking into account for rounding errors when calculating the point, I sometimes get heights as large as 0.19 units down to 0.09 units.
Does anybody have an idea as to why this might be? I've verfied that the ray is actually hitting the box. My code for determining the point is as follows;
Code: Select all
bool
SPhysicsManager::TestRay(
TTestRayResult& lResult,
const Ogre::Vector3& lRayStart,
const Ogre::Vector3& lRayEnd,
UINT32 lCollisionFlags /*= 0xffffffff*/)
{
InternalRayResultCallback lInternalCallback;
lInternalCallback.mRayTestFlags = lCollisionFlags;
mpDynamicsWorld->rayTest(btVector3(lRayStart.x, lRayStart.y, lRayStart.z), btVector3(lRayEnd.x, lRayEnd.y, lRayEnd.z), lInternalCallback);
if (lInternalCallback.mHitSomething)
{
lResult = lInternalCallback.mResult;
lResult.mPoint = lRayStart + ((lRayEnd - lRayStart) * (lResult.mFraction));
return true;
}
return false;
}
And here is my ray call back method, just incase anybody can spot something wrong with it.
Code: Select all
btScalar SPhysicsManager::InternalRayResultCallback::addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
{
// Store the fraction/interval of the collision on the ray, as well as the physics object pointer
CPhysicsObject* lpObject = (CPhysicsObject*) rayResult.m_collisionObject->getUserPointer();
// If we have a non-null object, check to see if the ray is allowed to hit it.
if (NULL != lpObject)
{
if (0 == (lpObject->GetCollisionGroup() & mRayTestFlags))
return 1.0f;
}
// We've gotten to here, so the ray is hitting a valid object. Flag that a valid hit has been found
// and set the fraction in the callback class.
mResult.mpObject = lpObject;
mResult.mFraction = rayResult.m_hitFraction;
mHitSomething = true;
// Do we have to store the closest hit fraction? It always seems to be 1, which is a bit of a pickle.
m_closestHitFraction = rayResult.m_hitFraction;
// Worldsace/local normal sruff
if (normalInWorldSpace)
{
mResult.mNormal = Ogre::Vector3(rayResult.m_hitNormalLocal.getX(), rayResult.m_hitNormalLocal.getY(), rayResult.m_hitNormalLocal.getZ());
}
else
{
///need to transform normal into worldspace
btVector3 lhitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;
mResult.mNormal = Ogre::Vector3(lhitNormalWorld.getX(), lhitNormalWorld.getY(),lhitNormalWorld.getZ());
}
return 1.0f;
}