Example #1
0
    IEnumerator CaptureFrameForFloor()
    {
        ToggleUI(false);
        yield return(new WaitForEndOfFrame());

        float capinv = 1 - m_SizeOfCap;

        m_PosOfCap = m_Camera.transform.position;
        m_RotOfCap = m_Camera.transform.rotation;

        Texture2D m_Image2DProjector = new Texture2D((int)(Screen.width * m_SizeOfCap), (int)(Screen.height * m_SizeOfCap), TextureFormat.ARGB32, false);

        m_Image2DProjector.ReadPixels(new Rect((float)(capinv / 2) * Screen.width, (float)(capinv / 2) * Screen.height, Screen.width * m_SizeOfCap, Screen.height * m_SizeOfCap), 0, 0);

        ToggleUI(true);
        int layer_mask = LayerMask.GetMask("MainPlane");

        //Raycast Center
        Ray        rayCenter = m_Camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit center_hit;
        GameObject center_hitObj;
        Vector3    center_hitPoint = new Vector3(0, 0, 0);
        float      center_distance = 0;

        if (Physics.Raycast(rayCenter, out center_hit, 99, layer_mask))
        {
            center_hitObj   = center_hit.transform.gameObject;
            center_hitPoint = center_hit.point;
            center_distance = center_hit.distance;
        }


        //Raycast TopLeft
        Ray        rayTopLeft = m_Camera.ViewportPointToRay(new Vector3((float)(capinv / 2), 1 - (float)(capinv / 2), 0));
        RaycastHit topleft_hit;
        GameObject topleft_hitObj;
        Vector3    topleft_hitPoint = new Vector3(0, 0, 0);
        float      topleft_distance = 0;

        if (Physics.Raycast(rayTopLeft, out topleft_hit, 99, layer_mask))
        {
            topleft_hitObj   = topleft_hit.transform.gameObject;
            topleft_hitPoint = topleft_hit.point;
            topleft_distance = topleft_hit.distance;
        }

        //Raycast TopRight
        Ray        rayTopRight = m_Camera.ViewportPointToRay(new Vector3(1 - (float)(capinv / 2), 1 - (float)(capinv / 2), 0));
        RaycastHit topright_hit;
        GameObject topright_hitObj;
        Vector3    topright_hitPoint = new Vector3(0, 0, 0);
        float      topright_distance = 0;

        if (Physics.Raycast(rayTopRight, out topright_hit, 99, layer_mask))
        {
            topright_hitObj   = topright_hit.transform.gameObject;
            topright_hitPoint = topright_hit.point;
            topright_distance = topright_hit.distance;
        }

        //Raycast BotLeft
        Ray        rayBotLeft = m_Camera.ViewportPointToRay(new Vector3((float)(capinv / 2), (float)(capinv / 2), 0));
        RaycastHit botleft_hit;
        GameObject botleft_hitObj;
        Vector3    botleft_hitPoint = new Vector3(0, 0, 0);
        float      botleft_distance = 0;

        if (Physics.Raycast(rayBotLeft, out botleft_hit, 99, layer_mask))
        {
            botleft_hitObj   = botleft_hit.transform.gameObject;
            botleft_hitPoint = botleft_hit.point;
            botleft_distance = botleft_hit.distance;
        }

        //Raycast BotRight
        Ray        rayBotRight = m_Camera.ViewportPointToRay(new Vector3(1 - (float)(capinv / 2), (float)(capinv / 2), 0));
        RaycastHit botright_hit;
        GameObject botright_hitObj;
        Vector3    botright_hitPoint = new Vector3(0, 0, 0);
        float      botright_distance = 0;

        if (Physics.Raycast(rayBotRight, out botright_hit, 99, layer_mask))
        {
            botright_hitObj   = botright_hit.transform.gameObject;
            botright_hitPoint = botright_hit.point;
            botright_distance = botright_hit.distance;
        }

        //Raycast Left2
        Ray        rayLeft2 = m_Camera.ViewportPointToRay(new Vector3(0 - (float)(capinv / 2), .66666f - (float)(capinv / 2), 0));
        RaycastHit Left2_hit;
        GameObject Left2_hitObj;
        Vector3    Left2_hitPoint = new Vector3(0, 0, 0);
        float      Left2_distance = 0;

        if (Physics.Raycast(rayLeft2, out Left2_hit, 99, layer_mask))
        {
            Left2_hitObj   = Left2_hit.transform.gameObject;
            Left2_hitPoint = Left2_hit.point;
            Left2_distance = Left2_hit.distance;
        }

        //Raycast Left3
        Ray        rayLeft3 = m_Camera.ViewportPointToRay(new Vector3(0 - (float)(capinv / 2), .33333f - (float)(capinv / 2), 0));
        RaycastHit Left3_hit;
        GameObject Left3_hitObj;
        Vector3    Left3_hitPoint = new Vector3(0, 0, 0);
        float      Left3_distance = 0;

        if (Physics.Raycast(rayLeft3, out Left3_hit, 99, layer_mask))
        {
            Left3_hitObj   = Left3_hit.transform.gameObject;
            Left3_hitPoint = Left3_hit.point;
            Left3_distance = Left3_hit.distance;
        }

        //Raycast Right2
        Ray        rayRight2 = m_Camera.ViewportPointToRay(new Vector3(1 - (float)(capinv / 2), .66666f - (float)(capinv / 2), 0));
        RaycastHit Right2_hit;
        GameObject Right2_hitObj;
        Vector3    Right2_hitPoint = new Vector3(0, 0, 0);
        float      Right2_distance = 0;

        if (Physics.Raycast(rayRight2, out Right2_hit, 99, layer_mask))
        {
            Right2_hitObj   = Right2_hit.transform.gameObject;
            Right2_hitPoint = Right2_hit.point;
            Right2_distance = Right2_hit.distance;
        }

        //Raycast Right3
        Ray        rayRight3 = m_Camera.ViewportPointToRay(new Vector3(1 - (float)(capinv / 2), .33333f - (float)(capinv / 2), 0));
        RaycastHit Right3_hit;
        GameObject Right3_hitObj;
        Vector3    Right3_hitPoint = new Vector3(0, 0, 0);
        float      Right3_distance = 0;

        if (Physics.Raycast(rayRight3, out Right3_hit, 99, layer_mask))
        {
            Right3_hitObj   = Right3_hit.transform.gameObject;
            Right3_hitPoint = Right3_hit.point;
            Right3_distance = Right3_hit.distance;
        }

        Debug.Log("Device Center: " + center_hitPoint);
        Debug.Log("Device Cam corners: " + topleft_hitPoint + ", " + topright_hitPoint + ", " + botleft_hitPoint + ", " + botright_hitPoint);

        floorControl.InitializeObjects();
    }
