Jump to content
  • Advertisement
Sign in to follow this  

Extract 6 planes from bounding box

This topic is 1897 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

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!