// Update is called once per frame void Update() { if (acquireEyeDatas) { LeftEye = FoveInterface.GetLeftEyeVector(); RightEye = FoveInterface.GetRightEyeVector(); acquireEyeDatas = targetMoveScript.trainingRunning; Frame FrameLeft = new Frame(); FrameLeft.timeStamp = Time.time; FrameLeft.EyePos = LeftEye; Frame FrameRight = new Frame(); FrameRight.timeStamp = Time.time; FrameRight.EyePos = RightEye; FrameLeft.EyePos = targetMoveScript.gameObject.transform.position; // :!!!!!!! framelistLeft.FrameList.Add(FrameLeft); framelistRight.FrameList.Add(FrameRight); /*if (!acquireEyeDatas) * WriteEyesData();*/ } if (Input.GetKeyDown(KeyCode.R)) { readEyeData(); } }
// 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; } }
// 固定秒数で呼ばれる処理。 private void FixedUpdate() { time = Time.realtimeSinceStartup - time2; Vector3 leftVec = FoveInterface.GetLeftEyeVector(); Vector3 rightVec = FoveInterface.GetRightEyeVector(); //if(FoveInterface.CheckEyesClosed() == Fove.Managed.EFVR_Eye.Neither) //{ // blink = 0; //} //if(FoveInterface.CheckEyesClosed() == Fove.Managed.EFVR_Eye.Left) //{ // blink = 1; //} //if(FoveInterface.CheckEyesClosed() == Fove.Managed.EFVR_Eye.Right) //{ // blink = 2; //} //if(FoveInterface.CheckEyesClosed() == Fove.Managed.EFVR_Eye.Both) //{ // blink = 3; //} if (state == 1 && flag == true) { // 1回目spaceを押した時に処理に入る。 UnityEngine.Debug.Log("初期化の処理。"); DateTime dtNow = DateTime.Now; fileName = TitleLoading.inputValue + count; count++; data.Append("time,left x,left y,left z,right x,right y,right z,\n"); // 反転する → falseになる flag = !flag; time2 = Time.realtimeSinceStartup; } else if (state == 1) { UnityEngine.Debug.Log("データを追加している。"); // 上のifが呼ばれたこちらがずっと呼ばれる。 data.Append(time + "," + leftVec.x + "," + leftVec.y + "," + leftVec.z + "," + rightVec.x + "," + rightVec.y + "," + rightVec.z + "," + "\n"); } else if (state == 2 && flag == false) { UnityEngine.Debug.Log("データを書き出している。"); //エクセルが開いたままだとIOExcepionのエラーが出現する filePath = "C:\\Users\\Yu Kume\\Desktop\\MeasureData\\blink\\" + fileName + ".csv"; WriteCsv(filePath, data); //print("write"); UnityEngine.Debug.Log("write"); data = new StringBuilder(); // 反転させている → trueにする flag = !flag; } }
// 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; } }