Пример #1
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
        //var point = rays.left.GetPoint(1.0f);
        //indicator.transform.position = point;
        RaycastHit hit;

        Physics.Raycast(rays.right, out hit, Mathf.Infinity);
        var vector1 = hit.point - node1.transform.position;
        var vector2 = node2.transform.position - node1.transform.position;
        var angle1  = Vector3.Angle(vector1, vector2);

        var vector3 = hit.point - node2.transform.position;
        var vector4 = node1.transform.position - node2.transform.position;
        var angle2  = Vector3.Angle(vector3, vector4);

        //Debug.LogFormat("angle 1: {0}, angle 2: {1}", angle1, angle2);
        highlight(angle1, angle2);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            cleanTargetsOnMenu();
            //further selection
            displayTargetsOnMenu();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            //clear all targets on menu
            TargetsController.selectedList.Clear();
        }
    }
Пример #2
0
    void Update()
    {
        FoveInterface.EyeRays             rays = fove.GetGazeRays();
        FoveInterface.GazeConvergenceData gcr  = FoveInterface.GetGazeConvergence();
        //FoveInterface.CheckEyesClosed();
        Debug.Log(gcr.accuracy);
        RaycastHit hit;

        if (Physics.Raycast(rays.left, out hit, 25))
        {
            //hit.transform.GetComponent<timerScript>().startCounting();
            if (hit.point != Vector3.zero) // Vector3 is non-nullable; comparing to null is always false
            {
                // Debug.Log(hit.point);
                transform.position = hit.point;
                x   = hit.transform.tag;
                vec = hit.point;
            }
        }

        if (x == "Player")
        {
            if (Vector3.Distance(prev, vec) > 0.9 || prev == Vector3.zero)
            {
                prev = vec;
                if (c < count)
                {
                    pcount         = c;
                    positions[c++] = new Vector4(vec.x, vec.y, vec.z, 0);
                    Debug.Log(c + ":" + count);
                }
                else
                {
                    if (c >= count)
                    {
                        Debug.Log("this is end");
                        c = 0;
                    }
                }
            }
            else
            {
                if (properties[pcount].y < 1.0)
                {
                    properties[pcount] += new Vector4(0, 0.005f, 0, 0);
                }
            }
        }

        for (int i = 0; i < positions.Length; i++)
        {
            positions[i] += new Vector4(UnityEngine.Random.Range(-0.1f, +0.1f), UnityEngine.Random.Range(-0.1f, +0.1f), 0, 0) * Time.deltaTime;
        }

        material.SetInt("_Points_Length", count);
        material.SetVectorArray("_Points", positions);
        material.SetVectorArray("_Properties", properties);
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                transform.position = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);
            }
            else
            {
                transform.position = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2);
            }

            /*Debug.Log("NotWink");
             * Debug.Log("Right:" + eyes.right);
             * Debug.Log("Hit_R:" + hitRight.point);
             * Debug.Log("Left:" + eyes.left);
             * Debug.Log("Hit_L" + hitLeft.point);*/
            break;

        case Fove.EFVR_Eye.Left:

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitRight.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                transform.position = hitRight.point;
            }
            else
            {
                transform.position = eyes.right.GetPoint(3.0f);
            }
            break;

        case Fove.EFVR_Eye.Right:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                transform.position = hitLeft.point;
            }
            else
            {
                transform.position = eyes.left.GetPoint(3.0f);
            }
            break;
        }
    }
    void drawLeftEyeRay()
    {
        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
        var origin = rays.left.origin;
        var merge  = rays.left.GetPoint(10f);

        Debug.Log(origin.x);
        Debug.Log(merge.x);

        lineRenderer.numCapVertices = 2;
        lineRenderer.SetPosition(0, origin);
        lineRenderer.SetPosition(1, merge);
    }
    // Latepdate ensures that the object doesn't lag behind the user's head motion
    void Update()
    {
        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
        Ray r = rays.left;

        RaycastHit   hit;
        MeshCollider coll = videoSphere.GetComponent <MeshCollider>();

        if (coll != null && coll.Raycast(r, out hit, Mathf.Infinity))
        {
            transform.position = hit.point;
        }
    }
    // Update is called once per frame
    private void UpdatePositionBasedOnEyes()
    {
        // this is from here.. maybe better robustness against lost tracking: https://github.com/twday/Fove-Unity-Examples/blob/master/Assets/Examples/FoveCursor/Scripts/FoveCursor.cs

        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                transform.position = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);
            }
            else
            {
                transform.position = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2);
            }

            break;

        case Fove.EFVR_Eye.Left:

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitRight.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                transform.position = hitRight.point;
            }
            else
            {
                transform.position = eyes.right.GetPoint(3.0f);
            }
            break;

        case Fove.EFVR_Eye.Right:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                transform.position = hitLeft.point;
            }
            else
            {
                transform.position = eyes.left.GetPoint(3.0f);
            }
            break;
        }
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        //時間関連データの取得
        nt = DateTime.Now;     //ここに到達したときの時刻を取得する
        TimeSpan ts = nt - st; //実行からどれくらい経過しているのかを計算

        //fpsの計算
        ++frameCount;
        float time = Time.realtimeSinceStartup - prevTime;

        if (time >= 0.5f)
        {
            fpstime = frameCount / time;
            //Debug.LogFormat("{0}fps", fpstime);
            frameCount = 0;
            prevTime   = Time.realtimeSinceStartup;
        }

        //目のデータの取得
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();

        //HMD関連のデータの取得
        hmdpos = FoveInterface.GetHMDPosition(); //HMDの位置座標
        hmdrot = FoveInterface.GetHMDRotation(); //HMDの方向座標
        //Debug.Log(hmdpos.x + "," + hmdpos.y + "," + hmdpos.z + "," + hmdrot.x + "," + hmdrot.y + "," + hmdrot.z + "," + hmdrot.w);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            tf = 1;
        }

        if (tf == 1)//csvへの書き込み
        {
            //CSVに記録する情報
            //現在時刻,現在時刻のミリ秒,経過時間,経過時間のミリ秒,fps,チェッカールームの回転速度,眼球の座標(左),眼球の座標(右),視線のベクトル(左),視線のベクトル(右),HMDの座標,HMDの向き
            streamWriter.Write(nt.ToString() + ',' + nt.Millisecond.ToString() + ',' + ts.ToString() + ',' + nt.Millisecond.ToString() + ','
                               + eyes.right.origin.x.ToString() + ',' + eyes.right.origin.y.ToString() + ',' + eyes.right.origin.z.ToString() + ','
                               + eyes.left.origin.x.ToString() + ',' + eyes.left.origin.y.ToString() + ',' + eyes.left.origin.z.ToString() + ','
                               + hmdpos.x.ToString() + ',' + hmdpos.y.ToString() + ',' + hmdpos.z.ToString() + ','
                               + hmdrot.x.ToString() + ',' + hmdrot.y.ToString() + ',' + hmdrot.z.ToString() + ',' + hmdrot.w.ToString()); //csvに書き込むデータのリスト
            streamWriter.WriteLine();                                                                                                      //データの取得
            Debug.Log("書き込み中");
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            streamWriter.Close();//csvに書き込む
            Debug.Log("書き込み終了");
        }
    }
