private void RigidBodyDataToState(sRigidBodyData rbData, OptitrackHiResTimer.Timestamp timestamp, OptitrackRigidBodyState rbState) { rbState.DeliveryTimestamp = timestamp; rbState.Pose = new OptitrackPose { Position = new Vector3(-rbData.X, rbData.Y, rbData.Z), Orientation = new Quaternion(-rbData.QX, rbData.QY, rbData.QZ, -rbData.QW), }; }
//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; } }
System.Collections.IEnumerator CheckConnectionHealth() { const float kHealthCheckIntervalSeconds = 1.0f; const float kRecentFrameThresholdSeconds = 5.0f; // The lifespan of these variables is tied to the lifespan of a single connection session. // The coroutine is stopped on disconnect and restarted on connect. YieldInstruction checkIntervalYield = new WaitForSeconds(kHealthCheckIntervalSeconds); OptitrackHiResTimer.Timestamp connectionInitiatedTimestamp = OptitrackHiResTimer.Now(); OptitrackHiResTimer.Timestamp lastFrameReceivedTimestamp; bool wasReceivingFrames = false; bool warnedPendingFirstFrame = false; while (true) { yield return(checkIntervalYield); if (m_receivedFrameSinceConnect == false) { // Still waiting for first frame. Warn exactly once if this takes too long. if (connectionInitiatedTimestamp.AgeSeconds > kRecentFrameThresholdSeconds) { if (warnedPendingFirstFrame == false) { Debug.LogWarning(GetType().FullName + ": No frames received from the server yet. Verify your connection settings are correct and that the server is streaming.", this); warnedPendingFirstFrame = true; } continue; } } else { // We've received at least one frame, do ongoing checks for changes in connection health. lastFrameReceivedTimestamp.m_ticks = Interlocked.Read(ref m_lastFrameDeliveryTimestamp.m_ticks); bool receivedRecentFrame = lastFrameReceivedTimestamp.AgeSeconds < kRecentFrameThresholdSeconds; if (wasReceivingFrames == false && receivedRecentFrame == true) { // Transition: Bad health -> good health. wasReceivingFrames = true; Debug.Log(GetType().FullName + ": Receiving streaming data from the server.", this); continue; } else if (wasReceivingFrames == true && receivedRecentFrame == false) { // Transition: Good health -> bad health. wasReceivingFrames = false; Debug.LogWarning(GetType().FullName + ": No streaming frames received from the server recently.", this); continue; } } } }
// Use this for initialization void Start() { reference = OptitrackHiResTimer.Now(); // Get the camera component Camera cam = GetComponentInChildren <Camera>(); cam.nearClipPlane = 0.000001f; // set the OSC communication osc.SetAddressHandler("/Close", OnReceiveStop); writer = new StreamWriter(Paths.recording_path, true); mouse2 = GameObject.CreatePrimitive(PrimitiveType.Sphere); mouse2.SetActive(false); }
// Use this for initialization void Start() { // get the reference timer reference = OptitrackHiResTimer.Now(); // Set up the camera (so it doesn't clip objects too close to the mouse) Camera cam = GetComponentInChildren <Camera>(); cam.nearClipPlane = 0.000001f; // set the OSC communication osc.SetAddressHandler("/Close", OnReceiveStop); // Set the writer writer = new StreamWriter(Paths.recording_path, 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; } } }
// Use this for initialization void Start() { // Force full screen on projector Screen.fullScreen = true; // Get the reference timer reference = OptitrackHiResTimer.Now(); // set the OSC communication osc.SetAddressHandler("/Close", OnReceiveStop); // Set up the camera (so it doesn't clip objects too close to the mouse) Camera cam = GetComponentInChildren <Camera>(); cam.nearClipPlane = 0.000001f; // Set the writer writer = new StreamWriter(Paths.recording_path, true); // Get cricket object array sorted by name/number CricketObjs = FindObsWithTag("Cricket"); }