// Update is called once per frame
    private void Update()
    {
        // Get the right most controller
        SteamVR_Controller.Device controller2 = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost));
        vr_device = SteamVR_Controller.Input((int)tracker.index);
        //   if(vr_device.angularVelocity.y > 0.02f) {
        transform.rotation = Quaternion.Lerp(transform.rotation, tracker.transform.rotation, 20 * Time.deltaTime);
        transform.position = tracker.transform.position + tracker.transform.forward * 0.2f;
        transform.GetChild(2).LookAt(Camera.main.transform);
        //   }
        y_angular_velocity = vr_device.angularVelocity.y;

        if (graph.graphIsClustered() && !createdMiniature)
        {
            clusters  = graph.transform.GetComponentsInChildren <ClusterBehaviour>();
            miniature = new GameObject();
            miniature.transform.name          = "Miniature Graph";
            miniature.transform.parent        = transform.GetChild(0);
            miniature.transform.localPosition = graph.transform.position / 15;
            origin        = new GameObject("origin").transform;
            origin.parent = transform.GetChild(0);
            origin.transform.localPosition = new Vector3(0, 0, 0);
            MeshFilter[]      meshFilters = new MeshFilter[clusters.Length];
            CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
            Material[]        mat         = new Material[clusters.Length];
            for (int k = 0; k < clusters.Length; k++)
            {
                GameObject g = clusters[k].gameObject;
                GameObject j = new GameObject();
                mat[k]                  = g.GetComponent <MeshRenderer>().material;
                meshFilters[k]          = g.GetComponent <MeshFilter>();
                combine[k].mesh         = meshFilters[k].sharedMesh;
                combine[k].subMeshIndex = k;
                combine[k].transform    = meshFilters[k].transform.localToWorldMatrix;
                j.AddComponent <MeshFilter>();
                j.AddComponent <MeshRenderer>();
                j.GetComponent <MeshRenderer>().material = mat[k];
                j.GetComponent <MeshFilter>().mesh       = combine[k].mesh;
                j.layer                   = 5;
                j.transform.parent        = miniature.transform;
                j.transform.localPosition = Vector3.zero;
                if (k == 0)
                {
                    Rcluster  = g.GetComponent <Renderer>();
                    WMcluster = j.GetComponent <Renderer>();
                }
            }
            // check if empty
            if (miniStudyNodes [0] != null)
            {
                for (int k = 0; k < miniStudyNodes.Length; k++)
                {
                    miniStudyNodes [k].transform.parent = miniature.transform;
                }
            }
            // identify study node and make parent of WIM
            WIMNode wimNode = GetComponentInChildren <WIMNode>();
            wimNode.transform.parent          = miniature.transform;
            miniature.transform.localRotation = Quaternion.Euler(new Vector3(0, -90, -90));
            miniature.transform.localScale    = new Vector3(0.07f, 0.07f, 0.07f);
            createdMiniature = true;
        }

        // if the miniature has been created, and the user is rotating the graph
        //if (createdMiniature && controller2.GetPress(SteamVR_Controller.ButtonMask.Grip)) {
        if (miniature != null && miniCam.Moving)
        {
            graph.transform.rotation = miniature.transform.rotation;
        }
        //}
        CalculateWMVectors();
    }
    // Update is called once per frame
    void Update()
    {
        if (graph.graphIsClustered() && !stop)
        {
            int pickNumber = studyAssign.DataArray[0];
            vis_nodes = graph.returnGraphNodes();

            // SimpleFind
            simpleFindAsset = simpleFind[pickNumber];
            string   s     = simpleFindAsset.text.Replace("\r", "\n");
            string[] lines = s.Split("\n"[0]);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Equals(string.Empty) == false)
                {
                    simpleFindNodes.Add(search(lines[i]));
                }
            }

            //ComplexFind
            pickNumber       = studyAssign.DataArray[1];
            complexFindAsset = complexFind[pickNumber];
            s     = complexFindAsset.text.Replace("\r", "\n");
            lines = s.Split("\n"[0]);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Equals(string.Empty) == false)
                {
                    complexFindNodes.Add(search(lines[i]));
                }
            }

            //CircleCount
            pickNumber       = studyAssign.DataArray[2];
            circleCountAsset = circleCount[pickNumber];
            s     = circleCountAsset.text.Replace("\r", "\n");
            lines = s.Split("\n"[0]);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Equals(string.Empty) == false)
                {
                    circleCountNodes.Add(search(lines[i]));
                }
            }

            //AssocCount
            pickNumber      = studyAssign.DataArray[3];
            assocCountAsset = AssocCount[pickNumber];
            s     = assocCountAsset.text.Replace("\r", "\n");
            lines = s.Split("\n"[0]);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Equals(string.Empty) == false)
                {
                    AssocCountNodes.Add(search(lines[i]));
                }
            }
            stop = true;
        }
        if (graph.graphIsClustered() && stop == true)
        {
            // set positions for nodes (simple nodes)
            if (studyStage == 1 && simpleStart == false)
            {
                currentTask = "Simple Find";
                for (int i = 0; i < simpleFindNodes.Count; i++)
                {
                    VisualNode v = (VisualNode)simpleFindNodes[i];
                    studyNodes[i].transform.position = v.transform.position;
                    studyNodes[i].setTarget(v);
                    if (i == 0)
                    {
                        currentStudyNode = studyNodes[i];
                        currentStudyNode.gameObject.SetActive(true);
                        closeBtns[0].setStudyNode(currentStudyNode);
                        closeBtns[1].setStudyNode(currentStudyNode);
                    }
                    else
                    {
                        studyNodes[i - 1].setNext(studyNodes[i]);
                        studyNodes[i].gameObject.SetActive(false);
                    }
                }
                simpleStart = true;
            }
            // set positions for nodes (complex nodes)
            if (studyStage == 2 && complexStart == false)
            {
                currentTask = "Complex Find";
                for (int i = 0; i < complexFindNodes.Count; i++)
                {
                    VisualNode v = (VisualNode)complexFindNodes[i];
                    studyNodes[i].transform.position = v.transform.position;
                    studyNodes[i].setTarget(v);
                    if (i == 0)
                    {
                        currentStudyNode = studyNodes[i];
                        currentStudyNode.gameObject.SetActive(true);
                        closeBtns[0].setStudyNode(currentStudyNode);
                        closeBtns[1].setStudyNode(currentStudyNode);
                    }
                    else
                    {
                        studyNodes[i - 1].setNext(studyNodes[i]);
                        studyNodes[i].gameObject.SetActive(false);
                    }
                }
                complexStart = true;
            }
            // set positions for nodes (circle nodes)
            if (studyStage == 3 && circleStart == false)
            {
                currentTask = "Circle Find";
                for (int i = 0; i < circleCountNodes.Count; i++)
                {
                    VisualNode v = (VisualNode)circleCountNodes[i];
                    studyNodes[i].transform.position = v.transform.position;
                    studyNodes[i].setTarget(v);
                    if (i == 0)
                    {
                        currentStudyNode = studyNodes[i];
                        currentStudyNode.gameObject.SetActive(true);
                        closeBtns[0].setStudyNode(currentStudyNode);
                        closeBtns[1].setStudyNode(currentStudyNode);
                    }
                    else
                    {
                        studyNodes[i - 1].setNext(studyNodes[i]);
                        studyNodes[i].gameObject.SetActive(false);
                    }
                }
                circleStart = true;
            }
            // set positions for nodes (circle nodes)
            if (studyStage == 4 && assocStart == false)
            {
                currentTask = "Association Find";
                for (int i = 0; i < AssocCountNodes.Count; i++)
                {
                    VisualNode v = (VisualNode)AssocCountNodes[i];
                    studyNodes[i].transform.position = v.transform.position;
                    studyNodes[i].setTarget(v);
                    if (i == 0)
                    {
                        currentStudyNode = studyNodes[i];
                        currentStudyNode.gameObject.SetActive(true);
                        closeBtns[0].setStudyNode(currentStudyNode);
                        closeBtns[1].setStudyNode(currentStudyNode);
                    }
                    else
                    {
                        studyNodes[i - 1].setNext(studyNodes[i]);
                        studyNodes[i].gameObject.SetActive(false);
                    }
                }
                assocStart = true;
            }
        }
        if (testCSVOutput)
        {
            createCSV();
            testCSVOutput = false;
        }
        if (studyAssign != null)
        {
            splashTime -= Time.deltaTime;
            if (splashTime > 0)
            {
                if (studyAssign.initialLoad > 1)
                {
                    splashText.text = studyAssign.currentNavigation;
                }
                else
                {
                    splashText.text = "INITIAL LOAD TEST";
                }
            }
            else
            {
                splashText.text = "";
            }
            if (studyAssign.currentNavigation.Equals("WM") == false)
            {
                wim.gameObject.SetActive(false);
            }
        }
    }