Example #1
0
        public void CalcFrustumPlanes()
        {
            Vector3d cN = Position + CenterOfInterest * Znear;
            Vector3d cF = Position + CenterOfInterest * Zfar;

            double Hnear  = 2.0f * Convert.ToSingle(Math.Tan(Matrix4dExtension.DegreesToRadians(fov / 2.0f)) * Znear);
            double Wnear  = Hnear * aspect_ratio;
            double Hfar   = 2.0f * Convert.ToSingle(Math.Tan(Matrix4dExtension.DegreesToRadians(fov / 2.0f)) * Zfar);
            double Wfar   = Hfar * aspect_ratio;
            double hHnear = Hnear / 2.0f;
            double hWnear = Wnear / 2.0f;
            double hHfar  = Hfar / 2.0f;
            double hWfar  = Wfar / 2.0f;


            farPts[0] = cF + Up * hHfar - right * hWfar;
            farPts[1] = cF - Up * hHfar - right * hWfar;
            farPts[2] = cF - Up * hHfar + right * hWfar;
            farPts[3] = cF + Up * hHfar + right * hWfar;

            nearPts[0] = cN + Up * hHnear - right * hWnear;
            nearPts[1] = cN - Up * hHnear - right * hWnear;
            nearPts[2] = cN - Up * hHnear + right * hWnear;
            nearPts[3] = cN + Up * hHnear + right * hWnear;

            planes[0] = CPlane.FromPoints(nearPts[3], nearPts[0], farPts[0]);
            planes[1] = CPlane.FromPoints(nearPts[1], nearPts[2], farPts[2]);
            planes[2] = CPlane.FromPoints(nearPts[0], nearPts[1], farPts[1]);
            planes[3] = CPlane.FromPoints(nearPts[2], nearPts[3], farPts[2]);
            planes[4] = CPlane.FromPoints(nearPts[0], nearPts[3], nearPts[2]);
            planes[5] = CPlane.FromPoints(farPts[3], farPts[0], farPts[1]);
        }
Example #2
0
        public static CPlane FromPoints(Vector3d v1, Vector3d v2, Vector3d v3)
        {
            CPlane   temp = new CPlane();
            Vector3d e1   = v2 - v1;
            Vector3d e2   = v3 - v1;
            Vector3d v    =
                temp.N = Vector3d.Normalize(Vector3d.Cross(e1, e2));

            temp.d = -Vector3d.Dot(temp.N, v1);
            return(temp);
        }