| 109 | } |
| 110 | |
| 111 | unsigned int InputManager::SpaceRelationToPoseState(const XrSpaceLocation& location, double time, ovrPoseStatef& lastPoseState, ovrPoseStatef& outPoseState) |
| 112 | { |
| 113 | unsigned int flags = 0; |
| 114 | |
| 115 | if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) |
| 116 | { |
| 117 | outPoseState.ThePose.Orientation = XR::Quatf(location.pose.orientation); |
| 118 | flags |= ovrStatus_OrientationValid; |
| 119 | flags |= (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) ? ovrStatus_OrientationTracked : 0; |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | outPoseState.ThePose.Orientation = XR::Quatf::Identity(); |
| 124 | } |
| 125 | |
| 126 | if (location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) |
| 127 | { |
| 128 | outPoseState.ThePose.Position = XR::Vector3f(location.pose.position); |
| 129 | flags |= ovrStatus_PositionValid; |
| 130 | flags |= (location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) ? ovrStatus_PositionTracked : 0; |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | outPoseState.ThePose.Position = XR::Vector3f::Zero(); |
| 135 | } |
| 136 | |
| 137 | XrSpaceVelocity *spaceVelocity = (XrSpaceVelocity *) location.next; |
| 138 | |
| 139 | if (spaceVelocity->velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) |
| 140 | { |
| 141 | XR::Vector3f currav(spaceVelocity->angularVelocity); |
| 142 | XR::Vector3f lastav(lastPoseState.AngularVelocity); |
| 143 | outPoseState.AngularVelocity = currav; |
| 144 | outPoseState.AngularAcceleration = time > lastPoseState.TimeInSeconds ? |
| 145 | (currav - lastav) / float(time - lastPoseState.TimeInSeconds) : lastPoseState.AngularAcceleration; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | outPoseState.AngularVelocity = XR::Vector3f::Zero(); |
| 150 | outPoseState.AngularAcceleration = XR::Vector3f::Zero(); |
| 151 | } |
| 152 | |
| 153 | if (spaceVelocity->velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) |
| 154 | { |
| 155 | XR::Vector3f currlv(spaceVelocity->linearVelocity); |
| 156 | XR::Vector3f lastlv(lastPoseState.LinearVelocity); |
| 157 | outPoseState.LinearVelocity = currlv; |
| 158 | outPoseState.LinearAcceleration = time > lastPoseState.TimeInSeconds ? |
| 159 | (currlv - lastlv) / float(time - lastPoseState.TimeInSeconds) : lastPoseState.LinearAcceleration; |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | outPoseState.LinearVelocity = XR::Vector3f::Zero(); |
| 164 | outPoseState.LinearAcceleration = XR::Vector3f::Zero(); |
| 165 | } |
| 166 | |
| 167 | outPoseState.TimeInSeconds = time; |
| 168 | |