float CheckCameraPoints(Vector3 from, Vector3 to)
    {
        var        nearestDistance = -1f;
        RaycastHit hitInfo;

        HelperK.ClipPlanePoints clipPlanePoints = HelperK.ClipPlaneAtNear(to);

        //debugging lines creation
        Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red);
        Debug.DrawLine(from, clipPlanePoints.UpperLeft);
        Debug.DrawLine(from, clipPlanePoints.LowerLeft);
        Debug.DrawLine(from, clipPlanePoints.UpperRight);
        Debug.DrawLine(from, clipPlanePoints.LowerRight);

        Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight);
        Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight);
        Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft);
        Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft);

        if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            nearestDistance = hitInfo.distance;
        }

        if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }


        return(nearestDistance);
    }
示例#2
0
    //helper function for the Occlusion system, given two vectors it checks the Clip Plane points and returns the nearest distance we can reach without occluding
    float CheckCameraPoints(Vector3 from, Vector3 to)
    {
        var        nearestDistance = -1f;
        RaycastHit hitInfo;

        HelperK.ClipPlanePoints clipPlanePoints = HelperK.ClipPlaneAtNear(to);

        //debugging lines creation
        Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red);
        Debug.DrawLine(from, clipPlanePoints.UpperLeft);
        Debug.DrawLine(from, clipPlanePoints.LowerLeft);
        Debug.DrawLine(from, clipPlanePoints.UpperRight);
        Debug.DrawLine(from, clipPlanePoints.LowerRight);

        Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight);
        Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight);
        Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft);
        Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft);

        //ensure at each step we do not hit irrelevant colliders (Player (Ourselves), Enemies, or Objects specifically marked to not have CameraCollisions)
        if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy")
        {
            nearestDistance = hitInfo.distance;
        }

        if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo))
        {
            Debug.Log(hitInfo.collider.tag);
            Debug.Log(hitInfo.collider.name);
        }

        return(nearestDistance);
    }