userPreFilterCallback problem

majc

14-03-2008 00:28:46

I used userPreFilterCallback function to ignore the player body when i fire my weapon but for some reason this it isnt working, here's the code:

OgreNewt::BasicRaycast::BasicRaycastInfo cCollisions::getBodyInfo()
{

float x = 0.5, y = 0.5, rayDistance = 3000.0; // center of screen
Ogre::Ray ray = mCamera->getCameraToViewportRay(x, y);
Ogre::Vector3 direction = ray.getDirection();
Ogre::Vector3 origin = ray.getOrigin();
Ogre::Vector3 start = origin;
Ogre::Vector3 end = origin + direction * rayDistance;
OgreNewt::BasicRaycast::BasicRaycastInfo info;
// normalized screen coords in [0,1]
OgreNewt::BasicRaycast* verticalRay = new OgreNewt::BasicRaycast(m_World,start,end);
info = verticalRay->getFirstHit();
if (info.mBody)
{
int myValue2 = info.mBody->getType();
Debugger* mDebugger = new Debugger();
String s = StringConverter::toString(myValue2);
mDebugger->debug(s,"BodyType:", "BodyType.txt");
if(info.mBody->getType() == TYPEPLAYER)
verticalRay->userPreFilterCallback(info.mBody);
}
return info;
}


I can still hit the player physical body when i fire my weapon.
What im doing wrong?
Thanks in advance!

walaber

17-03-2008 22:06:13

OgreNewt::BasicRaycast* verticalRay = new OgreNewt::BasicRaycast(m_World,start,end);
info = verticalRay->getFirstHit();
if (info.mBody)
{
int myValue2 = info.mBody->getType();
Debugger* mDebugger = new Debugger();
String s = StringConverter::toString(myValue2);
mDebugger->debug(s,"BodyType:", "BodyType.txt");
if(info.mBody->getType() == TYPEPLAYER)
verticalRay->userPreFilterCallback(info.mBody);
}
return info;


you don't call the filter callback like that... you need to make your own class that inherits from Raycast, and override the prefiltercallback to check if the body that is passed is the player, and ignore in that case.

if that doesn't make sense, let me know, I will provide more detail.