Пример #8
0
    void Update()
    {
        if (Input.GetKeyDown(VisualizeEyesKey))
        {
            VisualizeEyes = !VisualizeEyes;
        }
        if (Input.GetKeyDown(VisualizeMidpointKey))
        {
            VisualizeMidPoint = !VisualizeMidPoint;
        }

        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();

        // LEFT
        Ray     rayLeft       = rays.left;
        Vector3 leftOrigin    = rayLeft.origin;
        Vector3 leftDirection = rayLeft.direction;
        Vector3 leftWorldPos  = leftOrigin + (DistanceOriginWorldPoint * leftDirection);

        // RIGHT
        Ray     rayRight       = rays.right;
        Vector3 rightOrigin    = rayRight.origin;
        Vector3 rightDirection = rayRight.direction;
        Vector3 rightWorldPos  = rightOrigin + (DistanceOriginWorldPoint * rightDirection);

        if (VisualizeEyes)
        {
            LeftPointer.transform.position  = leftWorldPos;
            RightPointer.transform.position = rightWorldPos;
        }

        // MIDPOINT
        Vector3 midpoint = (rightWorldPos + leftWorldPos) / 2;

        if (VisualizeMidPoint)
        {
            MidpointPointer.transform.position = midpoint;
        }

        var tempObj = GetFocussedHighlightPiece(midpoint);

        if (tempObj != null)
        {
            if (highlightedObject != tempObj)
            {
                highlightedObject = tempObj;
                GazeHighLighter.SetProceduralBox(highlightedObject);
            }
        }
    }
Пример #9
0
    // Latepdate ensures that the object doesn't lag behind the user's head motion
    void Update()
    {
        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();

        // TODO: calculate the convergence point in FoveInterface

        // Just hack in to use the left eye for now...
        RaycastHit hit;

        Physics.Raycast(rays.left, out hit, Mathf.Infinity);
        if (hit.point != Vector3.zero) // Vector3 is non-nullable; comparing to null is always false
        {
            transform.position = hit.point;
        }
        else
        {
            transform.position = rays.left.GetPoint(3.0f);
        }
    }
Пример #10
0
    void FixedUpdate()
    {
        if (!recordingTrackingData)
        {
            return;
        }

        var vp = videoSphere.GetComponent <VideoPlayer>();

        if (vp.isPlaying)
        {
            nextRecord = Time.time + recordRate;

            var quaternion = FoveInterface.GetHMDRotation();
            var euler      = quaternion.eulerAngles;

            //var leftEyeVector = FoveInterface.GetLeftEyeVector();
            //var rightEyeVector = FoveInterface.GetRightEyeVector();

            //var leftRay = new Ray(foveInterface.GetEyeCamera(Fove.EFVR_Eye.Left).transform.position, leftEyeVector);
            //var rightRay = new Ray(foveInterface.GetEyeCamera(Fove.EFVR_Eye.Right).transform.position, rightEyeVector);

            FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
            var leftRay  = rays.left;
            var rightRay = rays.right;


            //Debug.DrawRay(leftRay.origin, leftRay.direction, Color.green, 2, false);
            //Debug.DrawRay(rightRay.origin, rightRay.direction, Color.blue, 2, false);

            Vector2 pixeluvLeft  = GetPixelTextureCoords(leftRay);
            Vector2 pixeluvRight = GetPixelTextureCoords(rightRay);

            string[] data = new string[] { vp.time.ToString(), euler.x.ToString(), euler.y.ToString(), euler.z.ToString(), quaternion.x.ToString(), quaternion.y.ToString(), quaternion.z.ToString(), quaternion.w.ToString(),
                     leftRay.direction.x.ToString(), leftRay.direction.y.ToString(), leftRay.direction.z.ToString(), rightRay.direction.x.ToString(), rightRay.direction.y.ToString(), rightRay.direction.z.ToString(),
                     pixeluvLeft.x.ToString(), pixeluvLeft.y.ToString(), pixeluvRight.x.ToString(), pixeluvRight.y.ToString(), insideTargetAreaChecker.InsideTargetArea().ToString() };

            orientationStringWriter.Write(string.Join(delimiter, data) + "\n");
        }
    }
    /// <summary>
    /// Sets the _rayOrigin variable based on the used VRHMD.
    /// </summary>
    private void FindGazeOrigin()
    {
        switch (TestController.Instance.TestBlockData.SelectedVRHMD)
        {
        case TestBlock.VRHMD.VIVE:
            _rayOrigin = transform.position;
            break;

        case TestBlock.VRHMD.FOVE:
            if (CurrentControlMethod == TestBlock.ControlMethod.Eyetracking)
            {
                FoveInterface.EyeRays rays = _foveInterface.GetGazeRays();
                EFVR_Eye eyeClosed         = FoveInterface.CheckEyesClosed();
                switch (eyeClosed)
                {
                case (EFVR_Eye.Neither):
                    _rayOrigin = (rays.left.origin + rays.right.origin) * 0.5f;
                    break;

                case (EFVR_Eye.Left):
                    _rayOrigin = rays.right.origin;
                    break;

                case (EFVR_Eye.Right):
                    _rayOrigin = rays.left.origin;
                    break;

                case (EFVR_Eye.Both):
                    _rayOrigin = Vector3.zero;
                    break;
                }
            }
            else if (CurrentControlMethod == TestBlock.ControlMethod.Headtracking)
            {
                _rayOrigin = transform.position;
            }
            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            transform.position = eyes.left.GetPoint(this.distanceFromEye) + ((eyes.right.GetPoint(this.distanceFromEye) - eyes.left.GetPoint(this.distanceFromEye)) / 2);
            break;

        case Fove.EFVR_Eye.Left:

            transform.position = eyes.right.GetPoint(this.distanceFromEye);
            break;

        case Fove.EFVR_Eye.Right:

            transform.position = eyes.left.GetPoint(this.distanceFromEye);
            break;
        }
    }
