Sign in to follow this  

Creating Camera Bounding Frustum From View and Projection Matrix

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

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

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