Example #1
0
                private void FixedUpdate()
                {
                    initialMenu();
                    border = Oval.Border;
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                    {
                        return;
                    }
                    Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal;

                    if (SRanipal_Eye.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else
                    {
                    };
                    Vector3 GazeDirectionCombined = Camera.main.transform.TransformDirection(GazeDirectionCombinedLocal);

                    GazeRayRenderer.SetPosition(0, Camera.main.transform.position - Camera.main.transform.up * 0.05f);
                    GazeRayRenderer.SetPosition(1, Camera.main.transform.position + GazeDirectionCombined * LengthOfRay);
                    Vector3 Gaze_oval = GazeDirectionCombinedLocal - new Vector3(Oval.X0, Oval.Y0, 0);
                    Vector2 Choice    = new Vector2(Gaze_oval.x, Gaze_oval.y);

                    if (count == rounds * (menu.Length - 1) + 1)
                    {
                        hint.GetComponent <TextMesh>().text = "Round Finished";
                        mark = "finished";
                    }
                    if (isStart && count == 0)
                    {
                        hint.GetComponent <TextMesh>().text = nextCount();
                        StreamWriter writer = new StreamWriter(new FileStream("rec\\" + filepath, FileMode.Append));
                        writer.WriteLine(mark + " " + time_recorder + " " + randomInt[(count - 1) % 12] + " " + GazeDirectionCombinedLocal.x + " " + GazeDirectionCombinedLocal.y
                                         + " " + GazeDirectionCombinedLocal.z + " " + mis);
                        writer.Close();
                    }
                    if (!GazeDirectionCombinedLocal.Equals(new Vector3(0, 0, 1)))
                    {
                        if (GetVal(Choice, Gaze_oval, 1) && isStart)
                        {
                            trigger = true;
                            ring_up();
                        }
                        else if (trigger)
                        {
                            if (dis_out.Count > 0 && dis_out[dis_out.Count - 1].y > 0)
                            {
                                string str = GetChoice(Choice);
                                if (!selection.Equals(str))
                                {
                                    if (area >= 0)
                                    {
                                        if (area_bf >= 0)
                                        {
                                            ren[area_bf % 12].material = bf;
                                        }
                                        bf = ren[area % 12].material;
                                        ren[area % 12].material = s;
                                    }
                                    area_bf   = area;
                                    selection = str;
                                }
                            }
                            ring_up();
                        }
                        if (GetVal(Choice, Gaze_oval, 0))
                        {
                            if (trigger && isStart)
                            {
                                trigger = false;
                                info.GetComponent <TextMesh>().text = "You have selected\n         " + selection;
                                if ((selection != hint.GetComponent <TextMesh>().text) && rec)
                                {
                                    mis++;
                                }
                                dis_in.Clear();
                                dis_out.Clear();
                            }
                            ring_down();
                        }
                    }
                    else
                    {
                        dis_in.Clear();
                        dis_out.Clear();
                    }
                    time_recorder += Time.fixedDeltaTime;
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        info.GetComponent <TextMesh>().text = "";
                        hint.GetComponent <TextMesh>().text = nextCount();
                    }
                    if (rec && isStart)
                    {
                        StreamWriter writer = new StreamWriter(new FileStream("rec\\" + filepath, FileMode.Append));
                        writer.WriteLine(mark + " " + time_recorder + " " + randomInt[(count - 1) % 12] + " " + GazeDirectionCombinedLocal.x + " " + GazeDirectionCombinedLocal.y
                                         + " " + GazeDirectionCombinedLocal.z + " " + mis);
                        writer.Close();
                    }
                }
