示例#1
0
        public static bool IsBoundsInCameraEx(this Bounds bounds, Camera camera, float leftex, float rightex, float downex,
                                              float upex)
        {
            Matrix4x4 matrix = camera.projectionMatrix * camera.worldToCameraMatrix;

            int code =
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y + bounds.size.y / 2,
                                                      bounds.center.z + bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);


            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y + bounds.size.y / 2,
                                                      bounds.center.z + bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);

            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y - bounds.size.y / 2,
                                                      bounds.center.z + bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);

            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y - bounds.size.y / 2,
                                                      bounds.center.z + bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);

            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y + bounds.size.y / 2,
                                                      bounds.center.z - bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);

            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y + bounds.size.y / 2,
                                                      bounds.center.z - bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);

            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y - bounds.size.y / 2,
                                                      bounds.center.z - bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);

            code &=
                MatrixEx.ComputeOutCodeEx(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y - bounds.size.y / 2,
                                                      bounds.center.z - bounds.size.z / 2, 1), matrix, leftex, rightex, downex, upex);


            if (code != 0)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
 protected override int CalculateCullCode(Vector4 position, Matrix4x4 matrix)
 {
     return(MatrixEx.ComputeOutCodeEx(position, matrix, m_LeftEx, m_RightEx, m_DownEx, m_UpEx));
 }