Пример #13
0
    void getConvergence()
    {
        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
        var leftOrigin             = rays.left.origin;
        var rightOrigin            = rays.right.origin;
        var leftPoint  = rays.left.GetPoint(0.1f);
        var rightPoint = rays.right.GetPoint(0.1f);

        var dist1 = Vector3.Distance(leftPoint, rightPoint);
        var dist2 = Vector3.Distance(leftOrigin, rightOrigin);

        var distance = (float)0.1 * dist2 / (dist2 - dist1);  // dist between convergence and origin

        if (distance > 3.5f)
        {
            distance = 3.5f;
        }

        //transform.position = rays.left.GetPoint(distance);
        MoveTowardsTarget(rays.left.GetPoint(distance));
        transform.localScale = new Vector3(defaultSize * distance / 5, defaultSize * distance / 5, defaultSize * distance / 5);
    }
Пример #14
0
    void Update()
    {
        // get gaze
        FoveInterface.EyeRays eyeRays = f.GetGazeRays();
        Ray left  = eyeRays.left;
        Ray right = eyeRays.right;

        leftEyeSphere.transform.position  = left.origin + left.direction.normalized * 2.0f;
        rightEyeSphere.transform.position = right.origin + right.direction.normalized * 2.0f;

        // get angles and rotation of left, right, head
        Vector2    leftAngles    = GetAngles(left.direction, f.transform.forward, f.transform.up);
        Vector2    rightAngles   = GetAngles(right.direction, f.transform.forward, f.transform.up);
        Vector3    headAngles    = GetAngles(f.transform.forward, Vector3.forward, Vector3.up);
        Quaternion leftRotation  = Quaternion.FromToRotation(left.direction, f.transform.forward);
        Quaternion rightRotation = Quaternion.FromToRotation(right.direction, f.transform.forward);
        Quaternion headRotation  = f.transform.rotation;

        // move
        if (Input.GetKey(KeyCode.W))
        {
            MoveFoveCamera(f.transform.rotation * Vector3.forward);
        }
        if (Input.GetKey(KeyCode.S))
        {
            MoveFoveCamera(f.transform.rotation * -Vector3.forward);
        }
        if (Input.GetKey(KeyCode.A))
        {
            MoveFoveCamera(f.transform.rotation * -Vector3.right);
        }
        if (Input.GetKey(KeyCode.D))
        {
            MoveFoveCamera(f.transform.rotation * Vector3.right);
        }
        if (true)
        {
            float rx = Input.GetAxis("Mouse X");
            float ry = Input.GetAxis("Mouse Y");
            f.transform.parent.transform.Rotate(f.transform.localRotation * Vector3.up, rx * ROTATE_SPEED, Space.World);
            f.transform.parent.transform.Rotate(f.transform.localRotation * Vector3.left, ry * ROTATE_SPEED, Space.World);
        }

        // enable calibration
        if (Input.GetKeyDown(KeyCode.Space))
        {
            calibrationSphere.SetActive(true);
        }

        // record the data
        if (Input.GetKeyDown(KeyCode.F))
        {
            if (recording)
            {
                recorder.Close();
                recordingLight.GetComponent <Renderer>().material.color = Color.white;
                recording = false;
            }
            else
            {
                recorder = new StreamWriter(new FileStream("record.txt", FileMode.OpenOrCreate));
                recordingLight.GetComponent <Renderer>().material.color = Color.red;
                recording = true;
            }
        }
        DateTime now = DateTime.Now;

        if (recording && (now - lastRecordTime).TotalMilliseconds > 100)
        {
            Record(recorder, "left", leftAngles, leftRotation);
            Record(recorder, "right", rightAngles, rightRotation);
            Record(recorder, "head", headAngles, headRotation);
            lastRecordTime = now;
        }

        // render calibration point
        if (calibrationSphere.activeSelf)
        {
            /*RaycastHit hit;
             * Ray ray = new Ray(f.transform.position, f.transform.forward);
             * if (Physics.Raycast(ray, out hit, 10.0f) && false) {
             *  calibSphere.transform.position = hit.point;
             * }*/
            calibrationSphere.transform.position = f.transform.position + f.transform.forward * 3.0f;
        }

        // calibrate
        if (Input.GetKeyUp(KeyCode.Space))
        {
            calibrationSphere.SetActive(false);
            f.ManualDriftCorrection3D(calibrationSphere.transform.localPosition);
        }
    }
    /// <summary>
    /// Update cursor position on screen based on the eye gaze ray from VRHMD (if using eyetracking as control method).
    /// This function is also called if RecordGazePosition is true, in which case the ray is still handled but the cursor position is not updated.
    /// This is in case we want to record gaze position regardless of using eyetracking as control method.
    /// </summary>
    private void TrackEyes()
    {
        List <Vector3> eyeDirections = new List <Vector3>();

        switch (TestController.Instance.TestBlockData.SelectedVRHMD)
        {
        case TestBlock.VRHMD.VIVE:
            Vector3 gaze = Pupil.values.GazePoint3D;
            //Transform and correct eye-tracking
            gaze = (transform.rotation * gaze).normalized;
            Vector3 delta = transform.forward.normalized - gaze;
            gaze = gaze + delta * 2;
            //float eyeConfidence = (Pupil.values.Confidences[0] + Pupil.values.Confidences[1]) / 2.0f;
            //if (eyeConfidence > 0.7f)
            //{
            eyeDirections.Add(gaze);
            //}
            break;

        case TestBlock.VRHMD.FOVE:
            FoveInterface.EyeRays rays = _foveInterface.GetGazeRays();
            EFVR_Eye eyeClosed         = FoveInterface.CheckEyesClosed();
            switch (eyeClosed)
            {
            case (EFVR_Eye.Neither):
                eyeDirections.Add(rays.left.direction);
                eyeDirections.Add(rays.right.direction);
                break;

            case (EFVR_Eye.Left):
                eyeDirections.Add(rays.right.direction);
                break;

            case (EFVR_Eye.Right):
                eyeDirections.Add(rays.left.direction);
                break;

            case (EFVR_Eye.Both):
                eyeDirections.Add(Vector3.zero);
                break;
            }
            break;
        }

        Vector3 direction = Vector3.zero;

        foreach (Vector3 eyeDirection in eyeDirections)
        {
            direction += eyeDirection;
        }
        direction = direction / eyeDirections.Count;
        Ray ray = new Ray(_rayOrigin, direction);

        ray = GetAverageEyeRay(ray);
        CurrentEyeGazeScreenPoint = VRCamera.WorldToScreenPoint(_rayOrigin + ray.direction * POINT_CALCULATION_DISTANCE);
        if (CurrentControlMethod == TestBlock.ControlMethod.Eyetracking)
        {
            HandleRay(ray);
        }
        else
        {
            HandleGazeTrackingRay(ray);
        }
        Debug.DrawRay(ray.origin, ray.direction * 100);
    }
