// Update is called once per frame
    void Update()
    {
        // track time
        inputtime += Time.deltaTime;
        if (Input.GetKeyDown("space") || m_GripAction.GetStateDown(m_Pose.inputSource))
        {
            SceneManager.LoadScene("3DAuthenticationSchemeTappingOnly");
            started = false;
            stopped = false;
        }

        if (m_GrabAction.GetStateDown(m_Pose.inputSource) && !started)
        {
            fw.StartRecording();
            //Debug.Log("recording started");
            started = true;
            mdfw.StartRecording();
            inputtime = 0;
            mdfw.WriteToFileCsv(new DataModel(inputtime, passwordmodel.getUserInput()));
        }
        else if (m_GrabAction.GetStateDown(m_Pose.inputSource) && started && !stopped)
        {
            Debug.Log("writing");
            mdfw.WriteToFileCsv(new DataModel(inputtime, passwordmodel.getUserInput()));
        }

        if (hand.Userinput.Count == 4 && !stopped)
        {
            mdfw.WriteToFileCsv(new DataModel(inputtime, passwordmodel.getUserInput()));

            stopped = true;
            List <String> userinputStrings = new List <String>();
            foreach (var userinput in hand.Userinput)
            {
                Debug.Log(userinput);
                userinputStrings.Add(userinput.name);
                passwordmodel.backupInput(userinput.name);
            }
            //passwordmodel.checkPassword(userinputStrings);
            passwordmodel.entryError(userinputStrings);
            Debug.Log("recording stopped");
            fw.StopRecording();
            mdfw.StopRecording();

            if (passwordmodel.getErrors() == 0)
            {
                foreach (GameObject pin in GameObject.FindGameObjectsWithTag("Interactable"))
                {
                    pin.GetComponent <MeshRenderer>().material = _pincorrect;
                }
            }
            else
            {
                foreach (GameObject pin in GameObject.FindGameObjectsWithTag("Interactable"))
                {
                    pin.GetComponent <MeshRenderer>().material = _pinwrong;
                }
            }
        }
    }
    string FormatInputToCsv(IVRGazeData input)
    {
        //Debug.Log("erroooooooooooooors" + pm.getErrors());
        //Vector3 headDirection = input.Pose.Rotation * Vector3.forward;
        //headDirection.normalized.x,
        //headDirection.normalized.y,
        //headDirection.normalized.z,
        //Debug.Log(input.Left.PupilDiameter);

        /* string line = string.Format(
         *       "{0},{1}",
         *   (Time.unscaledTime - recordingStart).ToString(),
         *   input.TimeStamp.ToString()
         * );
         * return line;*/

        string line = string.Format(
            "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}," +
            "{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25}," +
            "{26},{27},{28},{29},{30},{31},{32},{33},{34},{35},{36},{37},{38},{39},{40},{41},{42},{43}," +
            "{44},{45},{46},{47},{48},{49},{50},{51},{52},{53},{54},{55},{56},{57},{58},{59},{60},{61},{62}",
            (Time.unscaledTime - recordingStart).ToString(),
            input.TimeStamp.ToString(),
            // global elements for hand movements
            // dominanthand global rotation x - z
            GameObject.FindGameObjectWithTag("Right").transform.rotation.x,
            GameObject.FindGameObjectWithTag("Right").transform.rotation.y,
            GameObject.FindGameObjectWithTag("Right").transform.rotation.z,
            // dominanthand position x - z
            GameObject.FindGameObjectWithTag("Right").transform.position.x,
            GameObject.FindGameObjectWithTag("Right").transform.position.y,
            GameObject.FindGameObjectWithTag("Right").transform.position.z,
            // non-dominanthand rotation x - z
            GameObject.FindGameObjectWithTag("Left").transform.rotation.x,
            GameObject.FindGameObjectWithTag("Left").transform.rotation.y,
            GameObject.FindGameObjectWithTag("Left").transform.rotation.z,
            // non-dominanthand position x - z
            GameObject.FindGameObjectWithTag("Left").transform.position.x,
            GameObject.FindGameObjectWithTag("Left").transform.position.y,
            GameObject.FindGameObjectWithTag("Left").transform.position.z,
            // local elements for hand movements (can get calculated from the camera)
            // dominanthand local rotation x - z
            GameObject.FindGameObjectWithTag("Right").transform.localRotation.x,
            GameObject.FindGameObjectWithTag("Right").transform.localRotation.y,
            GameObject.FindGameObjectWithTag("Right").transform.localRotation.z,
            // dominanthand position x - z
            GameObject.FindGameObjectWithTag("Right").transform.localPosition.x,
            GameObject.FindGameObjectWithTag("Right").transform.localPosition.y,
            GameObject.FindGameObjectWithTag("Right").transform.localPosition.z,
            // non-dominanthand rotation x - z
            GameObject.FindGameObjectWithTag("Left").transform.localRotation.x,
            GameObject.FindGameObjectWithTag("Left").transform.localRotation.y,
            GameObject.FindGameObjectWithTag("Left").transform.localRotation.z,
            // non-dominanthand position x - z
            GameObject.FindGameObjectWithTag("Left").transform.localPosition.x,
            GameObject.FindGameObjectWithTag("Left").transform.localPosition.y,
            GameObject.FindGameObjectWithTag("Left").transform.localPosition.z,
            // camera (fov) information
            Camera.main.transform.rotation.x,
            Camera.main.transform.rotation.y,
            Camera.main.transform.rotation.z,
            Camera.main.transform.position.x,
            Camera.main.transform.position.y,
            Camera.main.transform.position.z,
            input.Pose.Rotation.x,
            input.Pose.Rotation.y,
            input.Pose.Rotation.z,
            input.Pose.Position.x,
            input.Pose.Position.y,
            input.Pose.Position.z,
            input.Left.GazeOrigin.x,
            input.Left.GazeOrigin.y,
            input.Left.GazeOrigin.z,
            input.Right.GazeOrigin.x,
            input.Right.GazeOrigin.y,
            input.Right.GazeOrigin.z,
            input.Left.GazeDirection.x,
            input.Left.GazeDirection.y,
            input.Left.GazeDirection.z,
            input.Right.GazeDirection.x,
            input.Right.GazeDirection.y,
            input.Right.GazeDirection.z,
            input.CombinedGazeRayWorld.direction.normalized.x,
            input.CombinedGazeRayWorld.direction.normalized.y,
            input.CombinedGazeRayWorld.direction.normalized.z,
            input.CombinedGazeRayWorld.origin.x,
            input.CombinedGazeRayWorld.origin.y,
            input.CombinedGazeRayWorld.origin.z,
            input.Left.PupilDiameter,
            input.Right.PupilDiameter,
            input.Left.PupilPosiitionInTrackingArea.x, // tobii sdk fix Grant [Tobii]
            input.Left.PupilPosiitionInTrackingArea.y,
            input.Right.PupilPosiitionInTrackingArea.x,
            input.Right.PupilPosiitionInTrackingArea.y,
            //todo input data, class communication/singleton?
            //pm.getErrors(),
            //pm.getErrorPos()[0],
            // pm.getErrorPos()[1],
            ////pm.getErrorPos()[2],
            //pm.getErrorPos()[3],
            pm.getUserInput()
            //GameObject.Find("Triggers").GetComponent<SelectionController>().getStatusTriggerRight()
            );

        return(line);
    }