UnityでUpdate関数内で計算された値
float Time
double phi1
double phi2
double theta1
double theta2
float headangle
を引数にして、これらをCSVファイルに書き出したいです.
プログラムにエラーが出てしまったのですがよくわかりません。
logSave関数でCSV書き出しの処理をしています。
また、別の.csファイルからもlogSave関数を使いたいと思っているのでstatic public にしています。
Unityは使い始めて4か月ほどで知らないことが多いですがどうかよろしくお願いします.
html
1using System.Collections; 2using System.Collections.Generic; 3using System; 4using System.IO; 5using UnityEngine; 6 7public class gaze_excel : MonoBehaviour { 8 public Vector3 vector1; 9 public Vector3 vector2; 10 double theta1, phi1, theta2, phi2; 11 public Vector2 left; 12 public Vector2 right; 13 float _timer; 14 float _deltatime; 15 float headangle=0f; 16 17 // Use this for initialization 18 void Start () { 19 20 } 21 22 // Update is called once per frame 23 void Update () { 24 _timer = Time.time; 25 _deltatime += Time.deltaTime; 26 vector1 = FoveInterface.GetLeftEyeVector_Immediate(); 27 vector2 = FoveInterface.GetRightEyeVector_Immediate(); 28 theta1 = Math.Atan((double)vector1.y / (double)vector1.z) * 180 / Math.PI; ; 29 phi1 = Math.Atan((double)vector1.x / (double)vector1.z) * 180 / Math.PI; 30 theta2 = Math.Atan((double)vector2.y / (double)vector2.z) * 180 / Math.PI; 31 phi2 = Math.Atan((double)vector2.x / (double)vector2.z) * 180 / Math.PI; 32 //left.x = 4 * (float)Math.Tan(phi1 * (Math.PI / 180)); 33 //left.y = 4 * (float)Math.Tan(theta1 * (Math.PI / 180)); 34 //right.x= 4 * (float)Math.Tan(phi2 * (Math.PI / 180)); 35 //right.y = 4 * (float)Math.Tan(theta2 * (Math.PI / 180)); 36 37 38 if (_deltatime >= 0.1){ 39 headangle += 1; 40 logSave(_timer, phi1, theta1, phi2, theta2,headangle); 41 _deltatime = 0; 42 } 43 } 44 45 46 static public void logSave(float Time, double phi1, double theta1, double phi2, double theta2, float headangle) 47 { 48 StreamWriter sw; 49 FileInfo fi; 50 fi = new FileInfo(Application.dataPath + "/sensor.csv"); 51 sw = fi.AppendText(); 52 53 if (headangle < 180f) 54 sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", Time, phi1, theta1, phi2, theta2, -headangle); 55 else 56 sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", Time, phi1, theta1, phi2, theta2, -(headangle-360f)); 57 58 sw.Flush(); 59 sw.Close(); 60 } 61 62}
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/01 06:00