// =============================================================================
    // METHODS STATIC --------------------------------------------------------------
    public static void SetVanishingPoint( Camera cam, float offset, ClientCameraScreen screen )
    {
        Transform t = cam.transform;
        NearPlane plane = new NearPlane();

        Vector3 nearCenter = t.position + t.forward*cam.nearClipPlane;
        Plane nearPlane = new Plane ( -t.forward, nearCenter );
        float distance = 0f;
        Vector3 direction;
        Ray ray;

        Vector3 screenTL = t.TransformPoint ( new Vector3 ( ( -screen.Width/2.0f ) + offset, screen.Height/2.0f, screen.Distance ) );
        direction = ( screenTL - t.position ).normalized;
        ray = new Ray ( t.position, direction );
        nearPlane.Raycast ( ray, out distance );
        Vector3 nearTL = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );

        Vector3 screenBR = t.TransformPoint ( new Vector3 ( ( screen.Width/2.0f ) + offset, -screen.Height/2.0f, screen.Distance ) );
        direction = ( screenBR - t.position ).normalized;
        ray = new Ray ( t.position, direction );
        nearPlane.Raycast ( ray, out distance );
        Vector3 nearBR = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );

        plane.left = nearTL.x;
        plane.top = nearTL.y;
        plane.right = nearBR.x;
        plane.bottom = nearBR.y;
        plane.near = cam.nearClipPlane;
        plane.far = cam.farClipPlane;
        cam.projectionMatrix = PerspectiveOffCenter ( plane );
    }
Beispiel #2
0
    // =============================================================================
    // METHODS STATIC --------------------------------------------------------------

    public static void SetVanishingPoint(Camera cam, float offset, ClientCameraScreen screen)
    {
        Transform t     = cam.transform;
        NearPlane plane = new NearPlane();

        Vector3 nearCenter = t.position + t.forward * cam.nearClipPlane;
        Plane   nearPlane  = new Plane(-t.forward, nearCenter);
        float   distance   = 0f;
        Vector3 direction;
        Ray     ray;

        Vector3 screenTL = t.TransformPoint(new Vector3((-screen.Width / 2.0f) + offset, screen.Height / 2.0f, screen.Distance));

        direction = (screenTL - t.position).normalized;
        ray       = new Ray(t.position, direction);
        nearPlane.Raycast(ray, out distance);
        Vector3 nearTL = -(t.InverseTransformPoint(nearCenter) - t.InverseTransformPoint((t.position + direction * distance)));

        Vector3 screenBR = t.TransformPoint(new Vector3((screen.Width / 2.0f) + offset, -screen.Height / 2.0f, screen.Distance));

        direction = (screenBR - t.position).normalized;
        ray       = new Ray(t.position, direction);
        nearPlane.Raycast(ray, out distance);
        Vector3 nearBR = -(t.InverseTransformPoint(nearCenter) - t.InverseTransformPoint((t.position + direction * distance)));

        plane.left           = nearTL.x;
        plane.top            = nearTL.y;
        plane.right          = nearBR.x;
        plane.bottom         = nearBR.y;
        plane.near           = cam.nearClipPlane;
        plane.far            = cam.farClipPlane;
        cam.projectionMatrix = PerspectiveOffCenter(plane);
    }