Optimizing collision detection code
Posted: Fri Jan 06, 2012 1:20 pm
Hey,
So I've implemented some collision code into my game but my FPS drops a fair bit and I'm guessing it's the way I've implemented it. I'm currently doing it the same way the terrain tutorial does the terrain itself, for each individual object (e.g. 4 different fences). So at the moment I'm duplicating the same code which I'm guessing is the problem. At the moment I'm doing it like this...
then...
and finally... (I've repeated the next piece of code 4 times for each fence, but to save room and not clutter this post I'm only posting an example of one).
I know people will reply with answers saying "use OOP properly", but that isn't important right now. I just want to implement the code in the best way possible to aid the FPS without doing it OOP.
Thanks in advance guys![Smile :)](./images/smilies/icon_smile.gif)
So I've implemented some collision code into my game but my FPS drops a fair bit and I'm guessing it's the way I've implemented it. I'm currently doing it the same way the terrain tutorial does the terrain itself, for each individual object (e.g. 4 different fences). So at the moment I'm duplicating the same code which I'm guessing is the problem. At the moment I'm doing it like this...
Code: Select all
scene::ITriangleSelector* FenceCollisionNorth = 0;
scene::ITriangleSelector* FenceCollisionWest = 0;
scene::ITriangleSelector* FenceCollisionEast = 0;
scene::ITriangleSelector* FenceCollisionSouth = 0;
Code: Select all
//Collision detection for FENCE's
FenceCollisionNorth = smgr->createOctreeTriangleSelector(metalFenceNodeNorth->getMesh(), metalFenceNodeNorth, 20);
metalFenceNodeNorth->setTriangleSelector(FenceCollisionNorth);
FenceCollisionEast = smgr->createOctreeTriangleSelector(metalFenceNodeEast->getMesh(), metalFenceNodeEast, 20);
metalFenceNodeEast->setTriangleSelector(FenceCollisionEast);
FenceCollisionWest = smgr->createOctreeTriangleSelector(metalFenceNodeWest->getMesh(), metalFenceNodeWest, 20);
metalFenceNodeWest->setTriangleSelector(FenceCollisionWest);
FenceCollisionSouth = smgr->createOctreeTriangleSelector(metalFenceNodeSouth->getMesh(), metalFenceNodeSouth, 20);
metalFenceNodeSouth->setTriangleSelector(FenceCollisionSouth);
Code: Select all
//Create collision on camera for Fence's...
scene::ISceneNodeAnimator* coll1 = smgr->createCollisionResponseAnimator(FenceCollisionNorth, fps_camera, core::vector3df(80,50,40),
core::vector3df(0,0,0),
core::vector3df(0,0,0));
FenceCollisionNorth->drop();
fps_camera->addAnimator(coll1);
coll1->drop();
Thanks in advance guys
![Smile :)](./images/smilies/icon_smile.gif)