MCPcopy Create free account
hub / github.com/LibreVR/Revive / ovr_TestBoundaryPoint

Function ovr_TestBoundaryPoint

Revive/REV_CAPI.cpp:641–688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

639}
640
641OVR_PUBLIC_FUNCTION(ovrResult) ovr_TestBoundaryPoint(ovrSession session, const ovrVector3f* point,
642 ovrBoundaryType singleBoundaryType, ovrBoundaryTestResult* outTestResult)
643{
644 REV_TRACE(ovr_TestBoundaryPoint);
645
646 ovrBoundaryTestResult result = { 0 };
647
648 if (vr::VRChaperone()->GetCalibrationState() != vr::ChaperoneCalibrationState_OK)
649 return ovrSuccess_BoundaryInvalid;
650
651 result.IsTriggering = vr::VRChaperone()->AreBoundsVisible();
652
653 OVR::Vector2f playArea;
654 if (!vr::VRChaperone()->GetPlayAreaSize(&playArea.x, &playArea.y))
655 return ovrSuccess_BoundaryInvalid;
656
657 // Clamp the point to the AABB
658 OVR::Vector2f p(point->x, point->z);
659 OVR::Vector2f halfExtents(playArea.x / 2.0f, playArea.y / 2.0f);
660 OVR::Vector2f clamped = OVR::Vector2f::Min(OVR::Vector2f::Max(p, -halfExtents), halfExtents);
661
662 // If the point is inside the AABB, we need to do some extra work
663 if (clamped.Compare(p))
664 {
665 if (std::abs(p.x) > std::abs(p.y))
666 clamped.x = halfExtents.x * (p.x / std::abs(p.x));
667 else
668 clamped.y = halfExtents.y * (p.y / std::abs(p.y));
669 }
670
671 // We don't have a ceiling, use the height from the original point
672 result.ClosestPoint.x = clamped.x;
673 result.ClosestPoint.y = point->y;
674 result.ClosestPoint.z = clamped.y;
675
676 // Get the normal, closest distance is the length of this normal
677 OVR::Vector2f normal = p - clamped;
678 result.ClosestDistance = normal.Length();
679
680 // Normalize the normal
681 normal.Normalize();
682 result.ClosestPointNormal.x = normal.x;
683 result.ClosestPointNormal.y = 0.0f;
684 result.ClosestPointNormal.z = normal.y;
685
686 *outTestResult = result;
687 return ovrSuccess;
688}
689
690OVR_PUBLIC_FUNCTION(ovrResult) ovr_SetBoundaryLookAndFeel(ovrSession session, const ovrBoundaryLookAndFeel* lookAndFeel)
691{

Callers 1

ovr_TestBoundaryFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected