Hi,
I was wondering if anyone has a solid solution for ray-casting from the center of the HMD? I can ray cast from the center of a regular camera and get a pixel-perfect hit on an object and render a decal where the trace hits. The same code fails when rendering in stereo as the center seems to get further and further away from the cursor I'm drawing in the HUD depending on whether I'm looking up, down, left or right. I've tried using: GetPositionalTrackingCameraProperties and getting the OutOrigin and using that as the start of my trace, then using a combination of OutOrientation rotating a vector as well as OutOrigin+cameraManager->GetCameraLocation()... it gets me reasonably close to a hit, but as I'm tracing on a surface I can clearly see the drift.
My HUD cursor is the standard sample code where you get the screen dimensions, divide by two and render a cursor in the center. I don't know if this is the right solution for VR but that seems to produce a solid cursor in the middle of the screen, but I can't trace from there. I've also tried this to get a hit from the center of the screen to see if that would help but I think it is offset b/c of the VR rendering as well.
I was wondering if anyone has a solid solution for ray-casting from the center of the HMD? I can ray cast from the center of a regular camera and get a pixel-perfect hit on an object and render a decal where the trace hits. The same code fails when rendering in stereo as the center seems to get further and further away from the cursor I'm drawing in the HUD depending on whether I'm looking up, down, left or right. I've tried using: GetPositionalTrackingCameraProperties and getting the OutOrigin and using that as the start of my trace, then using a combination of OutOrientation rotating a vector as well as OutOrigin+cameraManager->GetCameraLocation()... it gets me reasonably close to a hit, but as I'm tracing on a surface I can clearly see the drift.
Code:
FVector CameraOrigin; FQuat OutOrientation; float OutHFOV, OutVFOV, OutCameraDistance, OutNearPlane, OutFarPlane; hmd->GetPositionalTrackingCameraProperties(CameraOrigin, OutOrientation, OutHFOV, OutVFOV, OutCameraDistance, OutNearPlane, OutFarPlane); FVector start = CameraOrigin; FVector end = CameraOrigin + cameraManager->GetCameraLocation() + OutOrientation.RotateVector(FVector(0, 1, 0))*1000000.0;
My HUD cursor is the standard sample code where you get the screen dimensions, divide by two and render a cursor in the center. I don't know if this is the right solution for VR but that seems to produce a solid cursor in the middle of the screen, but I can't trace from there. I've also tried this to get a hit from the center of the screen to see if that would help but I think it is offset b/c of the VR rendering as well.
Code:
const FVector2D ViewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY()); const FVector2D ViewportCenter = FVector2D(ViewportSize.X/2, ViewportSize.Y/2); playerController->GetHitResultAtScreenPosition(ViewportCenter, UEngineTypes::ConvertToTraceType(ECC_Camera), true, OutHitResult);
Comment