Bounding Box Calculation

This topic contains 2 replies, has 3 voices, and was last updated by  AndreyOGL_D3D 5 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30866

    Hello,

    I’m using POD Models in my iOS Open GL ES 2.0 engine thanks to your PVRTools parser. I want to know the xMin, xMax, yMin, yMax, zMin, zMax of my models to build some kind of bounding box. But I can’t get this to work and I don’t know why. Here is my code :

    -(void) findCenter

    {

        float xMin = 0.0f;

        float yMin = 0.0f;

        float zMin = 0.0f;

        float xMax = 0.0f;

        float yMax = 0.0f;

        float zMax = 0.0f;

        for (unsigned int i = 0; i < _scene->nNumMesh; ++i)

        {

            SPODMesh* pMesh = &_scene->pMesh;

            for(unsigned int j = 0; j < (pMesh->nNumVertex – pMesh->sVertex.nStride); j+=pMesh->sVertex.nStride)

            {

                if(pMesh->sVertex.pData[j] < xMin) xMin = pMesh->sVertex.pData[j];

                else if(pMesh->sVertex.pData[j] > xMax) xMax = pMesh->sVertex.pData[j];

                

                if(pMesh->sVertex.pData[j+1] < yMin) yMin = pMesh->sVertex.pData[j+1];

                else if(pMesh->sVertex.pData[j+1] > yMax) yMax = pMesh->sVertex.pData[j+1];

                

                if(pMesh->sVertex.pData[j+2] < zMin) zMin = pMesh->sVertex.pData[j+2];

                else if(pMesh->sVertex.pData[j+2] > zMax) zMax = pMesh->sVertex.pData[j+2];

            }

        }

        _center.x = (xMax – xMin) / 2;

        _center.y = (yMax – yMin) / 2;

        _center.z = (zMax – zMin) / 2;

    }

    _scene represents my CPVRTModelPOD and I’m trying to find through each mesh my min and max values.

    Can you tell me what’s wrong with this ?

    #35825

    Aaron
    Member

    Take a look at either of these PVRTools functions:

    PVRTBoundingBoxCompute()
    PVRTBoundingBoxComputeInterleaved()
    Regards,
    Aaron.
    #35826

    The code of the calculation of a center of the bounding box is correct, you can try to fix a code:

    for (unsigned int i = 0; i < _scene->nNumMesh; ++i)

     {

    SPODMesh* pMesh = &_scene->pMesh;

      for(unsigned int j = 0; j < pMesh->nNumVertex; ++j)

    {

    if(pMesh->sVertex.pData[j] < xMin) xMin = pMesh->sVertex.pData[j];

    else if(pMesh->sVertex.pData[j] > xMax) xMax = pMesh->sVertex.pData[j];

    }

     _center.x = (xMax – xMin) / 2;

     _center.y = (yMax – yMin) / 2;

     _center.z = (zMax – zMin) / 2;

    }

    AndreyOGL_D3D2012-05-28 11:24:30

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.