Example #1
0
    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        float midX            = Screen.width / 2.0f;
        float midY            = Screen.height / 2.0f;
        float componentHeight = 20;
        float componentWidth  = 50;

        stringCameraX = GUI.TextField(new Rect(midX - 100, 50, 50, componentHeight), stringCameraX, 25);
        stringCameraY = GUI.TextField(new Rect(midX - 50, 50, 50, componentHeight), stringCameraY, 25);
        stringCameraZ = GUI.TextField(new Rect(midX, 50, 50, componentHeight), stringCameraZ, 25);


        if (GUI.Button(new Rect(midX + 50, 50, componentWidth, componentHeight), "CAMERA"))
        {
            float cameraX = float.Parse(stringCameraX);
            float cameraY = float.Parse(stringCameraY);
            float cameraZ = float.Parse(stringCameraZ);
            SARCameraPrefab.transform.position = new Vector3(cameraX, cameraY, cameraZ);
        }

        int index    = 0;
        int position = 0;

        stringIndex    = GUI.TextField(new Rect(midX - 25, 25, 50, componentHeight), stringIndex, 25);
        stringPosition = GUI.TextField(new Rect(midX + 25, 25, 50, componentHeight), stringPosition, 25);

        if (GUI.Button(new Rect(midX + 75, 25, componentWidth, componentHeight), "SEND"))
        {
            index    = int.Parse(stringIndex);
            position = int.Parse(stringPosition);
            Debug.Log(index + " " + position);
            int row    = (int)(index / (float)expanDialSticks.NbColumns);
            int column = index % expanDialSticks.NbColumns;
            Debug.Log(row + " " + column);
            expanDialSticks.modelMatrix[row, column].TargetPosition            = (sbyte)position;
            expanDialSticks.modelMatrix[row, column].TargetShapeChangeDuration = 2f;
            expanDialSticks.triggerShapeChange();
        }
        if (GUI.Button(new Rect(midX + 150, 25, componentWidth, componentHeight), "CROSS"))
        {
            for (int i = 0; i < expanDialSticks.NbRows; i++)
            {
                for (int j = 0; j < expanDialSticks.NbColumns; j++)
                {
                    expanDialSticks.modelMatrix[i, j].TargetColor = Color.red;
                    expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration        = 0.1f;
                    expanDialSticks.modelMatrix[i, j].TargetProjectorFrontTexture        = "cross-reverse";
                    expanDialSticks.modelMatrix[i, j].TargetProjectorFrontColor          = Color.white;
                    expanDialSticks.modelMatrix[i, j].TargetProjectorFrontRotation       = 90f;
                    expanDialSticks.modelMatrix[i, j].TargetProjectorFrontSize           = 0.02f;
                    expanDialSticks.modelMatrix[i, j].TargetProjectorFrontChangeDuration = 0.1f;
                }
            }
            expanDialSticks.triggerProjectorChange();
            expanDialSticks.triggerTextureChange();
        }
    }
Example #2
0
 private void ResetDisplay()
 {
     for (int i = 0; i < expanDialSticks.NbRows; i++)
     {
         for (int j = 0; j < expanDialSticks.NbColumns; j++)
         {
             //Projector
             expanDialSticks.modelMatrix[i, j].TargetProjectorTexture        = "default";
             expanDialSticks.modelMatrix[i, j].TargetProjectorRotation       = 90f;
             expanDialSticks.modelMatrix[i, j].TargetProjectorSize           = expanDialSticks.modelMatrix[i, j].Diameter / 3f;
             expanDialSticks.modelMatrix[i, j].TargetProjectorChangeDuration = 0.1f;
             //Texture
             expanDialSticks.modelMatrix[i, j].TargetColor = Color.white;
             expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration = 0.1f;
             //Shape
             //expanDialSticks.modelMatrix[i, j].TargetPosition = 0;
             //expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration;
         }
     }
     expanDialSticks.triggerProjectorChange();
     expanDialSticks.triggerTextureChange();
     //expanDialSticks.triggerShapeChange();
 }