Example #2
0
    IEnumerator CaptureFrameForFloor()
    {
        ToggleUI(false);
        yield return(new WaitForEndOfFrame());

        float capinv = 1 - m_SizeOfCap;

        m_PosOfCap = m_Camera.transform.position;
        m_RotOfCap = m_Camera.transform.rotation;

        Texture2D m_Image2DProjector = new Texture2D((int)(Screen.width * m_SizeOfCap), (int)(Screen.height * m_SizeOfCap), TextureFormat.ARGB32, false);

        m_Image2DProjector.ReadPixels(new Rect((float)(capinv / 2) * Screen.width, (float)(capinv / 2) * Screen.height, Screen.width * m_SizeOfCap, Screen.height * m_SizeOfCap), 0, 0);
        //m_Image2DProjector.ReadPixels(new Rect((float)(capinv / 2) * Screen.width, (float)(capinv / 2) * Screen.height, Screen.width - ((float)(capinv / 2) * Screen.width), Screen.height - ((float)(capinv / 2) * Screen.height)), 0, 0);
        ToggleUI(true);
        int layer_mask = LayerMask.GetMask("MainPlane");

        //      1--2--3--4
        //      | 7| 8| 9|
        //      5--6--7--8
        //      | 4| 5| 6|
        //      9-10-11-12
        //      | 1| 2| 3|
        //     13-14-15-16

        float   centerX  = 0.5f;
        float   centerY  = 0.5f;
        Vector3 CenterPt = GetRaycastPosition(centerX, centerY);

        float   Pt1X = (float)(capinv / 2);
        float   Pt1Y = (1 - (float)(capinv / 2));
        Vector3 Pt1  = GetRaycastPosition(Pt1X, Pt1Y);

        float   Pt13X = (float)(capinv / 2);
        float   Pt13Y = (float)(capinv / 2);
        Vector3 Pt13  = GetRaycastPosition(Pt13X, Pt13Y);

        float   Pt5X = (float)(capinv / 2);
        float   Pt5Y = ((Pt1Y - Pt13Y) * .66666f) + Pt13Y;
        Vector3 Pt5  = GetRaycastPosition(Pt5X, Pt5Y);

        float   Pt9X = (float)(capinv / 2);
        float   Pt9Y = ((Pt1Y - Pt13Y) * .33333f) + Pt13Y;
        Vector3 Pt9  = GetRaycastPosition(Pt9X, Pt9Y);

        float   Pt4X = (1 - (float)(capinv / 2));
        float   Pt4Y = (1 - (float)(capinv / 2));
        Vector3 Pt4  = GetRaycastPosition(Pt4X, Pt4Y);

        float   Pt16X = (1 - (float)(capinv / 2));
        float   Pt16Y = (float)(capinv / 2);
        Vector3 Pt16  = GetRaycastPosition(Pt16X, Pt16Y);

        float   Pt8X = (1 - (float)(capinv / 2));
        float   Pt8Y = ((Pt4Y - Pt16Y) * .66666f) + Pt16Y;
        Vector3 Pt8  = GetRaycastPosition(Pt8X, Pt8Y);

        float   Pt12X = (1 - (float)(capinv / 2));
        float   Pt12Y = ((Pt4Y - Pt16Y) * .33333f) + Pt16Y;
        Vector3 Pt12  = GetRaycastPosition(Pt12X, Pt12Y);

        float   Pt2X = ((Pt4X - Pt1X) * 0.33333f) + Pt1X;
        float   Pt2Y = (1 - (float)(capinv / 2));
        Vector3 Pt2  = GetRaycastPosition(Pt2X, Pt2Y);

        float   Pt3X = ((Pt4X - Pt1X) * 0.66666f) + Pt1X;
        float   Pt3Y = (1 - (float)(capinv / 2));
        Vector3 Pt3  = GetRaycastPosition(Pt3X, Pt3Y);

        float   Pt14X = ((Pt16X - Pt13X) * 0.33333f) + Pt13X;
        float   Pt14Y = (float)(capinv / 2);
        Vector3 Pt14  = GetRaycastPosition(Pt14X, Pt14Y);

        float   Pt15X = ((Pt16X - Pt13X) * 0.66666f) + Pt13X;
        float   Pt15Y = (float)(capinv / 2);
        Vector3 Pt15  = GetRaycastPosition(Pt15X, Pt15Y);

        float   Pt6X = ((Pt8X - Pt5X) * 0.33333f) + Pt5X;
        float   Pt6Y = ((Pt2Y - Pt14Y) * 0.66666f) + Pt14Y;
        Vector3 Pt6  = GetRaycastPosition(Pt6X, Pt6Y);

        float   Pt7X = ((Pt8X - Pt5X) * 0.66666f) + Pt5X;
        float   Pt7Y = ((Pt3Y - Pt15Y) * 0.66666f) + Pt15Y;
        Vector3 Pt7  = GetRaycastPosition(Pt7X, Pt7Y);

        float   Pt10X = ((Pt12X - Pt9X) * 0.33333f) + Pt9X;
        float   Pt10Y = ((Pt2Y - Pt14Y) * 0.33333f) + Pt14Y;
        Vector3 Pt10  = GetRaycastPosition(Pt10X, Pt10Y);

        float   Pt11X = ((Pt12X - Pt9X) * 0.66666f) + Pt9X;
        float   Pt11Y = ((Pt3Y - Pt15Y) * 0.33333f) + Pt15Y;
        Vector3 Pt11  = GetRaycastPosition(Pt11X, Pt11Y);

        //      1--2--3--4
        //      | 7| 8| 9|
        //      5--6--7--8
        //      | 4| 5| 6|
        //      9-10-11-12
        //      | 1| 2| 3|
        //     13-14-15-16

        //Jerry rigged adjustment of points
        float t_distance;
        float RightAdj = 1 - FloorUIControl.m_RightAdj;
        float TopAdj   = 1 - FloorUIControl.m_TopAdj;
        float LeftAdj  = 1 - FloorUIControl.m_LeftAdj;
        float BotAdj   = 1 - FloorUIControl.m_BotAdj;

        Vector3 AdjLeft1Pt, AdjLeft2Pt, AdjLeft3Pt, AdjLeft4Pt;
        Vector3 AdjRight1Pt, AdjRight2Pt, AdjRight3Pt, AdjRight4Pt;

        //crunch top to bot
        t_distance = Vector3.Distance(Pt1, Pt13);
        AdjLeft1Pt = Vector3.MoveTowards(Pt1, Pt13, t_distance * TopAdj);

        t_distance = Vector3.Distance(Pt5, Pt13);
        AdjLeft2Pt = Vector3.MoveTowards(Pt5, Pt13, t_distance * TopAdj);

        t_distance = Vector3.Distance(Pt9, Pt13);
        AdjLeft3Pt = Vector3.MoveTowards(Pt9, Pt13, t_distance * TopAdj);

        t_distance  = Vector3.Distance(Pt4, Pt16);
        AdjRight1Pt = Vector3.MoveTowards(Pt4, Pt16, t_distance * TopAdj);

        t_distance  = Vector3.Distance(Pt8, Pt16);
        AdjRight2Pt = Vector3.MoveTowards(Pt8, Pt16, t_distance * TopAdj);

        t_distance  = Vector3.Distance(Pt12, Pt16);
        AdjRight3Pt = Vector3.MoveTowards(Pt12, Pt16, t_distance * TopAdj);

        //crunch bot to top
        t_distance = Vector3.Distance(AdjLeft2Pt, AdjLeft1Pt);
        AdjLeft2Pt = Vector3.MoveTowards(AdjLeft2Pt, AdjLeft1Pt, t_distance * BotAdj);

        t_distance = Vector3.Distance(AdjLeft3Pt, AdjLeft1Pt);
        AdjLeft3Pt = Vector3.MoveTowards(AdjLeft3Pt, AdjLeft1Pt, t_distance * BotAdj);

        t_distance = Vector3.Distance(Pt13, AdjLeft1Pt);
        AdjLeft4Pt = Vector3.MoveTowards(Pt13, AdjLeft1Pt, t_distance * BotAdj);

        t_distance  = Vector3.Distance(AdjRight2Pt, AdjRight1Pt);
        AdjRight2Pt = Vector3.MoveTowards(AdjRight2Pt, AdjRight1Pt, t_distance * BotAdj);

        t_distance  = Vector3.Distance(AdjRight3Pt, AdjRight1Pt);
        AdjRight3Pt = Vector3.MoveTowards(AdjRight3Pt, AdjRight1Pt, t_distance * BotAdj);

        t_distance  = Vector3.Distance(Pt16, AdjRight1Pt);
        AdjRight4Pt = Vector3.MoveTowards(Pt16, AdjRight1Pt, t_distance * BotAdj);

        //crunch right to left
        t_distance  = Vector3.Distance(AdjLeft1Pt, AdjRight1Pt);
        AdjRight1Pt = Vector3.MoveTowards(AdjRight1Pt, AdjLeft1Pt, t_distance * RightAdj);

        t_distance  = Vector3.Distance(AdjLeft2Pt, AdjRight2Pt);
        AdjRight2Pt = Vector3.MoveTowards(AdjRight2Pt, AdjLeft2Pt, t_distance * RightAdj);

        t_distance  = Vector3.Distance(AdjLeft3Pt, AdjRight3Pt);
        AdjRight3Pt = Vector3.MoveTowards(AdjRight3Pt, AdjLeft3Pt, t_distance * RightAdj);

        t_distance  = Vector3.Distance(AdjLeft4Pt, AdjRight4Pt);
        AdjRight4Pt = Vector3.MoveTowards(AdjRight4Pt, AdjLeft4Pt, t_distance * RightAdj);

        //chunk left to right
        t_distance = Vector3.Distance(AdjLeft1Pt, AdjRight1Pt);
        AdjLeft1Pt = Vector3.MoveTowards(AdjLeft1Pt, AdjRight1Pt, t_distance * LeftAdj);

        t_distance = Vector3.Distance(AdjLeft2Pt, AdjRight2Pt);
        AdjLeft2Pt = Vector3.MoveTowards(AdjLeft2Pt, AdjRight2Pt, t_distance * LeftAdj);

        t_distance = Vector3.Distance(AdjLeft3Pt, AdjRight3Pt);
        AdjLeft3Pt = Vector3.MoveTowards(AdjLeft3Pt, AdjRight3Pt, t_distance * LeftAdj);

        t_distance = Vector3.Distance(AdjLeft4Pt, AdjRight4Pt);
        AdjLeft4Pt = Vector3.MoveTowards(AdjLeft4Pt, AdjRight4Pt, t_distance * LeftAdj);


        FloorControl.SetValues(m_Image2DProjector, m_SizeOfCap, m_PosOfCap, m_RotOfCap, CenterPt);
        PitControl.SetValues(CenterPt, AdjLeft1Pt, AdjRight1Pt, AdjLeft4Pt, AdjRight4Pt);
        //ChunkControl.SetValues(CenterPt, AdjLeft1Pt, AdjLeft2Pt, AdjLeft3Pt, Pt13, AdjRight1Pt, AdjRight2Pt, AdjRight3Pt, AdjRight4Pt, Pt6, Pt7, Pt10, Pt11);
        ChunkControl.SetValues(CenterPt, Pt1, Pt2, Pt3, Pt4,
                               Pt5, Pt6, Pt7, Pt8,
                               Pt9, Pt10, Pt11, Pt12,
                               Pt13, Pt14, Pt15, Pt16);


        //      1--2--3--4
        //      | 7| 8| 9|
        //      5--6--7--8
        //      | 4| 5| 6|
        //      9-10-11-12
        //      | 1| 2| 3|
        //     13-14-15-16

        FloorControl.InitializeObjects();
    }