Why does Ogre only do bounding sphere checks?

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
User avatar
JohnJ
OGRE Expert User
OGRE Expert User
Posts: 975
Joined: Thu Aug 04, 2005 4:14 am
Location: Santa Clara, California
x 4

Why does Ogre only do bounding sphere checks?

Post by JohnJ »

I was looking at the Ogre source for bounding box checks, and I was lead to what seems to be the central function where Ogre checks a bounding box against the view frustum: OgreFrustum.cpp - Frustum::isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy) const.

I noticed that it's not actually checking the bounding box against the frustum. It's calculating a sphere that encloses the bounding box (center, and halfSize) and doing bounding sphere culling instead.

Here's the code (lines 226-262):

Code: Select all

    bool Frustum::isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy) const
    {
        // Null boxes always invisible
        if (bound.isNull()) return false;

        // Infinite boxes always visible
        if (bound.isInfinite()) return true;

        // Make any pending updates to the calculated frustum planes
        updateFrustumPlanes();

        // Get centre of the box
        Vector3 centre = bound.getCenter();
        // Get the half-size of the box
        Vector3 halfSize = bound.getHalfSize();

        // For each plane, see if all points are on the negative side
        // If so, object is not visible
        for (int plane = 0; plane < 6; ++plane)
        {
            // Skip far plane if infinite view frustum
            if (plane == FRUSTUM_PLANE_FAR && mFarDist == 0)
                continue;

            Plane::Side side = mFrustumPlanes[plane].getSide(centre, halfSize);
            if (side == Plane::NEGATIVE_SIDE)
            {
                // ALL corners on negative side therefore out of view
                if (culledBy)
                    *culledBy = (FrustumPlane)plane;
                return false;
            }

        }

        return true;
    }
This is a bit misleading because for my custom Renderable I was using camera->isVisible(...) to do a camera-AABB visibility check, I expect it to actually do an AABB cull rather than a bounding sphere cull.

Does anyone know why this is? This is rather inefficient for certain types of objects (for example, long skinny ones like telephone poles).
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Why does Ogre only do bounding sphere checks?

Post by Kojack »

It's calculating a sphere that encloses the bounding box (center, and halfSize) and doing bounding sphere culling instead.
No it's not. It's an aabb check.
Take a look at the code for getSide.
It does use the centre and halfSize of the box, but it doesn't compare the distance of the centre to the length of halfSize (that would be a sphere check), it actually compares the distance of the centre to the absolute dot product of halfSize with the plane normal (that makes it an aabb check).
User avatar
JohnJ
OGRE Expert User
OGRE Expert User
Posts: 975
Joined: Thu Aug 04, 2005 4:14 am
Location: Santa Clara, California
x 4

Re: Why does Ogre only do bounding sphere checks?

Post by JohnJ »

Ah, that makes sense. I missed the fact that halfSize is a Vector3 and not just a radius. You can delete this "spam" thread in this case, sorry about that.

This all began as I was investigating how a bounding box check is capable of returning a single FrustumPlane *culledBy, since it's not unusual for a volume to be behind multiple frustum planes simultaneously. This made this culledBy return value not particularly useful to me, but that doesn't matter at this point since I could fairly easily implement my own culling behavior.

Thanks for clarifying this!
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Why does Ogre only do bounding sphere checks?

Post by Kojack »

No prob, I had to look at the code carefully because it did look like it could be a sphere check to me too. :)
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Why does Ogre only do bounding sphere checks?

Post by drwbns »

I'd keep the thread in case others think it works as thought.
User avatar
altren
Gnome
Posts: 329
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 24
Contact:

Re: Why does Ogre only do bounding sphere checks?

Post by altren »

Better add comments about that in code.
Image
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Why does Ogre only do bounding sphere checks?

Post by bstone »

Better read existing comments before anything else:

Code: Select all

        // For each plane, see if all points are on the negative side
        // If so, object is not visible
The "all points" part is quite explanatory in case of the sphere vs bbox contention. The related Ogre::Plane method names are not optimal though and more descriptive naming could have resolved that issue.
Post Reply