apparent bug in DistanceLodBoxStrategy

Minor issues with the Ogre API that can be trivial to fix
Post Reply
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California
x 19

apparent bug in DistanceLodBoxStrategy

Post by lunkhound »

from OgreDistanceLodStrategy.cpp:

Code: Select all

    Real DistanceLodBoxStrategy::getSquaredDepth(const MovableObject *movableObject, const Ogre::Camera *camera) const
    {
[color=#FF0000]        return Math::Sqr(movableObject->getBoundingBox().distance(camera->getPosition()));
[/color]    }
This can't be right! The bounding box it's getting is in LOCAL coordinates, and for that matter, the camera position is not in world coordinates either.
That's a nonsensical calculation. Surely what was intended is something more like this:

Code: Select all

    Real DistanceLodBoxStrategy::getSquaredDepth(const MovableObject *movableObject, const Ogre::Camera *camera) const
    {
        return movableObject->getWorldBoundingBox().squaredDistance(camera->_getDerivedPosition());
    }
I noticed this as I was looking into how Ogre computes bounding boxes of things. It seems that the method MovingObject::getBoundingBox() is only ever called by MovingObject (or in a couple of cases, by classes derived from MovingObject)--except in that case above where it's called by mistake. It seems to be more of an internal utility method, and not really intended for public use. Maybe it should be "protected".
Post Reply