public static void GetPositionRotation(OptitrackStreamingClient streamingClient, int trackerId, out Vector position, out Rotation rotation) { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); position = Passer.Target.ToVector(rbState.Pose.Position); rotation = Passer.Target.ToRotation(rbState.Pose.Orientation); }
void Update() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; if (localToParent) { this.transform.localPosition = transform.parent.InverseTransformPoint(this.transform.localPosition); this.transform.localRotation = Quaternion.Inverse(transform.parent.localRotation) * this.transform.localRotation; } if (markers == null || markers.Length != rbState.Markers.Count) { markers = new Vector3[rbState.Markers.Count]; markerSize = new float[rbState.Markers.Count]; } try { for (int m = 0; m < markers.Length; ++m) { markers[m] = rbState.Markers[m].Position; markerSize[m] = rbState.Markers[m].Size; } } catch (Exception e) { } } }
private const float maxAge_sec = 0.01F; // if a measurement is older then this value, it will not be used public void Update(int trackerId) { if (streamingClient == null) { return; } OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); if (rbState == null || rbState.DeliveryTimestamp.AgeSeconds > maxAge_sec) { _rotationConfidence = 0; _positionConfidence = 0; status = Status.Present; return; } _localSensorPosition = Passer.Target.ToVector(rbState.Pose.Position); _localSensorRotation = Passer.Target.ToRotation(rbState.Pose.Orientation); _rotationConfidence = 0.99F; // only native tracking is better _positionConfidence = 1; UpdateSensor(); status = Status.Tracking; }
// Update is called once per frame void Update() { // create the color for the square new_color = new Color(color_factor, color_factor, color_factor, 1f); // put it on the square tracking_square.GetComponent <Renderer>().material.SetColor("_Color", new_color); // Define the color for the next iteration (switch it) if (color_factor > 0.0f) { color_factor = 0.0f; } else { color_factor = 1.0f; } // Get the status of the rigid body OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { // get the position of the mouse RB Mouse_Position = rbState.Pose.Position; // change the transform position of the game object this.transform.localPosition = Mouse_Position; // also change its rotation this.transform.localRotation = rbState.Pose.Orientation; // turn the angles into Euler (for later printing) Mouse_Orientation = this.transform.eulerAngles; // get the timestamp Time_stamp = rbState.DeliveryTimestamp.SecondsSince(reference); } // get the position of single trackable points in the arena, used for labeled real crickets List <OptitrackMarkerState> markerStates = StreamingClient.GetLatestMarkerStates(); // for each detected marker foreach (OptitrackMarkerState marker in markerStates) { // if it's not part of a rigid body, save the position as cricket if (marker.Labeled == false) { Cricket = marker.Position; } else { // if not, ignore it Cricket = new Vector3(10.0f, 10.0f, 10.0f); } } // Write the line of data writer.WriteLine(string.Concat(Time_stamp.ToString(), ',', Mouse_Position.x.ToString(), ',', Mouse_Position.y.ToString(), ',', Mouse_Position.z.ToString(), ',', Mouse_Orientation.x.ToString(), ',', Mouse_Orientation.y.ToString(), ',', Mouse_Orientation.z.ToString(), ',', Cricket.x.ToString(), ',', Cricket.y.ToString(), ',', Cricket.z.ToString(), ',', color_factor.ToString())); }
// Update is called once per frame void Update() { if (Input.GetKeyDown("c") && (calibrateMethod == CalibrationLoadMethod.CALIBRATION) && !dataInitiate) { StartCoroutine(RunCalibration()); } if (sampling) { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(ControllerRigidbodyID); if (rbState != null) { calibrationData.addPositionData(rbState.Pose.Position, ControllerGameobject.transform.position); samplingCount++; //new 0524 Instantiate(generate_rbState_Objects_0, rbState.Pose.Position, Quaternion.identity); Instantiate(generate_ControllerGameobject_Objects_0, ControllerGameobject.transform.position, Quaternion.identity); // log some data Debug.Log(samplingCount + " - OptitrackRB: " + rbState.Pose.Position + ", GameObj: " + ControllerGameobject.transform.position); string path = "Assets/Resources/test.txt"; //Write some text to the test.txt file StreamWriter writer = new StreamWriter(path, true); writer.WriteLine(rbState.Pose.Position); writer.Close(); if (samplingCount >= samplingPoints) { sampling = false; calibrationData.calibrateTransformationMatrix(); print("Finish Calibrate"); ShowCalibrationInfo("Finish Calibrate"); dataInitiate = true; float error = 0.0f; print("Calculating Error"); for (int i = 0; i < samplingCount; i++) { Vector3 temp = calibrationData.PositiontransformationMatrix.MultiplyPoint3x4(calibrationData.oriPosition[i]); error += Vector3.Distance(temp, calibrationData.targetPosition[i]); } float errorMean = error / samplingCount; Debug.Log(errorMean.ToString("F6")); ShowCalibrationInfo("Calculating Error: " + errorMean.ToString("F6")); } } } }
//update the transform position, rotation and timestamp every frame void Update() { rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; this.rbTimestamp = rbState.DeliveryTimestamp; } }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; } }
// Update is called once per frame void Update() { // set the color of the square for tracking the frames new_color = new Color(color_factor, color_factor, color_factor, 1f); tracking_square.GetComponent <Renderer> ().material.SetColor("_Color", new_color); if (color_factor > 0.0f) { color_factor = 0.0f; } else { color_factor = 1.0f; } OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { Mouse_Position = rbState.Pose.Position; this.transform.localPosition = Mouse_Position; this.transform.localRotation = rbState.Pose.Orientation; Mouse_Orientation = this.transform.eulerAngles; Time_stamp = rbState.DeliveryTimestamp.SecondsSince(reference); } OptitrackRigidBodyState rbState2 = StreamingClient.GetLatestRigidBodyState(RigidBodyId2); if (rbState2 != null) { Mouse_Position2 = rbState2.Pose.Position; mouse2.transform.localPosition = Mouse_Position2; mouse2.transform.localRotation = rbState2.Pose.Orientation; Mouse_Orientation2 = mouse2.transform.eulerAngles; } writer.WriteLine(string.Concat(Time_stamp.ToString(), ',', Mouse_Position.x.ToString(), ',', Mouse_Position.y.ToString(), ',', Mouse_Position.z.ToString(), ',', Mouse_Orientation.x.ToString(), ',', Mouse_Orientation.y.ToString(), ',', Mouse_Orientation.z.ToString(), ',', Mouse_Position2.x.ToString(), ',', Mouse_Position2.y.ToString(), ',', Mouse_Position2.z.ToString(), ',', Mouse_Orientation2.x.ToString(), ',', Mouse_Orientation2.y.ToString(), ',', Mouse_Orientation2.z.ToString(), ',', color_factor.ToString())); }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { trans.UpdateValue(rbState.Pose.Position, rbState.Pose.Orientation); this.transform.localPosition = Filtering ? trans.GetFilteredTransform().Position : rbState.Pose.Position; this.transform.localRotation = Filtering ? trans.GetFilteredTransform().Rotation : rbState.Pose.Orientation; } }
void UpdatePose() { Vector3 lastPos = transform.position; OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; } tracked = Vector3.Distance(lastPos, transform.position) > 0; }
void Update() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { this.transform.localPosition = Vector3.Lerp(transform.localPosition, rbState.Pose.Position.V3, Time.deltaTime * lerpSpeed); // this.transform.localPosition = rbState.Pose.Position.V3; this.transform.localRotation = Quaternion.Lerp(transform.rotation, rbState.Pose.Orientation.Q, Time.deltaTime * lerpSpeed); // this.transform.localRotation = rbState.Pose.Orientation.Q; } }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { Vector3 position = rbState.Pose.Position * moveFactor; Vector2 newPos = new Vector2(position.z, position.x); GetComponent <Rigidbody2D> ().AddForce(oldPos - newPos); oldPos = newPos; } }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { // Fix Unity rigidbody in z-plane. rbState.Pose.Position.z = 0.0f; // Amplify Unity rigidbody movement. this.transform.localPosition = rbState.Pose.Position * ampFactor; this.transform.localRotation = rbState.Pose.Orientation; } }
void Update() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { float new_x = Mathf.Clamp(rbState.Pose.Position.x, x_bound.x, x_bound.y); float new_y = Mathf.Clamp(rbState.Pose.Position.y, y_bound.x, y_bound.y); float new_z = Mathf.Clamp(rbState.Pose.Position.z, z_bound.x, z_bound.y); // Debug.Log (new_y); this.transform.localPosition = new Vector3(new_x, new_y, new_z); // this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; //Debug.Log(this.transform.localPosition); } }
void Update() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null && rbState.DeliveryTimestamp.AgeSeconds < 1.0f) { // Update position. this.transform.localPosition = rbState.Pose.Position; // Update drift correction. if (m_driftCorrHandle != IntPtr.Zero && m_hmdCameraObject) { NpHmdQuaternion opticalOri = new NpHmdQuaternion(rbState.Pose.Orientation); NpHmdQuaternion inertialOri = new NpHmdQuaternion(m_hmdCameraObject.transform.localRotation); NpHmdResult result = NativeMethods.NpHmd_MeasurementUpdate( m_driftCorrHandle, ref opticalOri, // const ref inertialOri, // const Time.deltaTime ); if (result == NpHmdResult.OK) { NpHmdQuaternion newCorrection; result = NativeMethods.NpHmd_GetOrientationCorrection(m_driftCorrHandle, out newCorrection); if (result == NpHmdResult.OK) { this.transform.localRotation = newCorrection; } else { Debug.LogError(GetType().FullName + ": NpHmd_GetOrientationCorrection failed.", this); this.enabled = false; return; } } else { Debug.LogError(GetType().FullName + ": NpHmd_MeasurementUpdate failed.", this); this.enabled = false; return; } } } }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; if (onlyRotation) { Vector3 localRotation = transform.localRotation.eulerAngles; localRotation.x = 0; localRotation.z = 0; transform.localRotation = Quaternion.Euler(localRotation); } } }
// Start is called before the first frame update void Start() { OptitrackRigidBodyState rigidBodyState = streamingClient.GetLatestRigidBodyState(rigidBodyId); if (rigidBodyState != null) { Debug.Log(string.Format("Align position of rigid body with id {0}", rigidBodyId)); gameObject.transform.SetPositionAndRotation(rigidBodyState.Pose.Position, rigidBodyState.Pose.Orientation); path = string.Format("{0}_rigidBody{1}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"), rigidBodyId); sw = new StreamWriter(path, true); Debug.Log("Print rigid body position to file"); sw.WriteLine(string.Format("{0}\t{1}", rigidBodyState.Pose.Position, rigidBodyState.Pose.Orientation)); sw.Close(); } }
public override void Update() { if (!humanoid.optitrack.enabled || !enabled) { return; } //float confidence = 1; OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); if (rbState != null) { targetTransform.position = rbState.Pose.Position; targetTransform.rotation = rbState.Pose.Orientation; // architecture does not allow confidence here... } }
void UpdateGO(int sname, GameObject go, ref OptitrackRigidBodyState otRBState, ref List <bool> readies) { float s = 0.05f; otRBState = StreamingClient.GetLatestRigidBodyState(sname); readies.Add(otRBState != null); go.transform.localScale = new Vector3(s, s, s); if (otRBState != null) { go.transform.position = otRBState.Pose.Position; go.transform.rotation = otRBState.Pose.Orientation; if (drawRotation) { Debug.DrawRay(go.transform.position, go.transform.TransformDirection(Vector3.forward), Color.blue); Debug.DrawRay(go.transform.position, go.transform.TransformDirection(Vector3.up), Color.green); Debug.DrawRay(go.transform.position, go.transform.TransformDirection(Vector3.right), Color.red); } } }
private const float maxAge_sec = 0.01F; // if a measurement is older then this value, it will not be used public override void UpdateComponent() { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(streamingID); if (rbState == null || rbState.DeliveryTimestamp.AgeSeconds > maxAge_sec) { status = Status.Present; positionConfidence = 0; rotationConfidence = 0; gameObject.SetActive(false); return; } status = Status.Tracking; transform.position = trackerTransform.TransformPoint(rbState.Pose.Position); transform.rotation = trackerTransform.rotation * rbState.Pose.Orientation; positionConfidence = 1F; rotationConfidence = 0.99F; gameObject.SetActive(true); }
void Update() { if (!useOptitrack) { this.transform.localPosition = new Vector3(0, 0, 0); if (!m_initialPoseSet) { m_initialPoseSet = true; m_fusion.setCurrentOrientation(this.transform.localRotation); } return; } OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null && rbState.DeliveryTimestamp.AgeSeconds < 1.0f) { Debug.Log("new position", this); // Update position. this.transform.localPosition = rbState.Pose.Position; // Update drift correction. if (m_lastTimestamp.AgeSeconds != rbState.DeliveryTimestamp.AgeSeconds) { // If we're coming here the first time: reset to optical pose. Otherwise // we're using the optical orientation for drift correction. if (!m_initialPoseSet) { m_initialPoseSet = true; m_fusion.setCurrentYaw(rbState.Pose.Orientation); } else if (enableDriftCorrection) { m_fusion.setCurrentYawSoft(rbState.Pose.Orientation); } m_lastTimestamp = rbState.DeliveryTimestamp; } } }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { if (rbState.DeliveryTimestamp.AgeSeconds > 0.05) { if (updated) { Debug.Log("no data from optitrack"); } updated = false; } else { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; updated = true; } } }
public static Vector GetPosition(OptitrackStreamingClient streamingClient, int trackerId) { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); return(Passer.Target.ToVector(rbState.Pose.Position)); }
/* * Method to update the position of the cue rigidbody every by reading the data from the Optitrack client */ void UpdatePose() { #region Cue State Variables OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); //access rigidbody Vector3 OfrontPos = new Vector3(); //optitrack front position Vector3 ObackPos = new Vector3(); //optitrack back position List <OptitrackMarkerState> markerStates = new List <OptitrackMarkerState>(); //initialize list of marker objects from rigidbody List <Vector3> markerPositions = new List <Vector3>(); //list of all cue marker positions #endregion if (rbState != null) { //Get marker positions markerStates = StreamingClient.GetLatestMarkerStates(); //get objects of all markers from rigidbody #region Check if valid Optitrack markers //if not all markers are tracked, make cue stick invisible if (markerStates.Count < 4) { Experiment.cuestickMesh.enabled = false; //Debug.Log(markerStates.Count); cuePos = prevPos; return; } Experiment.cuestickMesh.enabled = true; #endregion #region Access & store marker poitions //Loop through markers for (int idx = 0; idx < markerStates.Count; idx++) { OptitrackMarkerState marker = markerStates[idx]; int markerID = marker.Id; Vector3 pos = marker.Position; markerPositions.Add(marker.Position); } #endregion #region Derive Unity cue position IEnumerable <Vector3> sorted = markerPositions.OrderBy(v => v.z); //sort marker positions by z position OfrontPos = (sorted.ElementAt(3) + sorted.ElementAt(2)) / 2; Vector3 dif = OfrontPos - sorted.ElementAt(1); ObackPos = sorted.ElementAt(0) + dif; //Translate optitrack positions to unity using helper methods ( [Xo, Zo, 1] * M = [Xu, Zu, 1]) float[,] frontMatrix = new float[, ] { { OfrontPos.x }, { OfrontPos.z }, { 1 } }; float[,] backMatrix = new float[, ] { { ObackPos.x }, { ObackPos.z }, { 1 } }; float[,] frontU = Experiment.MultiplyMatrix(Experiment.M, frontMatrix); float[,] backU = Experiment.MultiplyMatrix(Experiment.M, backMatrix); Vector3 backPos = new Vector3(backU[0, 0], ObackPos.y * Experiment.yratio, backU[1, 0]); Vector3 frontPos = new Vector3(frontU[0, 0], OfrontPos.y * Experiment.yratio, frontU[1, 0]); //cue position is front position plus projected vector Vector3 direction = (frontPos - backPos).normalized; cuePos = frontPos + (direction * PlayerPrefs.GetFloat("tip_marker1") * PlayerPrefs.GetFloat("cmToUnity")); //limit cuetip height to table surface height if (cuePos.y < Experiment.corner1.position.y) { cuePos = new Vector3(cuePos.x, Experiment.corner1.position.y, cuePos.z); } #endregion #region Calculate cue velocity //calculate velocity cueVelocity = (cuePos - prevPos) / Time.fixedDeltaTime; if (cueVelocity.magnitude > 3) { cueVelocity = 3f * cueVelocity.normalized; } VelocityList.Add(cueVelocity); //avgVelocity = AverageVelocity(VelocityList, Experiment.numVelocitiesAverage); prevPos = cuePos; #endregion //move cue rigidbody to updated position Experiment.cueFront.transform.position = cuePos; //get forward direction by lookng at forwrd position from actual optitrack position (could also do with transformed positions) Experiment.cueFront.transform.rotation = Quaternion.LookRotation(frontPos - backPos) * Quaternion.Euler(0f, 0f, 0f); } }
void UpdatePose() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null && rbState.DeliveryTimestamp.AgeSeconds < 1.0f) { this.transform.localPosition = rbState.Pose.Position; if (m_nphmdHandle != IntPtr.Zero && m_deviceInitialized) { NpHmdQuaternion inertialOri = new NpHmdQuaternion(m_hmdCameraObject.transform.localRotation); NpHmdQuaternion opticalOri; switch (RigidBodyOrientation) { case OptitrackHmdRbOrientation.NegativeZForward: opticalOri = new NpHmdQuaternion(rbState.Pose.Orientation * Quaternion.Euler(0.0f, 180.0f, 0.0f)); break; case OptitrackHmdRbOrientation.PositiveZForward: opticalOri = new NpHmdQuaternion(rbState.Pose.Orientation); break; case OptitrackHmdRbOrientation.PositiveXForward: opticalOri = new NpHmdQuaternion(rbState.Pose.Orientation * Quaternion.Euler(0.0f, -90.0f, 0.0f)); break; default: return; } NpHmdResult result = NativeMethods.NpHmd_MeasurementUpdate( m_nphmdHandle, ref opticalOri, // const ref inertialOri, // const Time.deltaTime ); if (result == NpHmdResult.OK) { NpHmdQuaternion newCorrection; result = NativeMethods.NpHmd_GetOrientationCorrection(m_nphmdHandle, out newCorrection); if (result == NpHmdResult.OK) { this.transform.localRotation = newCorrection; } else { Debug.LogError(GetType().FullName + ": NpHmd_GetOrientationCorrection failed.", this); this.enabled = false; return; } } else { Debug.LogError(GetType().FullName + ": NpHmd_MeasurementUpdate failed.", this); this.enabled = false; return; } } } }
public static Rotation GetRotation(OptitrackStreamingClient streamingClient, int trackerId) { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); return(Passer.Target.ToRotation(rbState.Pose.Orientation)); }
// Update is called once per frame void Update() { count += 1; // --- Handle the tracking square --- // // create the color for the square new_color = new Color(color_factor, color_factor, color_factor, 1f); // put it on the square tracking_square.GetComponent <Renderer>().material.SetColor("_Color", new_color); // Define the color for the next iteration (switch it) //if (count % 120 == 0) //{ if (color_factor > 0.0f) { color_factor = 0.0f; } else { color_factor = 1.0f; } //} // --- Handle mouse and cricket data --- // // This works for a single VR cricket // Process the mouse position as the other scripts OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyId); if (rbState != null) { // get the position of the mouse RB Mouse_Position = rbState.Pose.Position; // change the transform position of the game object this.transform.localPosition = Mouse_Position; // also change its rotation this.transform.localRotation = rbState.Pose.Orientation; // turn the angles into Euler (for later printing) Mouse_Orientation = this.transform.eulerAngles; // get the timestamp Time_stamp = rbState.DeliveryTimestamp.SecondsSince(reference); } else { Mouse_Position = MouseObj.transform.position; Mouse_Orientation = MouseObj.transform.rotation.eulerAngles; } // Write the mouse data to a string mouse_data = string.Concat(Mouse_Position.x.ToString(), ',', Mouse_Position.y.ToString(), ',', Mouse_Position.z.ToString(), ',', Mouse_Orientation.x.ToString(), ',', Mouse_Orientation.y.ToString(), ',', Mouse_Orientation.z.ToString()); // Loop through the VR Crickets to get their data foreach (GameObject cricket_obj in CricketObjs) { // Get the VR cricket position and orientation Cricket_Position = cricket_obj.transform.position; Cricket_Orientation = cricket_obj.transform.rotation.eulerAngles; // Get the VR cricket speed and current motion state speed = cricket_obj.GetComponent <Animator>().GetFloat("speed");; state = cricket_obj.GetComponent <Animator>().GetInteger("state_selector"); motion = cricket_obj.GetComponent <Animator>().GetInteger("motion_selector"); encounter = cricket_obj.GetComponent <Animator>().GetInteger("in_encounter"); // Concatenate strings for this cricket object, and add to all cricket string this_cricket = String.Concat(Cricket_Position.x.ToString(), ',', Cricket_Position.y.ToString(), ',', Cricket_Position.z.ToString(), ',', Cricket_Orientation.x.ToString(), ',', Cricket_Orientation.y.ToString(), ',', Cricket_Orientation.z.ToString(), ',', speed.ToString(), ',', state.ToString(), ',', motion.ToString(), ',', encounter.ToString(), ','); cricket_data = String.Concat(cricket_data, this_cricket); } // --- Data Saving --- // // Write the mouse and VR cricket info writer.WriteLine(string.Concat(Time_stamp.ToString(), ',', mouse_data, ',', cricket_data, color_factor.ToString())); cricket_data = ""; }
void Update() { OptitrackRigidBodyState rbState = StreamingClient.GetLatestRigidBodyState(RigidBodyID); Vector3 eulerAngles = this.transform.rotation.eulerAngles; if (rbState != null) { //assign the correct position if (matrixSet) { //Position CalibrationProcessData controllerData = calibrationScript.getControllerData(); this.transform.localPosition = transformationMatrix.MultiplyPoint3x4(rbState.Pose.Position); //Rotation //Quaternion to Matrix4x4 Matrix4x4 angleInMatrix = Matrix4x4.TRS(Vector3.zero, rbState.Pose.Orientation, Vector3.one); Matrix4x4 resultInMatrix = transformationMatrix * angleInMatrix; Quaternion q = QuaternionFromMatrix(resultInMatrix); //this.transform.rotation = q * Quaternion.Euler(offsetRotation.x, offsetRotation.y, offsetRotation.z); this.transform.rotation = q; } else { this.transform.localPosition = rbState.Pose.Position; this.transform.localRotation = rbState.Pose.Orientation; //Get the controller data if (calibrationScript.isDataInitiate() && !matrixSet) { CalibrationProcessData controllerData = calibrationScript.getControllerData(); transformationMatrix = controllerData.PositiontransformationMatrix; matrixSet = true; } } Debug.Log("transform.rotation angles x: " + eulerAngles.x + " y: " + eulerAngles.y + " z: " + eulerAngles.z); } //if Pen's angel in this range , it can show photos if (this.transform.rotation.eulerAngles.y > 250 && this.transform.rotation.eulerAngles.y < 290) { photo_show_flag = true; } else { photo_show_flag = false; obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); object_text.gameObject.SetActive(false); } //if Pen's angel in this range , it can listen music if ((this.transform.rotation.eulerAngles.y < 20 || this.transform.rotation.eulerAngles.y > 340) && this.transform.rotation.eulerAngles.x > 290) { music_play = true; } else { music_play = false; music1.gameObject.SetActive(false); music2.gameObject.SetActive(false); music3.gameObject.SetActive(false); m_text1.gameObject.SetActive(false); m_text2.gameObject.SetActive(false); m_text3.gameObject.SetActive(false); } //play music if (music_play) { //play 1st music if (this.transform.rotation.eulerAngles.z < 120) { music1.gameObject.SetActive(true); music2.gameObject.SetActive(false); music3.gameObject.SetActive(false); Debug.Log("0000000000"); m_text1.gameObject.SetActive(true); m_text2.gameObject.SetActive(false); m_text3.gameObject.SetActive(false); } //play 2nd music else if (this.transform.rotation.eulerAngles.z > 120 && this.transform.rotation.eulerAngles.z < 240) { music1.gameObject.SetActive(false); music2.gameObject.SetActive(true); music3.gameObject.SetActive(false); Debug.Log("1111111111111"); m_text1.gameObject.SetActive(false); m_text2.gameObject.SetActive(true); m_text3.gameObject.SetActive(false); } //play 3rd music else { music1.gameObject.SetActive(false); music2.gameObject.SetActive(false); music3.gameObject.SetActive(true); Debug.Log("222222222222"); m_text1.gameObject.SetActive(false); m_text2.gameObject.SetActive(false); m_text3.gameObject.SetActive(true); } } // Show Photos if (photo_show_flag) { object_text.gameObject.SetActive(true); //Show Photo 1 if (this.transform.rotation.eulerAngles.z < 45) { obeject1.gameObject.SetActive(true); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); } //Show Photo 2 else if (this.transform.rotation.eulerAngles.z >= 45 && this.transform.rotation.eulerAngles.z < 90) { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(true); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); } //Show Photo 3 else if (this.transform.rotation.eulerAngles.z >= 90 && this.transform.rotation.eulerAngles.z < 135) { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(true); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); } //Show Photo 4 else if (this.transform.rotation.eulerAngles.z >= 135 && this.transform.rotation.eulerAngles.z < 180) { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(true); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); } //Show Photo 5 else if (this.transform.rotation.eulerAngles.z >= 180 && this.transform.rotation.eulerAngles.z < 225) { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(true); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); } //Show Photo 6 else if (this.transform.rotation.eulerAngles.z >= 225 && this.transform.rotation.eulerAngles.z < 270) { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(true); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); } //Show Photo 7 else if (this.transform.rotation.eulerAngles.z >= 270 && this.transform.rotation.eulerAngles.z < 315) { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(true); object8.gameObject.SetActive(false); } //Show Photo 8 else { obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(true); } } }