Пример #16
0
    // Update is called once per frame
    void Update()
    {
        //fpsの計算
        ++frameCount;
        float time = Time.realtimeSinceStartup - prevTime;

        if (time >= 0.5f)
        {
            fpstime = frameCount / time;
            //Debug.LogFormat("{0}fps", fpstime);
            frameCount = 0;
            prevTime   = Time.realtimeSinceStartup;
        }

        //目のデータの取得
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        //視点の計算
        RaycastHit hitLeft, hitRight;

        Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
        Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
        originhit = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);//視点座標を代入

        //HMD関連のデータの取得
        hmdpos = FoveInterface.GetHMDPosition(); //HMDの位置座標
        hmdrot = FoveInterface.GetHMDRotation(); //HMDの方向座標
        //Debug.Log(hmdpos.x + "," + hmdpos.y + "," + hmdpos.z + "," + hmdrot.x + "," + hmdrot.y + "," + hmdrot.z + "," + hmdrot.w);


        if (Input.GetKeyDown(KeyCode.Space))
        {
            spintim   = 1;
            n         = 90.0f;
            spinstart = DateTime.Now;//実行を始めた時刻
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            vectionfeel = 1;
            //n = 90.0f;
        }

        if (spintim == 1)                 //checkerroomの回転、csvへの書き込み
        {
            nt = DateTime.Now;            //ここに到達したときの時刻を取得する
            TimeSpan ts = nt - spinstart; //実行からどれくらい経過しているのかを計算

            //経過時刻と角速度に合わせてチェッカールームを傾ける
            //フレーム当たりの角速度を
            spinangle  = ts.Milliseconds * n / 1000.0f;
            spinangle += ts.Seconds * n;
            spinangle += ts.Minutes * n;
            //spinangle += 0.9f;//Unityは60fpsというのを前提
            transform.localRotation = Quaternion.Euler(0.0f, spinangle, 0.0f);

            //CSVに記録する情報
            //現在時刻,現在時刻のミリ秒,経過時間,経過時間のミリ秒,fps,チェッカールームの回転速度,眼球の座標(左),眼球の座標(右),視線のベクトル(左),視線のベクトル(右),視点の座標,HMDの座標,HMDの向き,ベクション
            streamWriter.Write(nt.ToString() + ',' + nt.Millisecond.ToString() + ',' + ts.ToString() + ',' + nt.Millisecond.ToString() + ','
                               + fpstime.ToString() + ','                                                                                                                                           //fps
                               + n.ToString() + ','                                                                                                                                                 //チェッカールームの回転速度
                               + eyes.left.origin.x.ToString() + ',' + eyes.left.origin.y.ToString() + ',' + eyes.left.origin.z.ToString() + ','                                                    //左目の座標
                               + eyes.right.origin.x.ToString() + ',' + eyes.right.origin.y.ToString() + ',' + eyes.right.origin.z.ToString() + ','                                                 //右目の座標
                               + FoveInterface.GetLeftEyeVector().x.ToString() + ',' + FoveInterface.GetLeftEyeVector().y.ToString() + ',' + FoveInterface.GetLeftEyeVector().z.ToString() + ','    //左目ベクトル
                               + FoveInterface.GetRightEyeVector().x.ToString() + ',' + FoveInterface.GetRightEyeVector().y.ToString() + ',' + FoveInterface.GetRightEyeVector().z.ToString() + ',' //右目ベクトル
                               + originhit.x.ToString() + ',' + originhit.y.ToString() + ',' + originhit.z.ToString() + ','                                                                         //視点の座標
                               + hmdpos.x.ToString() + ',' + hmdpos.y.ToString() + ',' + hmdpos.z.ToString() + ','                                                                                  //HMDの座標
                               + hmdrot.x.ToString() + ',' + hmdrot.y.ToString() + ',' + hmdrot.z.ToString() + ',' + hmdrot.w.ToString() + ','                                                      //HMDの向き
                               + vectionfeel.ToString());                                                                                                                                           //ベクション
            //csvに書き込むデータのリスト
            streamWriter.WriteLine();                                                                                                                                                               //改行
            Debug.Log("書き込み中");

            //データ確認用
            //Debug.Log(spinstart);//回転開始時
            //Debug.Log(nt);//現在時刻
            //Debug.Log(ts);//経過時間
            //Debug.Log(ts.Milliseconds);//経過時間(ミリ秒)
            //Debug.Log(spinangle);//移動角
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            spintim = 0;
            streamWriter.Close();//csvに書き込む
            //Debug.Log("書き込み終了");
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            n = 180.0f;
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            n = 60.0f;
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            n = 90.0f;
        }
    }
