------------------------------------------------------------------------------
| 131 | |
| 132 | //------------------------------------------------------------------------------ |
| 133 | void vtkOpenVRRenderWindow::UpdateHMDMatrixPose() |
| 134 | { |
| 135 | if (!this->HMD) |
| 136 | { |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | // Retrieve Open VR poses |
| 141 | vr::VRCompositor()->WaitGetPoses( |
| 142 | this->OpenVRTrackedDevicePoses, vr::k_unMaxTrackedDeviceCount, nullptr, 0); |
| 143 | |
| 144 | // Store poses with generic type |
| 145 | for (uint32_t deviceIdx = 0; deviceIdx < vr::k_unMaxTrackedDeviceCount; ++deviceIdx) |
| 146 | { |
| 147 | if (this->OpenVRTrackedDevicePoses[deviceIdx].bPoseIsValid) |
| 148 | { |
| 149 | auto handle = this->GetDeviceHandleForOpenVRHandle(deviceIdx); |
| 150 | auto device = this->GetDeviceForOpenVRHandle(deviceIdx); |
| 151 | this->AddDeviceHandle(handle, device); |
| 152 | vtkMatrix4x4* tdPose = this->GetDeviceToPhysicalMatrixForDeviceHandle(handle); |
| 153 | this->SetMatrixFromOpenVRPose(tdPose, this->OpenVRTrackedDevicePoses[deviceIdx]); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // update the camera values based on the pose |
| 158 | auto hmdHandle = this->GetDeviceHandleForOpenVRHandle(vr::k_unTrackedDeviceIndex_Hmd); |
| 159 | vtkNew<vtkMatrix4x4> d2wMat; |
| 160 | this->GetDeviceToWorldMatrixForDeviceHandle(hmdHandle, d2wMat); |
| 161 | |
| 162 | vtkRenderer* ren; |
| 163 | vtkCollectionSimpleIterator rit; |
| 164 | this->Renderers->InitTraversal(rit); |
| 165 | while ((ren = this->Renderers->GetNextRenderer(rit))) |
| 166 | { |
| 167 | vtkVRCamera* cam = vtkVRCamera::SafeDownCast(ren->GetActiveCamera()); |
| 168 | if (cam && cam->GetTrackHMD()) |
| 169 | { |
| 170 | cam->SetCameraFromDeviceToWorldMatrix(d2wMat, this->GetPhysicalScale()); |
| 171 | if (ren->GetLightFollowCamera()) |
| 172 | { |
| 173 | ren->UpdateLightsGeometryToFollowCamera(); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | //------------------------------------------------------------------------------ |
| 180 | void vtkOpenVRRenderWindow::SetMatrixFromOpenVRPose( |
no test coverage detected