summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc')
-rw-r--r--chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc65
1 files changed, 29 insertions, 36 deletions
diff --git a/chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc b/chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc
index bef36eb3ffc..e0b47c1aea7 100644
--- a/chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc
+++ b/chromium/third_party/blink/renderer/modules/xr/xr_bounded_reference_space.cc
@@ -15,6 +15,10 @@
namespace blink {
namespace {
+
+// Bounds must be a valid polygon (at least 3 vertices).
+constexpr wtf_size_t kMinimumNumberOfBoundVertices = 3;
+
float RoundCm(float val) {
// Float round will only round to the nearest whole number. In order to get
// two decimal points of precision, we need to move the decimal out then
@@ -38,12 +42,6 @@ XRBoundedReferenceSpace::XRBoundedReferenceSpace(
XRBoundedReferenceSpace::~XRBoundedReferenceSpace() = default;
-// No default pose for bounded reference spaces.
-std::unique_ptr<TransformationMatrix>
-XRBoundedReferenceSpace::DefaultViewerPose() {
- return nullptr;
-}
-
void XRBoundedReferenceSpace::EnsureUpdated() {
// Check first to see if the stage parameters have updated since the last
// call. We only need to update the transform and bounds if it has.
@@ -57,57 +55,52 @@ void XRBoundedReferenceSpace::EnsureUpdated() {
if (display_info && display_info->stage_parameters) {
// Use the transform given by xrDisplayInfo's stage_parameters if available.
- bounded_space_from_mojo_ = std::make_unique<TransformationMatrix>(
+ bounded_native_from_mojo_ = std::make_unique<TransformationMatrix>(
display_info->stage_parameters->standing_transform.matrix());
// In order to ensure that the bounds continue to line up with the user's
- // physical environment we need to transform by the inverse of the
- // originOffset. TODO(https://crbug.com/1008466): move originOffset to
- // separate class? If yes, that class would need to apply a transform
- // in the boundsGeometry accessor.
- TransformationMatrix bounds_transform = InverseOriginOffsetMatrix();
+ // physical environment we need to transform them from native to offset.
+ // Bounds are provided in our native coordinate space.
+ // TODO(https://crbug.com/1008466): move originOffset to separate class? If
+ // yes, that class would need to apply a transform in the boundsGeometry
+ // accessor.
+ TransformationMatrix offset_from_native = OffsetFromNativeMatrix();
// We may not have bounds if we've lost tracking after being created.
// Whether we have them or not, we need to clear the existing bounds.
- bounds_geometry_.clear();
- if (display_info->stage_parameters->bounds) {
+ offset_bounds_geometry_.clear();
+ if (display_info->stage_parameters->bounds &&
+ display_info->stage_parameters->bounds->size() >=
+ kMinimumNumberOfBoundVertices) {
for (const auto& bound : *(display_info->stage_parameters->bounds)) {
- FloatPoint3D p =
- bounds_transform.MapPoint(FloatPoint3D(bound.X(), 0.0, bound.Z()));
- bounds_geometry_.push_back(RoundedDOMPoint(p));
+ FloatPoint3D p = offset_from_native.MapPoint(
+ FloatPoint3D(bound.x(), 0.0, bound.z()));
+ offset_bounds_geometry_.push_back(RoundedDOMPoint(p));
}
}
} else {
// If stage parameters aren't available set the transform to null, which
// will subsequently cause this reference space to return null poses.
- bounded_space_from_mojo_.reset();
- bounds_geometry_.clear();
+ bounded_native_from_mojo_.reset();
+ offset_bounds_geometry_.clear();
}
DispatchEvent(*XRReferenceSpaceEvent::Create(event_type_names::kReset, this));
}
-// Gets the pose of the mojo origin in this reference space, corresponding to a
-// transform from mojo coordinates to reference space coordinates. Ideally in
-// the future this reference space can be used without additional transforms,
-// with the various XR backends returning poses already in the right space.
-std::unique_ptr<TransformationMatrix> XRBoundedReferenceSpace::SpaceFromMojo(
- const TransformationMatrix& mojo_from_viewer) {
+std::unique_ptr<TransformationMatrix>
+XRBoundedReferenceSpace::NativeFromMojo() {
EnsureUpdated();
- // If the reference space has a transform apply it to the base pose and return
- // that, otherwise return null.
- if (bounded_space_from_mojo_) {
- std::unique_ptr<TransformationMatrix> space_from_mojo(
- std::make_unique<TransformationMatrix>(*bounded_space_from_mojo_));
- return space_from_mojo;
- }
- return nullptr;
+ if (!bounded_native_from_mojo_)
+ return nullptr;
+
+ return std::make_unique<TransformationMatrix>(*bounded_native_from_mojo_);
}
HeapVector<Member<DOMPointReadOnly>> XRBoundedReferenceSpace::boundsGeometry() {
EnsureUpdated();
- return bounds_geometry_;
+ return offset_bounds_geometry_;
}
base::Optional<XRNativeOriginInformation>
@@ -115,8 +108,8 @@ XRBoundedReferenceSpace::NativeOrigin() const {
return XRNativeOriginInformation::Create(this);
}
-void XRBoundedReferenceSpace::Trace(blink::Visitor* visitor) {
- visitor->Trace(bounds_geometry_);
+void XRBoundedReferenceSpace::Trace(Visitor* visitor) {
+ visitor->Trace(offset_bounds_geometry_);
XRReferenceSpace::Trace(visitor);
}