Sign in to follow this  

Extract 6 planes from bounding box

This topic is 1706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

This topic is 1706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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