// condition: (1) left high, right low (2) right high, left low (3) both high (4) both low // (5) left 39, right 30 ~ 27 (6) left 30 ~ 27, right 39 (7) high low modulation (8) high high modulation void setStimulus(int condition) { Vector3[] ps = new Vector3[TARGET_NUM]; Vector3[] qs = new Vector3[TARGET_NUM]; float[] freqs = new float[TARGET_NUM]; string[] labels = new string[TARGET_NUM]; string[] layers = new string[TARGET_NUM]; int[] modulations = Enumerable.Repeat(0, TARGET_NUM).ToArray(); float[] modulationFreqs = Enumerable.Repeat(-1f, TARGET_NUM).ToArray(); float[] phases = Enumerable.Repeat(0f, TARGET_NUM).ToArray(); float[] dutyCycles = Enumerable.Repeat(0.5f, TARGET_NUM).ToArray(); for (int i = 0; i < TARGET_NUM; i++) { ps[i] = new Vector3(9f * ((i - 1) % 2), 9f * ((i - 2) % 2), z_pos); qs[i] = new Vector3(-90, 0, 0); freqs[i] = PredefinedFreqs[i]; labels[i] = (i + 1).ToString(); layers[i] = "Default"; } stimulusManager.InitialTargets(ps, qs, freqs, labels, layers, modulations, modulationFreqs, phases, dutyCycles); }
void Start() { targetTime = 2f; state = 0; trainingTarget = 0; var soundManager = GameObject.Find("Audio Manager"); textToSpeech = soundManager.GetComponent <TextToSpeech>(); textToSpeech.Voice = TextToSpeechVoice.Zira; textToSpeech.StartSpeaking("Hello, welcome to the Steady State Visually Evoked Potential experiment!"); var stimulusManagerObject = GameObject.Find("Stimulus Manager"); stimulusManager = stimulusManagerObject.GetComponent <StimulusManager>(); //stimulusManager.InitialTargets(numPerColumn, numPerRow, -1.5f, 7f, 8f, 1f); stimulusManager.InitialTargets(numPerColumn, numPerRow, 0f, 0f, 8f, 1f); }
void ParseObjectDetectionResult(int read_length, byte[] result_bytes) { if (read_length < 26) { Debug.Log("No detected object. Lenght: " + read_length.ToString()); return; } else { float panelWidth = canvasRectTransform.rect.width; // * canvasRectTransform.localScale.x; float panelHeight = canvasRectTransform.rect.height; // * canvasRectTransform.localScale.y; var labelArray = new byte[10]; var positionArray = new float[4]; // Show no more than MAX_OBJECT_NUM objects read_length = Math.Min(MAX_OBJECT_NUM * 26, read_length); Vector3[] positions = new Vector3[read_length / 26]; Vector3[] qs = new Vector3[read_length / 26]; float[] freqs = new float[read_length / 26]; string[] labels = new string[read_length / 26]; for (int i = 0; i < read_length; i += 26) { System.Buffer.BlockCopy(result_bytes, i, labelArray, 0, 10); string label = Encoding.UTF8.GetString(labelArray); Debug.Log(label); System.Buffer.BlockCopy(result_bytes, i + 10, positionArray, 0, 16); Debug.Log(positionArray[0].ToString() + " " + positionArray[1].ToString()); float pos_x = panelWidth * ((positionArray[0] - 0.5f) * 1.3f + 0.5f); float pos_y = panelWidth * (1 - positionArray[1]) - 200; float pos_z = 100f; Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(pos_x, pos_y, pos_z)); positions[i / 26] = pos; qs[i / 26] = new Vector3(-90, 0, 0); freqs[i / 26] = startFreq + (i / 26) * freqResolution; labels[i / 26] = label; } if (textUpdater != null) { textUpdater.setTargetLabelMap(labels); } stimulusManager.InitialTargets(positions, qs, freqs, labels); stimulusManager.GazeShift(); targetTime = 0.5f; state = 1; return; } /* * var floatArray = new float[(read_length) / 4]; * System.Buffer.BlockCopy(result_bytes, 0, floatArray, 0, read_length); * * float[] result = floatArray; * if (result.Length < 4) * { * Debug.Log("No detected object " + result_bytes[0].ToString()); * state = 0; * targetTime = 0; * return; * } * * float panelWidth = canvasRectTransform.rect.width;// * canvasRectTransform.localScale.x; * float panelHeight = canvasRectTransform.rect.height;// * canvasRectTransform.localScale.y; * * Vector3[] positions = new Vector3[(int)result.Length / 4]; * Quaternion[] qs = new Quaternion[(int)result.Length / 4]; * float[] freqs = new float[(int)result.Length / 4]; * * for (int i = 0; i < result.Length; i += 4) * { * Debug.Log("Object " + (i / 4).ToString() + ": x = " + result[i] + ", y = " + result[i + 1]); * float pos_x = panelWidth * ((result[i] - 0.5f) * 1.3f + 0.5f); * float pos_y = panelWidth * (1 - result[i + 1]) - 200; * float pos_z = 100f; * Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(pos_x, pos_y, pos_z)); * positions[i / 4] = pos; * qs[i / 4] = Quaternion.Euler(-90, 0, 0); * freqs[i / 4] = startFreq + (i / 4) * freqResolution; * } * stimulusManager.InitialTargets(positions, qs, freqs); * stimulusManager.StopStimulating(); * targetTime = 0.5f; * state = 1; * //photoCaptureObject.Dispose(); */ }