Пример #17
0
    void Update()
    {
        if (Input.GetKeyDown(VisualizeEyesKey))
        {
            VisualizeEyes = !VisualizeEyes;
        }
        if (Input.GetKeyDown(VisualizeMidpointKey))
        {
            VisualizeMidPoint = !VisualizeMidPoint;
            print("midpoint");
        }

        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();

        // LEFT
        Ray     rayLeft       = rays.left;
        Vector3 leftOrigin    = rayLeft.origin;
        Vector3 leftDirection = rayLeft.direction;
        Vector3 leftWorldPos  = leftOrigin + (DistanceOriginWorldPoint * leftDirection);

        // RIGHT
        Ray     rayRight       = rays.right;
        Vector3 rightOrigin    = rayRight.origin;
        Vector3 rightDirection = rayRight.direction;
        Vector3 rightWorldPos  = rightOrigin + (DistanceOriginWorldPoint * rightDirection);

        if (VisualizeEyes)
        {
            LeftPointer.transform.position  = leftWorldPos;
            RightPointer.transform.position = rightWorldPos;
        }

        // MIDPOINT
        Vector3 midpoint  = (rightWorldPos + leftWorldPos) / 2;
        Vector3 midOrigin = (rightOrigin + leftOrigin) / 2;
        // print midOrigin;

        Vector3 midDirection = (rightDirection + leftDirection) / 2;

        rayMid = new Ray(midOrigin, midDirection);


        if (VisualizeMidPoint)
        {
            MidpointPointer.transform.position = midpoint;
        }

        var tempObj = GetFocussedHighlightPiece(midpoint);

        if (tempObj != null)
        {
            if (highlightedObject != tempObj)
            {
                highlightedObject = tempObj;
                GazeHighLighter.SetProceduralBox(highlightedObject);
            }
        }

        //GRAB
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //print("DOWN" + grabbedObject);
            if (grabbedObject == null)
            {
                TryGrabObject(GetMouseHoverObject(50));
            }

            switch (grabbedObject.name)
            {
            case "Scissors":
                hasScissors = true;
                break;

            case "Key":
                hasKey = true;
                break;

            case "Wrench":
                hasWrench = true;
                break;
            }
            print("GRAB " + (grabbedObject != null));
        }
        if (Input.GetKeyUp(KeyCode.Space))
        {
            //    DropObject();
        }

        if (grabbedObject != null)

        {
            //    //Vector3 newPosition = charCam.ScreenToWorldPoint(Input.mousePosition) + charCam.transform.forward * (grabbedObjectSize + camDistance);
            //    Vector3 newPosition = midpoint;
            //    //Vector3 newPosition = eyeSight.transform.position;
            //    grabbedObject.transform.position = newPosition;
            //    print(newPosition);
        }
    }
Пример #18
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                eyepos = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);
                //eyepos = eyepos / displaysize;
                eyepos.x = eyepos.x / displaysize.x;
                eyepos.y = eyepos.y / displaysize.y;
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            else
            {
                eyepos = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2);;
                //eyepos = eyepos / displaysize;
                eyepos.x = eyepos.x / displaysize.x;
                eyepos.y = eyepos.y / displaysize.y;
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }

            break;

        case Fove.EFVR_Eye.Left:

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitRight.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                eyepos = hitRight.point;
                //eyepos = eyepos / displaysize;
                eyepos.x = eyepos.x / displaysize.x;
                eyepos.y = eyepos.y / displaysize.y;
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            else
            {
                eyepos = eyes.right.GetPoint(3.0f);
                //eyepos = eyepos / displaysize;
                eyepos.x = eyepos.x / displaysize.x;
                eyepos.y = eyepos.y / displaysize.y;
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            break;

        case Fove.EFVR_Eye.Right:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                eyepos = hitLeft.point;
                //eyepos = eyepos / displaysize;
                eyepos.x = eyepos.x / displaysize.x;
                eyepos.y = eyepos.y / displaysize.y;
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            else
            {
                eyepos = eyes.left.GetPoint(3.0f);
                //eyepos = eyepos / displaysize;
                eyepos.x = eyepos.x / displaysize.x;
                eyepos.y = eyepos.y / displaysize.y;
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            break;
        }
    }
