Пример #1
0
    private Vector3 DecideDistractionPoint() // Controls where the light looks to distract the player
    {
        height = cam.pixelHeight;
        width  = cam.pixelWidth;
        GazePoint gazePoint     = TobiiAPI.GetGazePoint();
        Vector2   avoidPosition = cam.WorldToScreenPoint(bookshelf.position);
        //  might be able to check if it is in frame: device.IsInsideFrame()

        // Calculate distance to corners of game view
        float UpperLeftDist   = Vector2.Distance(new Vector2(0, height), avoidPosition);
        float BottomLeftDist  = Vector2.Distance(new Vector2(0, 0), avoidPosition);
        float UpperRightDist  = Vector2.Distance(new Vector2(width, height), avoidPosition);
        float BottomRightDist = Vector2.Distance(new Vector2(width, 0), avoidPosition);

        // Select corner furthest away
        Vector2 furthestCorner;
        float   maxDist = Mathf.Max(UpperLeftDist, BottomLeftDist, UpperRightDist, BottomRightDist);

        if (Math.Abs(maxDist - UpperLeftDist) < 0.1)
        {
            furthestCorner = new Vector2(0, height);
        }
        else if (Math.Abs(maxDist - UpperRightDist) < 0.1)
        {
            furthestCorner = new Vector2(width, height);
        }
        else if (Math.Abs(maxDist - BottomLeftDist) < 0.1)
        {
            furthestCorner = new Vector2(0, 0);
        }
        else if (Math.Abs(maxDist - BottomRightDist) < 0.1)
        {
            furthestCorner = new Vector2(width, 0);
        }
        else
        {
            furthestCorner = new Vector2(width, height);
        }

        // Clamp distraction point
        var x   = Mathf.Clamp(furthestCorner.x, width * distractionMarginMin, width * distractionMarginMax);
        var y   = Mathf.Clamp(furthestCorner.y, height * distractionMarginMin, height * distractionMarginMax);
        var pos = new Vector2(x, y);

        // Cast ray through camera to find point in world coordinates
        RaycastHit hit;
        Ray        ray = cam.ScreenPointToRay(pos);

        Physics.Raycast(ray, out hit);

        return(hit.point);
    }