Example #3
0
    void Update()
    {
        // check if ExpanDialSticks is connected
        if (connected)
        {
            if (Input.GetKey("escape") || (currentIndex > expanDialSticks.NbRows * expanDialSticks.NbColumns - 1))
            {
                Quit();
            }

            if (Input.GetKeyDown("i"))
            {
                for (int i = 0; i < expanDialSticks.NbRows; i++)
                {
                    for (int j = 0; j < expanDialSticks.NbColumns; j++)
                    {
                        expanDialSticks.modelMatrix[i, j].TargetColor = Color.red;
                        expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration   = 0.1f;
                        expanDialSticks.modelMatrix[i, j].TargetProjectorTexture        = "cross-reverse";
                        expanDialSticks.modelMatrix[i, j].TargetProjectorColor          = Color.white;
                        expanDialSticks.modelMatrix[i, j].TargetProjectorRotation       = 90f;
                        expanDialSticks.modelMatrix[i, j].TargetProjectorSize           = 2f;
                        expanDialSticks.modelMatrix[i, j].TargetProjectorChangeDuration = 0.1f;
                    }
                }
                expanDialSticks.triggerProjectorChange();
                expanDialSticks.triggerTextureChange();
            }

            if (Input.GetKeyDown("n"))
            {
                int i = currentIndex / expanDialSticks.NbColumns;                // int i = 4;
                int j = currentIndex % expanDialSticks.NbColumns;                // int j = 3;

                expanDialSticks.modelMatrix[i, j].TargetPosition            = 30;
                expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = 1f;
                expanDialSticks.triggerShapeChange();
                currentIndex++;
                Debug.Log(i + " " + j + " " + 30);
            }
        }
    }
