Jump to content
  • Advertisement
Sign in to follow this  
Medo Mex

Creating Camera Bounding Frustum From View and Projection Matrix

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

Advertisement

You just need to multiply the ViewMatrix*Projection Matrix. Then you need to extra the 6 planes that makes up the frustum.

 

//This is Column Major matrix.

//If you have row based then you would flip the multiplication order.

Matrix4x4 ViewProjection = ProjectionMatrix*ViewMatrix;
    
    Plane& right = GetPlaneRight();
    right.normal.x=ViewProjection.m14-ViewProjection.m11;
    right.normal.y=ViewProjection.m24-ViewProjection.m21;
    right.normal.z=ViewProjection.m34-ViewProjection.m31;
    right.distance=ViewProjection.m44-ViewProjection.m41;
    right.Normalized();

    Plane& left = GetPlaneLeft();
    left.normal.x=ViewProjection.m14+ViewProjection.m11;
    left.normal.y=ViewProjection.m24+ViewProjection.m21;
    left.normal.z=ViewProjection.m34+ViewProjection.m31;
    left.distance=ViewProjection.m44+ViewProjection.m41;
    left.Normalized();

    Plane& top = GetPlaneTop();
    top.normal.x=ViewProjection.m14-ViewProjection.m12;
    top.normal.y=ViewProjection.m24-ViewProjection.m22;
    top.normal.z=ViewProjection.m34-ViewProjection.m32;
    top.distance=ViewProjection.m44-ViewProjection.m42;
    top.Normalized();

    Plane& bottom = GetPlaneBottom();
    bottom.normal.x=ViewProjection.m14+ViewProjection.m12;
    bottom.normal.y=ViewProjection.m24+ViewProjection.m22;
    bottom.normal.z=ViewProjection.m34+ViewProjection.m32;
    bottom.distance=ViewProjection.m44+ViewProjection.m42;
    bottom.Normalized();

    Plane& front = GetPlaneFront();
    front.normal.x=ViewProjection.m14-ViewProjection.m13;
    front.normal.y=ViewProjection.m24-ViewProjection.m23;
    front.normal.z=ViewProjection.m34-ViewProjection.m33;
    front.distance=ViewProjection.m44-ViewProjection.m43;
    front.Normalized();

    Plane& back = GetPlaneBack();
    back.normal.x=ViewProjection.m14+ViewProjection.m13;
    back.normal.y=ViewProjection.m24+ViewProjection.m23;
    back.normal.z=ViewProjection.m34+ViewProjection.m33;
    back.distance=ViewProjection.m44+ViewProjection.m43;
    back.Normalized();

Edited by BornToCode

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!