Ejemplo n.º 1
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);
        }
    }