Пример #19
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                //origineye = (eyes.left.origin + eyes.right.origin) / 2;//眼球の中間の座標を求める
                //originvector = (FoveInterface.GetLeftEyeVector() + FoveInterface.GetRightEyeVector()) / 2;//両目のベクトルの平均を求める
                //origineye = eyes.right.origin;//右目の座標を求める
                //originvector = FoveInterface.GetRightEyeVector();//右目のベクトルの平均を求める
                //tunneringpos = root10 * originvector - origineye;//眼球の座標と大きさ10のベクトルでトンネリングの座標を求める



                tunneringpos = ((eyes.left.origin + FoveInterface.GetLeftEyeVector() * 10.0f) + (eyes.right.origin + FoveInterface.GetRightEyeVector() * 10.0f)) / 2;
                //tunneringpos = eyes.right.origin + FoveInterface.GetRightEyeVector() * 10.0f;
                transform.position =  tunneringpos;   //トンネリングを移動

                //kyori = tunneringpos.x * tunneringpos.x + tunneringpos.y * tunneringpos.y + tunneringpos.z * tunneringpos.z;

                /*Debug.Log(origineye.ToString());
                 * Debug.Log(originvector.ToString());
                 * Debug.Log(tunneringpos.ToString());*/
                //Debug.Log(tunneringpos.x.ToString() + ":" + tunneringpos.y.ToString() + ":" + tunneringpos.z.ToString() + ":" + kyori.ToString());
            }
            else
            {
                originhit          = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2); //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z;       //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            break;

        case Fove.EFVR_Eye.Left:

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitRight.point != Vector3.zero)                         // Vector3 is non-nullable; comparing to null is always false
            {
                origineye          = eyes.right.origin;                 //右目の座標を求める
                originvector       = FoveInterface.GetRightEyeVector(); //右目のベクトルの平均を求める
                tunneringpos       = root10 * originvector - origineye; //眼球の座標と大きさ10のベクトルでトンネリングの座標を求める
                transform.position = tunneringpos;                      //トンネリングを移動

                //kyori = tunneringpos.x * tunneringpos.x + tunneringpos.y * tunneringpos.y + tunneringpos.z * tunneringpos.z;
                //Debug.Log(tunneringpos.x.ToString() + ":" + tunneringpos.y.ToString() + ":" + tunneringpos.z.ToString() + ":" + kyori.ToString());
            }
            else
            {
                originhit          = eyes.right.GetPoint(3.0f);                                                         //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z; //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            break;

        case Fove.EFVR_Eye.Right:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero)                          // Vector3 is non-nullable; comparing to null is always false
            {
                origineye          = eyes.left.origin;                  //左目の座標を求める
                originvector       = FoveInterface.GetLeftEyeVector();  //左目のベクトルの平均を求める
                tunneringpos       = root10 * originvector - origineye; //眼球の座標と大きさ10のベクトルでトンネリングの座標を求める
                transform.position = tunneringpos;                      //トンネリングを移動

                //kyori = tunneringpos.x * tunneringpos.x + tunneringpos.y * tunneringpos.y + tunneringpos.z * tunneringpos.z;
                //Debug.Log(tunneringpos.x.ToString() + ":" + tunneringpos.y.ToString() + ":" + tunneringpos.z.ToString() + ":" + kyori.ToString());
            }
            else
            {
                originhit          = eyes.left.GetPoint(3.0f);                                                          //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z; //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            break;
        }
    }
Пример #20
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                originhit = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);    //視点座標を代入
                //眼球の中心座標を求める
                //視点の座標から眼球の中心座標を引いて、眼球から視点までのベクトルを求める
                origindirection  = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z;                                                      //距離の2乗を計算
                origindirection2 = Mathf.Sqrt(origindirection);                                                                                                            //√計算
                origindirection3 = Mathf.Sqrt(origindirection2);                                                                                                           //√計算
                newtunnering     = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //長さ10のベクトルに変換
                //眼球の座標にトンネリングまでの座標を足す
                transform.position = newtunnering;                                                                                                                         //トンネリングを移動
                kyori = newtunnering.x * newtunnering.x + newtunnering.y * newtunnering.y + newtunnering.z * newtunnering.z;
                Debug.Log(kyori.ToString());
            }
            else
            {
                originhit          = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2); //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z;       //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            break;

        case Fove.EFVR_Eye.Left:

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitRight.point != Vector3.zero)                                                                         // Vector3 is non-nullable; comparing to null is always false
            {
                originhit          = hitRight.point;                                                                    //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z; //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            else
            {
                originhit          = eyes.right.GetPoint(3.0f);                                                         //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z; //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            break;

        case Fove.EFVR_Eye.Right:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero)                                                                          // Vector3 is non-nullable; comparing to null is always false
            {
                originhit          = hitLeft.point;                                                                     //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z; //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            else
            {
                originhit          = eyes.left.GetPoint(3.0f);                                                          //視点を代入
                origindirection    = originhit.x * originhit.x + originhit.y * originhit.y + originhit.z * originhit.z; //距離の2乗を計算
                origindirection2   = Mathf.Sqrt(origindirection);
                origindirection3   = Mathf.Sqrt(origindirection2);
                newtunnering       = new Vector3(originhit.x * root10 / origindirection3, originhit.y * root10 / origindirection3, originhit.z * root10 / origindirection3); //トンネリングの座標を計算して代入
                transform.position = newtunnering;                                                                                                                           //トンネリングを移動
            }
            break;
        }
    }
