/// <summary> /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive. /// </summary> /// <param name="secondsFromNow">The time offset in the future (estimated) or in the past (previously recorded) you want to get data from</param> /// <returns>true if we successfully returned a pose</returns> public bool GetPoseAtTimeOffset(float secondsFromNow, out Vector3 positionAtTime, out Quaternion rotationAtTime, out Vector3 velocityAtTime, out Vector3 angularVelocityAtTime) { EVRInputError err = OpenVR.Input.GetPoseActionData(handle, universeOrigin, secondsFromNow, ref tempPoseActionData, poseActionData_size, inputSourceHandle); if (err != EVRInputError.None) { Debug.LogError("<b>[SteamVR]</b> GetPoseActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); //todo: this should be an error velocityAtTime = Vector3.zero; angularVelocityAtTime = Vector3.zero; positionAtTime = Vector3.zero; rotationAtTime = Quaternion.identity; return(false); } velocityAtTime = GetUnityCoordinateVelocity(tempPoseActionData.pose.vVelocity); angularVelocityAtTime = GetUnityCoordinateAngularVelocity(tempPoseActionData.pose.vAngularVelocity); positionAtTime = SteamVR_Utils.GetPosition(tempPoseActionData.pose.mDeviceToAbsoluteTracking); rotationAtTime = SteamVR_Utils.GetRotation(tempPoseActionData.pose.mDeviceToAbsoluteTracking); return(true); }
/// <summary> /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive. /// </summary> /// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param> public bool GetPoseAtTimeOffset(SteamVR_Input_Sources inputSource, float secondsFromNow, out Vector3 position, out Quaternion rotation, out Vector3 velocity, out Vector3 angularVelocity) { EVRInputError err = OpenVR.Input.GetPoseActionData(handle, universeOrigin, secondsFromNow, ref tempPoseActionData, poseActionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { if (err == EVRInputError.InvalidHandle) { //todo: ignoring this error for now since it throws while the dashboard is up } else { Debug.LogError("GetPoseActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); //todo: this should be an error } velocity = Vector3.zero; angularVelocity = Vector3.zero; position = Vector3.zero; rotation = Quaternion.identity; return(false); } velocity = new Vector3(tempPoseActionData.pose.vVelocity.v0, tempPoseActionData.pose.vVelocity.v1, -tempPoseActionData.pose.vVelocity.v2); angularVelocity = new Vector3(-tempPoseActionData.pose.vAngularVelocity.v0, -tempPoseActionData.pose.vAngularVelocity.v1, tempPoseActionData.pose.vAngularVelocity.v2); position = SteamVR_Utils.GetPosition(tempPoseActionData.pose.mDeviceToAbsoluteTracking); rotation = SteamVR_Utils.GetRotation(tempPoseActionData.pose.mDeviceToAbsoluteTracking); return(true); }
protected void SetCacheVariables() { localPosition = SteamVR_Utils.GetPosition(poseActionData.pose.mDeviceToAbsoluteTracking); localRotation = SteamVR_Utils.GetRotation(poseActionData.pose.mDeviceToAbsoluteTracking); velocity = GetUnityCoordinateVelocity(poseActionData.pose.vVelocity); angularVelocity = GetUnityCoordinateAngularVelocity(poseActionData.pose.vAngularVelocity); updateTime = Time.realtimeSinceStartup; }
public void UpdateComponents(CVRRenderModels renderModels) { if (renderModels == null) { return; } if (transform.childCount == 0) { return; } if (nameCache == null) { nameCache = new Dictionary <int, string>(); } for (int childIndex = 0; childIndex < transform.childCount; childIndex++) { Transform child = transform.GetChild(childIndex); // Cache names since accessing an object's name allocate memory. string componentName; if (!nameCache.TryGetValue(child.GetInstanceID(), out componentName)) { componentName = child.name; nameCache.Add(child.GetInstanceID(), componentName); } var componentState = new RenderModel_ComponentState_t(); if (!renderModels.GetComponentStateForDevicePath(renderModelName, componentName, SteamVR_Input_Source.GetHandle(inputSource), ref controllerModeState, ref componentState)) { continue; } child.localPosition = SteamVR_Utils.GetPosition(componentState.mTrackingToComponentRenderModel); child.localRotation = SteamVR_Utils.GetRotation(componentState.mTrackingToComponentRenderModel); Transform attach = null; for (int childChildIndex = 0; childChildIndex < child.childCount; childChildIndex++) { Transform childChild = child.GetChild(childChildIndex); int childInstanceID = childChild.GetInstanceID(); string childName; if (!nameCache.TryGetValue(childInstanceID, out childName)) { childName = childChild.name; nameCache.Add(childInstanceID, componentName); } if (childName == SteamVR_RenderModel.k_localTransformName) { attach = childChild; } } if (attach != null) { attach.position = transform.TransformPoint(SteamVR_Utils.GetPosition(componentState.mTrackingToComponentLocal)); attach.rotation = transform.rotation * SteamVR_Utils.GetRotation(componentState.mTrackingToComponentLocal); initializedAttachPoints = true; } bool visible = (componentState.uProperties & (uint)EVRComponentProperty.IsVisible) != 0; if (visible != child.gameObject.activeSelf) { child.gameObject.SetActive(visible); } } }
/// <summary>The last local rotation of the pose relative to the center of the tracked space.</summary> /// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param> public Quaternion GetLastLocalRotation(SteamVR_Input_Sources inputSource) { return(SteamVR_Utils.GetRotation(lastPoseActionData[inputSource].pose.mDeviceToAbsoluteTracking)); }