Example #2
0
                private void FixedUpdate()
                {
                    // counter
                    if (dwellCounter > 0)
                    {
                        dwellCounter--;
                        if (dwellCounter == DWELL_PROGRESS_COUNTER)
                        {
                            progressbarBg.SetActive(true);
                            progressbarFg.SetActive(true);
                            Debug.Log("yyy " + progressbarBg.activeSelf);
                        }
                        if (dwellCounter < DWELL_PROGRESS_COUNTER)
                        {
                            RenewProgressbar(1.0f * (DWELL_PROGRESS_COUNTER - dwellCounter) / DWELL_PROGRESS_COUNTER);
                        }
                        if (dwellCounter == 0)
                        {
                            progressbarBg.SetActive(false);
                            progressbarFg.SetActive(false);
                            if (state == 1)
                            {
                                // trigger menu
                                headTarget = headFocus;
                                dwellMenu.SetActive(true);
                                state = 3;
                                Log("trigger dwell");
                            }
                            else if (state == 2)
                            {
                                // gaze forward
                                if (gazeFocus.name == "Trigger 0")
                                {
                                    MoveForward();
                                    state = 0;
                                    Log("forward gaze");
                                }
                                else if (gazeFocus.name == "Trigger 1")
                                {
                                    headTarget = null;
                                    dwellMenu.SetActive(true);
                                    state = 3;
                                    Log("trigger gaze");
                                }
                            }
                            else if (state == 3)
                            {
                                // select gaze menu
                                if (gazeFocus.name == "Item 0")
                                {
                                    int res = toy.Pick(headTarget);
                                    Log("pick " + res);
                                }
                                else if (gazeFocus.name == "Item 1")
                                {
                                    int res = toy.Drop(headTarget);
                                    Log("drop " + res);
                                }
                                else if (gazeFocus.name == "Item 2")
                                {
                                    int res = MoveForward();
                                    Log("move " + res);
                                }
                                else if (gazeFocus.name == "Item 3")
                                {
                                    Log("exit");
                                }
                                dwellMenu.SetActive(false);
                                state = 0;
                            }
                        }
                    }
                    if (infoCounter > 0)
                    {
                        infoCounter--;
                        if (infoCounter == 0)
                        {
                            info.SetActive(false);
                        }
                    }

                    // get gaze
                    initialMenu();
                    border = Oval.Border;
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                    {
                        return;
                    }
                    Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal;

                    if (SRanipal_Eye.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else
                    {
                    };
                    Vector3 GazeDirectionCombined = Camera.main.transform.TransformDirection(GazeDirectionCombinedLocal);

                    GazeRayRenderer.SetPosition(0, Camera.main.transform.position - Camera.main.transform.up * 0.05f);
                    GazeRayRenderer.SetPosition(1, Camera.main.transform.position + GazeDirectionCombined * LengthOfRay);
                    Log("gaze " + GazeDirectionCombined.x + " " + GazeDirectionCombined.y + " " + GazeDirectionCombined.z);

                    // gaze dock
                    if (technique == Technique.GazeDock)
                    {
                        Vector3 Gaze_oval = GazeDirectionCombinedLocal - new Vector3(Oval.X0, Oval.Y0, 0);
                        Vector2 Choice    = new Vector2(Gaze_oval.x, Gaze_oval.y);

                        // (0,0,1) is blink
                        if (!GazeDirectionCombinedLocal.Equals(new Vector3(0, 0, 1)))
                        {
                            //in
                            if (GetVal(Choice, Gaze_oval, 1) && isStart)
                            {
                                trigger = true;
                                ring_up();
                                Log("ringup");
                            }
                            else if (trigger)
                            {
                                // highlight
                                if (dis_out.Count > 0 && dis_out[dis_out.Count - 1].y > 0)
                                {
                                    string str = GetChoice(Choice);
                                    if (!selection.Equals(str))
                                    {
                                        if (area >= 0)
                                        {
                                            if (area_bf >= 0)
                                            {
                                                ren[area_bf % 4].material = bf;
                                            }
                                            bf = ren[area % 4].material;
                                            ren[area % 4].material = s;
                                        }
                                        area_bf   = area;
                                        selection = str;
                                    }
                                }
                                ring_up();
                            }
                            // out
                            if (GetVal(Choice, Gaze_oval, 0))
                            {
                                if (trigger && isStart)
                                {
                                    trigger = false;
                                    //RaiseInfo(selection);
                                    if (selection == "↑")
                                    {
                                        int res = MoveForward();
                                        Log("move " + res);
                                    }
                                    else if (selection == "Pick")
                                    {
                                        int res = toy.Pick(headFocus);
                                        Log("pick " + res);
                                    }
                                    else if (selection == "Drop")
                                    {
                                        int res = toy.Drop(headFocus);
                                        Log("drop " + res);
                                    }
                                    dis_in.Clear();
                                    Log("ringdown");
                                }
                                ring_down();
                            }
                        }
                        else
                        {
                            dis_in.Clear();
                            dis_out.Clear();
                        }
                        time_recorder += Time.fixedDeltaTime;
                    }

                    // dwell
                    if (technique == Technique.Dwell)
                    {
                        ring_down();
                        RaycastHit hit;
                        if (Physics.Raycast(new Ray(Camera.main.transform.position - Camera.main.transform.up * 0.05f + GazeDirectionCombined * PENETRATE_GAZEDOCK, GazeDirectionCombined), out hit))
                        {
                            GameObject g = hit.collider.gameObject;
                            if (g.name != gazeNameLast)
                            {
                                progressbarBg.SetActive(false);
                                progressbarFg.SetActive(false);
                                if (gazeFocus != null && gazeFocus.name.Substring(0, 4) == "Item")
                                {
                                    gazeFocus.GetComponent <Renderer>().material.color = Color.red;
                                }
                                if (g.name.Substring(0, 4) == "Item")
                                {
                                    g.GetComponent <Renderer>().material.color = Color.yellow;
                                    dwellCounter = DWELL_START_COUNTER;
                                    gazeFocus    = g;
                                    Log("dwell start item");
                                }
                                else if (g.name.Substring(0, 4) == "Trig")
                                {
                                    if (technique == Technique.Dwell)
                                    {
                                        if (state == 0)
                                        {
                                            state        = 2;
                                            dwellCounter = DWELL_START_COUNTER;
                                            Log("dwell start gaze");
                                        }
                                    }
                                    gazeFocus = g;
                                }
                                else
                                {
                                    if (state == 2)
                                    {
                                        state        = 0;
                                        dwellCounter = 0;
                                        Log("dwell quit gaze");
                                    }
                                    if (state == 3)
                                    {
                                        dwellCounter = 0;
                                        Log("dwell quit item");
                                    }
                                }
                            }
                            gazeNameLast = g.name;
                        }
                        else
                        {
                            progressbarBg.SetActive(false);
                            progressbarFg.SetActive(false);
                            gazeNameLast = "";
                            if (state == 2)
                            {
                                state        = 0;
                                dwellCounter = 0;
                                Log("dwell quit gaze");
                            }
                            if (state == 3)
                            {
                                dwellCounter = 0;
                                Log("dwell quit item");
                            }
                        }
                    }


                    if (Input.GetKey(KeyCode.W))
                    {
                        Vector3 vc = mainCamera.transform.forward;
                        vc.y = 0;
                        GameObject.Find("Movable").transform.Translate(vc / vc.magnitude * 0.1f);
                    }
                    if (Input.GetKey(KeyCode.S))
                    {
                        Vector3 vc = mainCamera.transform.forward;
                        vc.y = 0;
                        GameObject.Find("Movable").transform.Translate(vc / vc.magnitude * -0.1f);
                    }
                }