Пример #21
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        switch (FoveInterface.CheckEyesClosed())                       //瞬き検知
        {
        case Fove.EFVR_Eye.Neither:                                    //両目が開いているとき

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);   //左目のraycastの取得
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity); //右目のraycastの取得
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                eyerightdistance   = eyes.right.direction * root10;              //右目から見たトンネリングの座標を計算
                eyerighttunnering  = eyes.right.origin + eyerightdistance;       //右目の座標と合わせることでトンネリングの正しい位置を出す
                eyeleftdistance    = eyes.left.direction * root10;               //右目から見たトンネリングの座標を計算
                eyelefttunnering   = eyes.left.origin + eyeleftdistance;         //右目の座標と合わせることでトンネリングの正しい位置を出す
                eyetunnering       = (eyerighttunnering + eyelefttunnering) / 2; //両目のトンネリング座標から、間の座標を出す
                transform.position = eyetunnering;                               //座標に移動
                //Debug.Log(eyetunnering.x.ToString() + '+' + eyetunnering.y.ToString() + '+' + eyetunnering.z.ToString());
                //kyori = eyetunnering.x * eyetunnering.x + eyetunnering.y * eyetunnering.y + eyetunnering.z * eyetunnering.z;
                //Debug.Log(kyori.ToString());
            }
            else
            {
                transform.position = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2);
            }
            break;

        case Fove.EFVR_Eye.Left:                                       //左目が閉じているとき

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity); //右目のraycastの取得
            if (hitRight.point != Vector3.zero)
            {
                eyerightdistance   = eyes.right.direction * root10;        //右目から見たトンネリングの座標を計算
                eyerighttunnering  = eyes.right.origin + eyerightdistance; //右目の座標と合わせることでトンネリングの正しい位置を出す
                transform.position = eyerighttunnering;                    //指定座標に移動
                //Debug.Log(eyerighttunnering.x.ToString() + '+' + eyerighttunnering.y.ToString() + '+' + eyerighttunnering.z.ToString());
            }
            else
            {
                transform.position = eyes.right.GetPoint(3.0f);
            }
            break;

        case Fove.EFVR_Eye.Right:                                    //右目閉じているとき

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity); //左目のraycastの取得
            if (hitLeft.point != Vector3.zero)
            {
                eyeleftdistance    = eyes.left.direction * root10;       //右目から見たトンネリングの座標を計算
                eyelefttunnering   = eyes.left.origin + eyeleftdistance; //右目の座標と合わせることでトンネリングの正しい位置を出す
                transform.position = eyelefttunnering;                   //指定座標に移動
                //Debug.Log(eyelefttunnering.x.ToString() + '+' + eyelefttunnering.y.ToString() + '+' + eyelefttunnering.z.ToString());
            }
            else
            {
                transform.position = eyes.left.GetPoint(3.0f);
            }
            break;
        }
    }
Пример #22
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
        RaycastHit            hitL;
        RaycastHit            hitR;

        Physics.Raycast(rays.left, out hitL, Mathf.Infinity);
        Physics.Raycast(rays.left, out hitR, Mathf.Infinity);
        bool isHitL = Physics.Raycast(rays.left, out hitL, Mathf.Infinity);
        bool isHitR = Physics.Raycast(rays.right, out hitR, Mathf.Infinity);

        transform.position      = hitL.point;
        eyeR.transform.position = hitR.point;
        if (hitL.point != Vector3.zero) // Vector3 is non-nullable; comparing to null is always false
        {
            transform.position = hitL.point;
        }
        else
        {
            transform.position = rays.left.GetPoint(3.0f);
        }

        if (hitR.point != Vector3.zero) // Vector3 is non-nullable; comparing to null is always false
        {
            transform.position = hitR.point;
        }
        else
        {
            transform.position = rays.right.GetPoint(3.0f);
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            ShootableTargetLeft  healthLeft  = objectL.GetComponent <ShootableTargetLeft>();
            ShootableTargetRight healthRight = objectR.GetComponent <ShootableTargetRight>();
            if (f.transform.forward.x < 0)
            {
                startTimeL = Time.time;
                healthLeft.Damage(countTime);
                if (isHitL || isHitR)
                {
                    successRate.Add(1);
                    Debug.Log("LEFT Hit successfully");
                }
                else
                {
                    successRate.Add(0);
                    Debug.Log("Left failed");
                }
            }
            if (f.transform.forward.x > 0)
            {
                healthRight.Damage(countTime);
                startTimeR = Time.time;
                if (isHitL || isHitR)
                {
                    Debug.Log("Right Hit successfully");
                    successRate.Add(1);
                }
                else
                {
                    successRate.Add(0);
                    Debug.Log("Right failed");
                }
            }

            durationTime = System.Math.Abs(startTimeL - startTimeR);
            selectionTime.Add(durationTime);
            Debug.Log(startTimeL + "-" + startTimeR + "=" + durationTime);
        }
    }
Пример #23
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();

        for (int i = 0; i < 9; i++)
        {
            _object[i].GetComponent <Renderer>().material = _material[0];
        }
        k             = 0;
        eyevector.x   = eyevector.y = eyevector.z = 0;
        truthvector.x = truthvector.y = truthvector.z = 0;

        //デフォルトの状態のとき
        if (k == 0)
        {
            if (Input.GetKey(KeyCode.Q))
            {
                k = 1;
            }
            if (Input.GetKey(KeyCode.W))
            {
                k = 2;
            }
            if (Input.GetKey(KeyCode.E))
            {
                k = 3;
            }
            if (Input.GetKey(KeyCode.A))
            {
                k = 4;
            }
            if (Input.GetKey(KeyCode.S))
            {
                k = 5;
            }
            if (Input.GetKey(KeyCode.D))
            {
                k = 6;
            }
            if (Input.GetKey(KeyCode.Z))
            {
                k = 7;
            }
            if (Input.GetKey(KeyCode.X))
            {
                k = 8;
            }
            if (Input.GetKey(KeyCode.C))
            {
                k = 9;
            }
        }

        if (k > 0)
        {
            _object[k - 1].GetComponent <Renderer>().material = _material[1];
            //ベクトルの取得
            switch (FoveInterface.CheckEyesClosed())
            {
            case Fove.EFVR_Eye.Neither:
                eyevector   = (FoveInterface.GetLeftEyeVector() + FoveInterface.GetLeftEyeVector()) / 2;
                truthvector = _object[k - 1].GetComponent <Transform>().position - ((eyes.left.origin + eyes.right.origin) / 2);

                break;

            case Fove.EFVR_Eye.Left:
                eyevector.x   = eyevector.y = eyevector.z = 0;
                truthvector.x = truthvector.y = truthvector.z = 0;
                //eyevector = FoveInterface.GetRightEyeVector();
                //truthvector = _object[k - 1].GetComponent<Transform>().position - eyes.right.origin;


                break;

            case Fove.EFVR_Eye.Right:
                eyevector.x   = eyevector.y = eyevector.z = 0;
                truthvector.x = truthvector.y = truthvector.z = 0;
                //eyevector = FoveInterface.GetLeftEyeVector();
                //truthvector = _object[k - 1].GetComponent<Transform>().position - eyes.left.origin;

                break;
            }
            //なす角の計算
            theta = Mathf.Acos(Vector3.Dot(eyevector, truthvector) / (eyevector.magnitude * truthvector.magnitude)) * Mathf.Rad2Deg;
            Debug.Log(theta);//誤差の表示
            streamWriter.Write(k.ToString() + ',' + theta.ToString() + ','
                               + eyevector.x.ToString() + ',' + eyevector.y.ToString() + ',' + eyevector.z.ToString() + ','
                               + truthvector.x.ToString() + ',' + truthvector.y.ToString() + ',' + truthvector.z.ToString());
            //csvに書き込むデータのリスト
            streamWriter.WriteLine();//改行
        }
        Debug.Log(k);
    }
