Jump to content
  • Advertisement
Sign in to follow this  

Creating the 6 clipping planes of a cube correctly.

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

Hello there, I have a plane class that defines a plane as follows:
        /// <summary>
        /// If we have a Point available that we know lies on the Plane.
        /// We can compute the distance directly from this Point and the plane normal using: 
        /// distance (d) = (Vector3.Dot(Point, Normal))
        /// </summary>
        /// <param name="normal">Plane Normal</param>
        /// <param name="point">Point that lies on Plane</param>
        public CD_Plane(Vector3 normal, Vector3 point)
            Normal = Vector3.Normalize(normal);
            D = Vector3.Dot(Normal, point);


When creating the 6 clipping planes of a cube I am currently doing the following:
            position = centre;
            normal = normal_Surface;

            Vector3 tangent = Vector3.Cross(normal, Vector3.UnitZ);

            if (tangent.LengthSquared() < 0.0001f)
                tangent = Vector3.Cross(normal, Vector3.UnitY);

            Vector3 binormal = Vector3.Cross(normal, tangent);

            //------- [Calculate Boundary Planes] ---------
            float d = Vector3.Dot(centre, tangent);

            plane_Left = new CD_Plane(tangent, tangent * (width * 0.5f + d));
            plane_Right = new CD_Plane(-tangent, -tangent * (width * 0.5f - d));

            d = Vector3.Dot(centre, binormal);

            plane_Bottom = new CD_Plane(-binormal, -binormal * (height * 0.5f - d));
            plane_Top = new CD_Plane(binormal, binormal * (height * 0.5f + d));

            d = Vector3.Dot(centre, normal);

            plane_Back = new CD_Plane(-normal, -normal * (depth * 0.5f - d));
            plane_Front = new CD_Plane(normal, normal * (depth * 0.5f + d));

The problem is that if the projection onto the axis for the plane is 0, then the plane is not in the right location based on the centre. For example if the centre of the cube is (5, 0, 0) and the tangent is (1, 0, 0) then d would be 5. Therefore a plane created using n = tangent and the distance along n [tangent * (width * 0.5f + d)] would be correct. If the tangent was (0, 1, 0) then d would be 0 and the distance along n is no longer correct. How can I obtain the correct distance along n in all cases for the 6 dividing planes? Thank you.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!