Sign in to follow this  
belfegor

Extract 6 planes from bounding box

Recommended Posts

belfegor    2834

I need to create six planes from axis aligned bounding box, so that each plane normal points inside "cube" it creates. If you know what i mean?

 

I think i got it right for normals that point outside? Do i?

struct Plane
{
    float nx, ny, nz, d;

};
 
std::array<Plane, 6> ExtractPlanesFromBBox(D3DXVECTOR3 bMin, D3DXVECTOR3 bMax)

{

    std::array<Plane, 6> out;

    D3DXVECTOR3 center = (bMax + bMin) * 0.5f;

    D3DXVECTOR3 extent = (bMax - bMin) * 0.5f;



    // up

    out[0].d  = center.y + extent.y;

    out[0].nx = 0.0f;

    out[0].ny = 1.0f;

    out[0].nz = 0.0f;



    // down

    out[1].d  = center.y - extent.y;

    out[1].nx = 0.0f;

    out[1].ny = -1.0f;

    out[1].nz = 0.0f;



    // left

    out[2].d  = center.x - extent.x;

    out[2].nx = 1.0f;

    out[2].ny = 0.0f;

    out[2].nz = 0.0f;



    // right

    out[3].d  = center.x + extent.x;

    out[3].nx = -1.0f;

    out[3].ny = 0.0f;

    out[3].nz = 0.0f;



    // back

    out[4].d  = center.z - extent.z;

    out[4].nx = 0.0f;

    out[4].ny = 0.0f;

    out[4].nz = 1.0f;



    // front

    out[5].d  = center.z + extent.z;

    out[5].nx = 0.0f;

    out[5].ny = 0.0f;

    out[5].nz = -1.0f;
 
    return out;
}

 

But normals to point inside, i don't know how to calculate 'd' ? Please advise.

 

Thank you for your time.

Share this post


Link to post
Share on other sites
BornToCode    1185

Compute it the same way you would compute the bounding frustum for an Orthographic view. Using the max and min of the box you can compute all 6 sides of the box.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this