Пример #24
0
    // Update is called once per frame
    void Update()
    {
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        RaycastHit            hitLeft, hitRight;

        //pos = mousemove / new Vector2(Screen.width, Screen.height);

        switch (FoveInterface.CheckEyesClosed())
        {
        case Fove.EFVR_Eye.Neither:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero && hitRight.point != Vector3.zero)
            {
                //transform.position = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);

                eyepos = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);
                eyepos = eyepos / new Vector2(25, 14);
                //tunpos = eyepos / new Vector2(Screen.width, Screen.height);
                //マウスの座標をシェーダーに代入するために値を調整
                //1~0で表現するためにスクリーンの大きさで割る
                //tunpos -= new Vector2(0.5f, 0.5f);//中心座標のずれを修正
                //plane.SetFloat("_UX", tunpos.x);//マウスのx座標をシェーダーのx座標に代入
                //plane.SetFloat("_VY", tunpos.y);//マウスのy座標をシェーダーのx座標に代入
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            else
            {
                //transform.position = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2);

                eyepos = eyes.left.GetPoint(3.0f) + ((eyes.right.GetPoint(3.0f) - eyes.left.GetPoint(3.0f)) / 2);;
                eyepos = eyepos / new Vector2(25, 14);
                //tunpos = eyepos / new Vector2(Screen.width, Screen.height);
                //マウスの座標をシェーダーに代入するために値を調整
                //1~0で表現するためにスクリーンの大きさで割る
                //tunpos -= new Vector2(0.5f, 0.5f);//中心座標のずれを修正
                //plane.SetFloat("_UX", tunpos.x);//マウスのx座標をシェーダーのx座標に代入
                //plane.SetFloat("_VY", tunpos.y);//マウスのy座標をシェーダーのx座標に代入
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }

            break;

        case Fove.EFVR_Eye.Left:

            Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
            if (hitRight.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                //transform.position = hitRight.point;

                eyepos = hitRight.point;
                eyepos = eyepos / new Vector2(25, 14);
                //tunpos = eyepos / new Vector2(Screen.width, Screen.height);
                //マウスの座標をシェーダーに代入するために値を調整
                //1~0で表現するためにスクリーンの大きさで割る
                //tunpos -= new Vector2(0.5f, 0.5f);//中心座標のずれを修正
                //plane.SetFloat("_UX", tunpos.x);//マウスのx座標をシェーダーのx座標に代入
                //plane.SetFloat("_VY", tunpos.y);//マウスのy座標をシェーダーのx座標に代入
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            else
            {
                //transform.position = eyes.right.GetPoint(3.0f);

                eyepos = eyes.right.GetPoint(3.0f);
                eyepos = eyepos / new Vector2(26, 14);
                //tunpos = eyepos / new Vector2(Screen.width, Screen.height);
                //マウスの座標をシェーダーに代入するために値を調整
                //1~0で表現するためにスクリーンの大きさで割る
                //tunpos -= new Vector2(0.5f, 0.5f);//中心座標のずれを修正
                //plane.SetFloat("_UX", tunpos.x);//マウスのx座標をシェーダーのx座標に代入
                //plane.SetFloat("_VY", tunpos.y);//マウスのy座標をシェーダーのx座標に代入
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            break;

        case Fove.EFVR_Eye.Right:

            Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
            if (hitLeft.point != Vector3.zero)     // Vector3 is non-nullable; comparing to null is always false
            {
                //transform.position = hitLeft.point;

                eyepos = hitLeft.point;
                eyepos = eyepos / new Vector2(25, 14);
                //tunpos = eyepos / new Vector2(Screen.width, Screen.height);
                //マウスの座標をシェーダーに代入するために値を調整
                //1~0で表現するためにスクリーンの大きさで割る
                //tunpos -= new Vector2(0.5f, 0.5f);//中心座標のずれを修正
                //plane.SetFloat("_UX", tunpos.x);//マウスのx座標をシェーダーのx座標に代入
                //plane.SetFloat("_VY", tunpos.y);//マウスのy座標をシェーダーのx座標に代入
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            else
            {
                //transform.position = eyes.left.GetPoint(3.0f);

                eyepos = eyes.left.GetPoint(3.0f);
                eyepos = eyepos / new Vector2(26, 14);
                //tunpos = eyepos / new Vector2(Screen.width, Screen.height);
                //マウスの座標をシェーダーに代入するために値を調整
                //1~0で表現するためにスクリーンの大きさで割る
                //tunpos -= new Vector2(0.5f, 0.5f);//中心座標のずれを修正
                //plane.SetFloat("_UX", tunpos.x);//マウスのx座標をシェーダーのx座標に代入
                //plane.SetFloat("_VY", tunpos.y);//マウスのy座標をシェーダーのx座標に代入
                plane.SetFloat("_UX", eyepos.x);    //マウスのx座標をシェーダーのx座標に代入
                plane.SetFloat("_VY", eyepos.y);    //マウスのy座標をシェーダーのx座標に代入
            }
            break;
        }

        //Debug.Log("Eyepos" + eyepos);
        //Debug.Log("Tunpos" + tunpos);
        //Debug.Log("Pos(" + pos.x + "," + pos.y + ")");
    }