Exemplo n.º 1
0
    //-----------------------------------------------------------------------
    PagingLandScapeOctree *PagingLandScapeOctree::_getChildWhereBoxFits(const AxisAlignedBox &box, 
                                                                        PagingLandScapeOctreeSceneManager *scn)
    { 
        /** It's assumed the the given box has already been proven to fit into
        * a child.  Since it's a loose PagingLandScapeOctree, only the centers need to be
        * compared to find the appropriate node.
        */
        const Vector3 &octantMax = mBox.getMaximum();
        const Vector3 &octantMin = mBox.getMinimum();
        const Vector3 octCenter = octantMin + mHalfSize;   

        const Vector3 ncenter = box.getMaximum().midPoint(box.getMinimum());

//ember change: We'll remove this assertion since it seems to trigger sometimes when stuff are placed really close to the boundaries, probably caused be precision issues
//         assert (octantMax.x >= ncenter.x && octantMax.y >= ncenter.y && octantMax.z >= ncenter.z &&
//                 octantMin.x <= ncenter.x && octantMin.y <= ncenter.y && octantMin.z <= ncenter.z);

        unsigned int x;
        if (ncenter.x > octCenter.x)
            x = 1;
        else
            x = 0;

        unsigned int y;
        if (ncenter.y > octCenter.y)
            y = 1;
        else
            y = 0;

        unsigned int z;
        if (ncenter.z > octCenter.z)
            z = 1;
        else
            z = 0;

        if (mChildren[ x ][ y ][ z ] == 0)
        {
            Vector3 min, max;

            if (x == 0)
            {
                min.x = octantMin.x;
                max.x = octCenter.x;
            }
            else
            {
                min.x = octCenter.x;
                max.x = octantMax.x;
            }

            if (y == 0)
            {
                min.y = octantMin.y;
                max.y = octCenter.y;
            }
            else
            {
                min.y = octCenter.y;
                max.y = octantMax.y;
            }

            if (z == 0)
            {
                min.z = octantMin.z;
                max.z = octCenter.z;
            }
            else
            {
                min.z = octCenter.z;
                max.z = octantMax.z;
            }

#ifdef _DEBUG
            std::cout << "new Child\n";
#endif

            PagingLandScapeOctree *newChild = scn->getNewOctree();
            newChild->setParent (this);
            newChild->setSceneManager(scn);
            newChild->setBoundingBox(min, max);

            assert (max.x >= ncenter.x && max.y >= ncenter.y && max.z >= ncenter.z &&
                    min.x <= ncenter.x && min.y <= ncenter.y && min.z <= ncenter.z);
          

            scn->registeredNodeInCamera (newChild);
            #ifdef _VISIBILITYDEBUG   
                newChild ->setDebugCorners(scn);
            #endif //_VISIBILITYDEBUG    
            mChildren[x][y][z] = newChild;
        }
        return mChildren[x][y][z];
            
    }
Exemplo n.º 2
0
    //-----------------------------------------------------------------------
    PagingLandScapeOctree *PagingLandScapeOctree::_getCullChildWhereBoxFits(const AxisAlignedBox &box, 
                                                                            PagingLandScapeOctreeSceneManager *scn)
    { 
        /** It's assumed the the given box has already been proven to fit into
        * a child.  Since it's a loose PagingLandScapeOctree, only the centers need to be
        * compared to find the appropriate node.
        */
        const Vector3 octCenter = mCullBox.getMinimum() + mCullHalfSize;   
        const Vector3 ncenter = box.getMaximum().midPoint(box.getMinimum());
        
        unsigned int x;
        if (ncenter.x > octCenter.x)
            x = 1;
        else
            x = 0;

        unsigned int y;
        if (ncenter.y > octCenter.y)
            y = 1;
        else
            y = 0;

        unsigned int z;
        if (ncenter.z > octCenter.z)
            z = 1;
        else
            z = 0;

        if (mChildren[ x ][ y ][ z ] == 0)
        {
            const Vector3 &octantMax = mBox.getMaximum();
            const Vector3 &octantMin = mBox.getMinimum();

            Vector3 min, max;

            if (x == 0)
            {
                min.x = octantMin.x;
                max.x = octCenter.x;
            }
            else
            {
                min.x = octCenter.x;
                max.x = octantMax.x;
            }

            if (y == 0)
            {
                min.y = octantMin.y;
                max.y = octCenter.y;
            }
            else
            {
                min.y = octCenter.y;
                max.y = octantMax.y;
            }

            if (z == 0)
            {
                min.z = octantMin.z;
                max.z = octCenter.z;
            }
            else
            {
                min.z = octCenter.z;
                max.z = octantMax.z;
            }

            PagingLandScapeOctree *newChild = scn->getNewOctree();
            newChild->setParent (this);
            newChild->setSceneManager(scn);
            newChild ->setBoundingBox(min, max);
            scn->registeredNodeInCamera (newChild);
            #ifdef _VISIBILITYDEBUG   
                newChild ->setDebugCorners(scn);
            #endif //_VISIBILITYDEBUG    
            mChildren[x][y][z] = newChild;
        }
        return mChildren[x][y][z];
            
    }