Example #4
0
    private void TriggerNextTrial()
    {
        if (trials.Count() > 0)
        {
            List <Vector3Int> unsafes;
            List <Vector3Int> safes;
            //Vector2Int rightCandidatePosition = new Vector2Int(rightCandidate.x, rightCandidate.y);
            bool candidatesFound = false;
            int  iconFactorIndex = -1;
            while (!candidatesFound)
            {
                iconFactorIndex++;
                if (iconFactorIndex < trials.Count())
                {
                    currIconUnder = trials[iconFactorIndex];
                    Debug.Log("Looking for candidates (" + currIconUnder + ")...");

                    // get all pins under and around user body
                    unsafes = FindAllUnsafesUnderDistance(safetyDistance);
                    safes   = FindAllSafesAboveDistance(safetyDistance);

                    // prevent same candidates
                    unsafes.RemoveAll(x => movingCandidates.Contains(x));
                    safes.RemoveAll(x => movingCandidates.Contains(x));
                    // candidates to find under or above
                    int nbUnderCandidates  = currIconUnder;
                    int nbAroundCandidates = maxIconUnder - currIconUnder;
                    Predicate <Vector3Int> hasPotentialRightCandidate = candidate => Math.Abs(positionCandidates.Last() - candidate.z) >= stepPositionCandidate;
                    List <Vector3Int>      potentialRightCandidates   = new List <Vector3Int>();
                    potentialRightCandidates.AddRange(unsafes.FindAll(hasPotentialRightCandidate));
                    potentialRightCandidates.AddRange(safes.FindAll(hasPotentialRightCandidate));
                    // if there is enough candidates
                    if (unsafes.Count() >= nbUnderCandidates && safes.Count() >= nbAroundCandidates && potentialRightCandidates.Count() > 0)
                    {
                        // Randomly select the right candidate
                        rightCandidate = potentialRightCandidates[Random.Range(0, potentialRightCandidates.Count())];
                        // Get all moving candidates
                        movingCandidates = new List <Vector3Int>();
                        ListExtension.Shuffle(unsafes);
                        ListExtension.Shuffle(safes);
                        bool isSafe = safes.Remove(rightCandidate);
                        //Debug.Log("isSafe => " + isSafe);
                        bool isUnsafe = unsafes.Remove(rightCandidate);
                        //Debug.Log("isUnsafe => " + isUnsafe);
                        // check if right candidates is safe or unsafe to not select him
                        if (isSafe)
                        {
                            movingCandidates.AddRange(unsafes.GetRange(0, nbUnderCandidates));
                            movingCandidates.AddRange(safes.GetRange(0, nbAroundCandidates - 1));
                        }
                        else if (isUnsafe)
                        {
                            movingCandidates.AddRange(unsafes.GetRange(0, nbUnderCandidates - 1));
                            movingCandidates.AddRange(safes.GetRange(0, nbAroundCandidates));
                        }
                        // generate position for moving candidates
                        for (int i = 0; i < movingCandidates.Count(); i++)
                        {
                            Vector3Int movingCandidate = movingCandidates[i];
                            movingCandidate.z   = Math.Abs(positionCandidates[0] - movingCandidate.z) > Math.Abs(positionCandidates[1] - movingCandidate.z) ? positionCandidates[0] : positionCandidates[1];
                            movingCandidates[i] = movingCandidate;
                        }
                        //Debug.Log("movingCandidates.Count() => " + movingCandidates.Count());
                        // Select a wrong candidate
                        wrongCandidate = movingCandidates[Random.Range(0, movingCandidates.Count())];
                        // Add the right candidate to moving candidate
                        rightCandidate.z = positionCandidates.Last();
                        movingCandidates.Add(rightCandidate);


                        candidatesFound = true;
                    }
                    else
                    {
                        //What if?
                    }
                }
                else                 // fails to find candidates for remaining icon factor
                {
                    Debug.Log("Candidates Fail! Adding IconFactor.NoIconUnder.");
                    iconFactorIndex = -1;
                    trials.Insert(0, 0);
                }
            }
            Debug.Log("Candidates Successfully found!");
            trials.RemoveAt(iconFactorIndex);

            // Output Control
            List <int> randomIcons = new List <int>();           //= Enumerable.Range(0, nbPins).ToList<int>();
            for (int i = 1; i < 30; i++)
            {
                randomIcons.Add(i);
            }
            ListExtension.Shuffle(randomIcons);

            for (int i = 0; i < expanDialSticks.NbRows; i++)
            {
                for (int j = 0; j < expanDialSticks.NbColumns; j++)
                {
                    Vector3Int movingCandidate = movingCandidates.Find(l => (l.x == i && l.y == j));
                    if (rightCandidate.x == i && rightCandidate.y == j)
                    {
                        Debug.Log("rightCandidate => " + rightCandidate);
                        // Projector
                        expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon0";
                        // Shape
                        expanDialSticks.modelMatrix[i, j].TargetPosition            = (sbyte)rightCandidate.z;
                        expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration;
                    }
                    else if (wrongCandidate.x == i && wrongCandidate.y == j)
                    {
                        Debug.Log("wrongCandidate => " + wrongCandidate);
                        // Projector
                        expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon0";
                        // Shape
                        expanDialSticks.modelMatrix[i, j].TargetPosition            = (sbyte)wrongCandidate.z;
                        expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration;
                    }
                    else if (movingCandidate != new Vector3Int())
                    {
                        Debug.Log("movingCandidate => " + movingCandidate);
                        // Projector
                        expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon" + randomIcons.First();
                        randomIcons.RemoveAt(0);
                        // Shape
                        expanDialSticks.modelMatrix[i, j].TargetPosition            = (sbyte)movingCandidate.z;
                        expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration;
                    }
                    else
                    {
                        // Projector
                        //expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "default";
                        expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon" + randomIcons.First();
                        randomIcons.RemoveAt(0);
                    }
                    // Projector
                    expanDialSticks.modelMatrix[i, j].TargetProjectorRotation       = 90f;
                    expanDialSticks.modelMatrix[i, j].TargetProjectorSize           = 2f;
                    expanDialSticks.modelMatrix[i, j].TargetProjectorChangeDuration = 0.1f;
                }
            }
            expanDialSticks.triggerProjectorChange();
            expanDialSticks.triggerShapeChange();

            string participantNumber = "<pos=0%><b>P" + numeroParticipant + "</b>";
            string trialProgress     = "<pos=90%><b>" + trials.Count() + "/" + nbTrials + "</b>";
            string legend            = participantNumber + trialProgress;
            expanDialSticks.setBottomBorderText(TextAlignmentOptions.Center, 16, Color.black, legend, new Vector3(90f, -90f, 0f));
            expanDialSticks.setBorderBackground(Color.white);
            expanDialSticks.triggerTextureChange();
            string iconSituationMsg = "ICON_APPARATUS " + currIconUnder;
            expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(iconSituationMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false);
            string selectCandidateMsg = "SYSTEM_SELECT_PIN ";
            foreach (Vector3Int movingCandidate in movingCandidates)
            {
                selectCandidateMsg += "(" + movingCandidate.x + ", " + movingCandidate.y + ", " + movingCandidate.z + ") ";
            }
            expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(selectCandidateMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false);
            string rightCandidateMsg = "SYSTEM_RIGHT_PIN (" + rightCandidate.x + ", " + rightCandidate.y + ", " + rightCandidate.z + ")";
            expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(rightCandidateMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false);
            string wrongCandidateMsg = "SYSTEM_WRONG_PIN (" + wrongCandidate.x + ", " + wrongCandidate.y + ", " + wrongCandidate.z + ")";
            expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(wrongCandidateMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false);
        }
        else
        {
            Quit();
        }
    }