RayCast preformance hit

capture

01-08-2007 01:17:05

I have created 10 raycast to attach to an object at different locations, and i took a massive performance hit about a loss of 50 FPS or more. Is this normal or am i doing something completely wrong?

walaber

01-08-2007 05:02:42

that seems excessive. are the rays very long with many bodies in the world?

capture

09-08-2007 15:06:23

The rays are each 10 units in legth and there is not a very large amout of objects in the scene. I think my problem could be in the way i am updating the rays, here is my code

void eCar::AIRayCast::CreateRay()
{
//Put together some strings that will create a unique name for the Objects
Ogre::String ManualObjectName;
ManualObjectName = ("rayline" + Ogre::StringConverter::toString(RayID));
Ogre::String RayNodeName;
RayNodeName = ("ray_node" + Ogre::StringConverter::toString(RayID));
Ogre::String RayMaterialName;
RayMaterialName = ("manualMaterial" + Ogre::StringConverter::toString(RayID));
OgreNewt::BasicRaycast ray(mWorld,Ogre::Vector3(0,0,0),Ogre::Vector3(0,0,0));

RayObject = mSceneMgr->createManualObject(ManualObjectName);
RayNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(RayNodeName);

MaterialPtr myRayMaterial = MaterialManager::getSingleton().create(RayMaterialName,"debugger");
myRayMaterial->setReceiveShadows(false);
myRayMaterial->getTechnique(0)->setLightingEnabled(true);
myRayMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0);
myRayMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1);
myRayMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1);

RayObject->begin(RayMaterialName, Ogre::RenderOperation::OT_LINE_LIST);
RayObject->position(0,0,0);
RayObject->position(4, 1, 0);

RayObject->end();

RayNode->attachObject(RayObject);
RayNode->setPosition(0,0,0);
Ogre::LogManager::getSingleton().logMessage("the ray position is");
}
void eCar::AIRayCast::UpdateRay()
{
Ogre::Vector3 RayStartPoint;
Ogre::Vector3 RayEndPoint;

Vector3 offset1(-2.5,0,mDifferenceOffset);
Vector3 offset2(-10,0,mDifferenceOffset);


RayStartPoint = (VehicleNode->getPosition() + VehicleNode->getOrientation() * offset1);
RayEndPoint = (VehicleNode->getPosition() + VehicleNode->getOrientation() * offset2);

//Update the drawing of the debug line
if (mDebug == true)
{
RayObject->beginUpdate(0);
RayObject->position(RayStartPoint);
RayObject->position(RayEndPoint);
RayObject->end();
}

OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast(mWorld,RayStartPoint,RayEndPoint);
Ogre::Real Count = ray->getHitCount();

OgreNewt::BasicRaycast::BasicRaycastInfo RayInfo = ray->getFirstHit();
Ogre::Real HitDistance = RayInfo.mDistance;

if (mDebug == true)
{
Ogre::LogManager::getSingleton().logMessage("the ray position is" +Ogre::StringConverter::toString(HitDistance));
}
if (HitDistance < 0)
{
mThrottle = 2.0f;
mSteering = 0.0f;
mBrakes = false;
}
}

Any ideas what is causing the performance hit?

walaber

09-08-2007 18:59:58

are you running in debug mode?

writing the the ogre::log many times per frame causes a serious performance hit.

otherwise... I don't see much there... perhaps updating that many ManualObjects causes a performance hit... if you turn off the manual objects do you still get the same dip in performance?

capture

09-08-2007 19:34:44

Yep, when i turn off the manual objects and the logger i do much better. thanks.