Commit 03abfbee authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Clarify XRSpace method's naming scheme

"Space" is a bit ambiguous, in order to remove some of this ambiguity,
explicitly refer to "Native" or "Offset", when referring to transforms.

Also renames OriginOffset to indicate what it is: OffsetFromNative.

Fixed: 1031600
Change-Id: I5863ac8a8c2bd81abd65e4ef17356de2c8891389
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1956109
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarPiotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722735}
parent d1fa2dfb
...@@ -51,56 +51,50 @@ void XRBoundedReferenceSpace::EnsureUpdated() { ...@@ -51,56 +51,50 @@ void XRBoundedReferenceSpace::EnsureUpdated() {
if (display_info && display_info->stage_parameters) { if (display_info && display_info->stage_parameters) {
// Use the transform given by xrDisplayInfo's stage_parameters if available. // 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()); display_info->stage_parameters->standing_transform.matrix());
// In order to ensure that the bounds continue to line up with the user's // 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 // physical environment we need to transform them from native to offset.
// originOffset. TODO(https://crbug.com/1008466): move originOffset to // Bounds are provided in our native coordinate space.
// separate class? If yes, that class would need to apply a transform // TODO(https://crbug.com/1008466): move originOffset to separate class? If
// in the boundsGeometry accessor. // yes, that class would need to apply a transform in the boundsGeometry
TransformationMatrix bounds_transform = InverseOriginOffsetMatrix(); // accessor.
TransformationMatrix offset_from_native = OffsetFromNativeMatrix();
// We may not have bounds if we've lost tracking after being created. // 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. // Whether we have them or not, we need to clear the existing bounds.
bounds_geometry_.clear(); offset_bounds_geometry_.clear();
if (display_info->stage_parameters->bounds) { if (display_info->stage_parameters->bounds) {
for (const auto& bound : *(display_info->stage_parameters->bounds)) { for (const auto& bound : *(display_info->stage_parameters->bounds)) {
FloatPoint3D p = FloatPoint3D p = offset_from_native.MapPoint(
bounds_transform.MapPoint(FloatPoint3D(bound.X(), 0.0, bound.Z())); FloatPoint3D(bound.X(), 0.0, bound.Z()));
bounds_geometry_.push_back(RoundedDOMPoint(p)); offset_bounds_geometry_.push_back(RoundedDOMPoint(p));
} }
} }
} else { } else {
// If stage parameters aren't available set the transform to null, which // If stage parameters aren't available set the transform to null, which
// will subsequently cause this reference space to return null poses. // will subsequently cause this reference space to return null poses.
bounded_space_from_mojo_.reset(); bounded_native_from_mojo_.reset();
bounds_geometry_.clear(); offset_bounds_geometry_.clear();
} }
DispatchEvent(*XRReferenceSpaceEvent::Create(event_type_names::kReset, this)); DispatchEvent(*XRReferenceSpaceEvent::Create(event_type_names::kReset, this));
} }
// Gets the pose of the mojo origin in this reference space, corresponding to a std::unique_ptr<TransformationMatrix>
// transform from mojo coordinates to reference space coordinates. Ideally in XRBoundedReferenceSpace::NativeFromMojo() {
// 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() {
EnsureUpdated(); EnsureUpdated();
// If the reference space has a transform apply it to the base pose and return if (!bounded_native_from_mojo_)
// that, otherwise return null. return nullptr;
if (bounded_space_from_mojo_) {
std::unique_ptr<TransformationMatrix> space_from_mojo( return std::make_unique<TransformationMatrix>(*bounded_native_from_mojo_);
std::make_unique<TransformationMatrix>(*bounded_space_from_mojo_));
return space_from_mojo;
}
return nullptr;
} }
HeapVector<Member<DOMPointReadOnly>> XRBoundedReferenceSpace::boundsGeometry() { HeapVector<Member<DOMPointReadOnly>> XRBoundedReferenceSpace::boundsGeometry() {
EnsureUpdated(); EnsureUpdated();
return bounds_geometry_; return offset_bounds_geometry_;
} }
base::Optional<XRNativeOriginInformation> base::Optional<XRNativeOriginInformation>
...@@ -109,7 +103,7 @@ XRBoundedReferenceSpace::NativeOrigin() const { ...@@ -109,7 +103,7 @@ XRBoundedReferenceSpace::NativeOrigin() const {
} }
void XRBoundedReferenceSpace::Trace(blink::Visitor* visitor) { void XRBoundedReferenceSpace::Trace(blink::Visitor* visitor) {
visitor->Trace(bounds_geometry_); visitor->Trace(offset_bounds_geometry_);
XRReferenceSpace::Trace(visitor); XRReferenceSpace::Trace(visitor);
} }
......
...@@ -19,7 +19,7 @@ class XRBoundedReferenceSpace final : public XRReferenceSpace { ...@@ -19,7 +19,7 @@ class XRBoundedReferenceSpace final : public XRReferenceSpace {
XRBoundedReferenceSpace(XRSession*, XRRigidTransform*); XRBoundedReferenceSpace(XRSession*, XRRigidTransform*);
~XRBoundedReferenceSpace() override; ~XRBoundedReferenceSpace() override;
std::unique_ptr<TransformationMatrix> SpaceFromMojo() override; std::unique_ptr<TransformationMatrix> NativeFromMojo() override;
HeapVector<Member<DOMPointReadOnly>> boundsGeometry(); HeapVector<Member<DOMPointReadOnly>> boundsGeometry();
...@@ -35,8 +35,8 @@ class XRBoundedReferenceSpace final : public XRReferenceSpace { ...@@ -35,8 +35,8 @@ class XRBoundedReferenceSpace final : public XRReferenceSpace {
void EnsureUpdated(); void EnsureUpdated();
HeapVector<Member<DOMPointReadOnly>> bounds_geometry_; HeapVector<Member<DOMPointReadOnly>> offset_bounds_geometry_;
std::unique_ptr<TransformationMatrix> bounded_space_from_mojo_; std::unique_ptr<TransformationMatrix> bounded_native_from_mojo_;
unsigned int stage_parameters_id_ = 0; unsigned int stage_parameters_id_ = 0;
}; };
......
...@@ -72,15 +72,16 @@ XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space, ...@@ -72,15 +72,16 @@ XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space,
session_->LogGetPose(); session_->LogGetPose();
std::unique_ptr<TransformationMatrix> pose = std::unique_ptr<TransformationMatrix> offset_space_from_viewer =
reference_space->OffsetSpaceFromViewer(); reference_space->OffsetFromViewer();
// Can only update an XRViewerPose's views with an invertible matrix. // Can only update an XRViewerPose's views with an invertible matrix.
if (!(pose && pose->IsInvertible())) { if (!(offset_space_from_viewer && offset_space_from_viewer->IsInvertible())) {
return nullptr; return nullptr;
} }
return MakeGarbageCollected<XRViewerPose>(session(), *pose); return MakeGarbageCollected<XRViewerPose>(session(),
*offset_space_from_viewer);
} }
XRAnchorSet* XRFrame::trackedAnchors() const { XRAnchorSet* XRFrame::trackedAnchors() const {
......
...@@ -14,7 +14,7 @@ namespace blink { ...@@ -14,7 +14,7 @@ namespace blink {
XRGripSpace::XRGripSpace(XRSession* session, XRInputSource* source) XRGripSpace::XRGripSpace(XRSession* session, XRInputSource* source)
: XRSpace(session), input_source_(source) {} : XRSpace(session), input_source_(source) {}
std::unique_ptr<TransformationMatrix> XRGripSpace::MojoFromSpace() { std::unique_ptr<TransformationMatrix> XRGripSpace::MojoFromNative() {
// Grip is only available when using tracked pointer for input. // Grip is only available when using tracked pointer for input.
if (input_source_->TargetRayMode() != if (input_source_->TargetRayMode() !=
device::mojom::XRTargetRayMode::POINTING) { device::mojom::XRTargetRayMode::POINTING) {
...@@ -28,8 +28,8 @@ std::unique_ptr<TransformationMatrix> XRGripSpace::MojoFromSpace() { ...@@ -28,8 +28,8 @@ std::unique_ptr<TransformationMatrix> XRGripSpace::MojoFromSpace() {
*(input_source_->MojoFromInput())); *(input_source_->MojoFromInput()));
} }
std::unique_ptr<TransformationMatrix> XRGripSpace::SpaceFromMojo() { std::unique_ptr<TransformationMatrix> XRGripSpace::NativeFromMojo() {
return TryInvert(MojoFromSpace()); return TryInvert(MojoFromNative());
} }
bool XRGripSpace::EmulatedPosition() const { bool XRGripSpace::EmulatedPosition() const {
......
...@@ -15,8 +15,8 @@ class XRGripSpace : public XRSpace { ...@@ -15,8 +15,8 @@ class XRGripSpace : public XRSpace {
public: public:
XRGripSpace(XRSession* session, XRInputSource* input_source); XRGripSpace(XRSession* session, XRInputSource* input_source);
std::unique_ptr<TransformationMatrix> MojoFromSpace() override; std::unique_ptr<TransformationMatrix> MojoFromNative() override;
std::unique_ptr<TransformationMatrix> SpaceFromMojo() override; std::unique_ptr<TransformationMatrix> NativeFromMojo() override;
bool EmulatedPosition() const override; bool EmulatedPosition() const override;
base::Optional<XRNativeOriginInformation> NativeOrigin() const override; base::Optional<XRNativeOriginInformation> NativeOrigin() const override;
......
...@@ -14,11 +14,11 @@ XRHitTestResult::XRHitTestResult(const TransformationMatrix& pose) ...@@ -14,11 +14,11 @@ XRHitTestResult::XRHitTestResult(const TransformationMatrix& pose)
: pose_(std::make_unique<TransformationMatrix>(pose)) {} : pose_(std::make_unique<TransformationMatrix>(pose)) {}
XRPose* XRHitTestResult::getPose(XRSpace* relative_to) { XRPose* XRHitTestResult::getPose(XRSpace* relative_to) {
DCHECK(relative_to->MojoFromSpace()); DCHECK(relative_to->MojoFromNative());
auto mojo_from_this = *pose_; auto mojo_from_this = *pose_;
auto mojo_from_other = *relative_to->MojoFromSpace(); auto mojo_from_other = *relative_to->MojoFromNative();
DCHECK(mojo_from_other.IsInvertible()); DCHECK(mojo_from_other.IsInvertible());
auto other_from_mojo = mojo_from_other.Inverse(); auto other_from_mojo = mojo_from_other.Inverse();
......
...@@ -21,7 +21,7 @@ class XRObjectSpace : public XRSpace { ...@@ -21,7 +21,7 @@ class XRObjectSpace : public XRSpace {
explicit XRObjectSpace(XRSession* session, const T* object) explicit XRObjectSpace(XRSession* session, const T* object)
: XRSpace(session), object_(object) {} : XRSpace(session), object_(object) {}
std::unique_ptr<TransformationMatrix> MojoFromSpace() override { std::unique_ptr<TransformationMatrix> MojoFromNative() override {
auto object_from_mojo = object_->poseMatrix(); auto object_from_mojo = object_->poseMatrix();
if (!object_from_mojo.IsInvertible()) { if (!object_from_mojo.IsInvertible()) {
...@@ -31,8 +31,8 @@ class XRObjectSpace : public XRSpace { ...@@ -31,8 +31,8 @@ class XRObjectSpace : public XRSpace {
return std::make_unique<TransformationMatrix>(object_from_mojo.Inverse()); return std::make_unique<TransformationMatrix>(object_from_mojo.Inverse());
} }
std::unique_ptr<TransformationMatrix> SpaceFromMojo() final { std::unique_ptr<TransformationMatrix> NativeFromMojo() final {
return TryInvert(MojoFromSpace()); return TryInvert(MojoFromNative());
} }
base::Optional<XRNativeOriginInformation> NativeOrigin() const override { base::Optional<XRNativeOriginInformation> NativeOrigin() const override {
......
...@@ -48,18 +48,18 @@ XRReferenceSpace::~XRReferenceSpace() = default; ...@@ -48,18 +48,18 @@ XRReferenceSpace::~XRReferenceSpace() = default;
XRPose* XRReferenceSpace::getPose(XRSpace* other_space) { XRPose* XRReferenceSpace::getPose(XRSpace* other_space) {
if (type_ == Type::kTypeViewer) { if (type_ == Type::kTypeViewer) {
std::unique_ptr<TransformationMatrix> other_offsetspace_from_viewer = std::unique_ptr<TransformationMatrix> other_offset_from_viewer =
other_space->OffsetSpaceFromViewer(); other_space->OffsetFromViewer();
if (!other_offsetspace_from_viewer) { if (!other_offset_from_viewer) {
return nullptr; return nullptr;
} }
auto viewer_from_offset = OriginOffsetMatrix(); auto viewer_from_offset = NativeFromOffsetMatrix();
auto other_offsetspace_from_offset = auto other_offset_from_offset =
*other_offsetspace_from_viewer * viewer_from_offset; *other_offset_from_viewer * viewer_from_offset;
return MakeGarbageCollected<XRPose>(other_offsetspace_from_offset, return MakeGarbageCollected<XRPose>(other_offset_from_offset,
session()->EmulatedPosition()); session()->EmulatedPosition());
} else { } else {
return XRSpace::getPose(other_space); return XRSpace::getPose(other_space);
...@@ -83,7 +83,7 @@ void XRReferenceSpace::SetFloorFromMojo() { ...@@ -83,7 +83,7 @@ void XRReferenceSpace::SetFloorFromMojo() {
display_info_id_ = session()->DisplayInfoPtrId(); display_info_id_ = session()->DisplayInfoPtrId();
} }
std::unique_ptr<TransformationMatrix> XRReferenceSpace::SpaceFromMojo() { std::unique_ptr<TransformationMatrix> XRReferenceSpace::NativeFromMojo() {
auto mojo_from_viewer = session()->MojoFromViewer(); auto mojo_from_viewer = session()->MojoFromViewer();
switch (type_) { switch (type_) {
case Type::kTypeLocal: case Type::kTypeLocal:
...@@ -121,15 +121,12 @@ std::unique_ptr<TransformationMatrix> XRReferenceSpace::SpaceFromMojo() { ...@@ -121,15 +121,12 @@ std::unique_ptr<TransformationMatrix> XRReferenceSpace::SpaceFromMojo() {
return nullptr; return nullptr;
} }
// Returns the refspace-from-viewerspace transform, corresponding to the pose of std::unique_ptr<TransformationMatrix> XRReferenceSpace::NativeFromViewer(
// the viewer in this space. This takes the mojo_from_viewer transform (viewer
// pose in mojo space) as input, and left-multiplies space_from_mojo onto that.
std::unique_ptr<TransformationMatrix> XRReferenceSpace::SpaceFromViewer(
const TransformationMatrix* mojo_from_viewer) { const TransformationMatrix* mojo_from_viewer) {
if (type_ == Type::kTypeViewer) { if (type_ == Type::kTypeViewer) {
// Special case for viewer space, always return an identity matrix // Special case for viewer space, always return an identity matrix
// explicitly. In theory the default behavior of multiplying SpaceFromMojo * // explicitly. In theory the default behavior of multiplying NativeFromMojo
// MojoFromViewer would be equivalent, but that would likely return an // onto MojoFromViewer would be equivalent, but that would likely return an
// almost-identity due to rounding errors. // almost-identity due to rounding errors.
return std::make_unique<TransformationMatrix>(); return std::make_unique<TransformationMatrix>();
} }
...@@ -137,23 +134,23 @@ std::unique_ptr<TransformationMatrix> XRReferenceSpace::SpaceFromViewer( ...@@ -137,23 +134,23 @@ std::unique_ptr<TransformationMatrix> XRReferenceSpace::SpaceFromViewer(
if (!mojo_from_viewer) if (!mojo_from_viewer)
return nullptr; return nullptr;
// Return space_from_viewer = space_from_mojo * mojo_from_viewer // Return native_from_viewer = native_from_mojo * mojo_from_viewer
auto space_from_viewer = SpaceFromMojo(); auto native_from_viewer = NativeFromMojo();
if (!space_from_viewer) if (!native_from_viewer)
return nullptr; return nullptr;
space_from_viewer->Multiply(*mojo_from_viewer); native_from_viewer->Multiply(*mojo_from_viewer);
return space_from_viewer; return native_from_viewer;
} }
std::unique_ptr<TransformationMatrix> XRReferenceSpace::MojoFromSpace() { std::unique_ptr<TransformationMatrix> XRReferenceSpace::MojoFromNative() {
return TryInvert(SpaceFromMojo()); return TryInvert(NativeFromMojo());
} }
TransformationMatrix XRReferenceSpace::OriginOffsetMatrix() { TransformationMatrix XRReferenceSpace::NativeFromOffsetMatrix() {
return origin_offset_->TransformMatrix(); return origin_offset_->TransformMatrix();
} }
TransformationMatrix XRReferenceSpace::InverseOriginOffsetMatrix() { TransformationMatrix XRReferenceSpace::OffsetFromNativeMatrix() {
return origin_offset_->InverseTransformMatrix(); return origin_offset_->InverseTransformMatrix();
} }
...@@ -164,7 +161,7 @@ XRReferenceSpace::Type XRReferenceSpace::GetType() const { ...@@ -164,7 +161,7 @@ XRReferenceSpace::Type XRReferenceSpace::GetType() const {
XRReferenceSpace* XRReferenceSpace::getOffsetReferenceSpace( XRReferenceSpace* XRReferenceSpace::getOffsetReferenceSpace(
XRRigidTransform* additional_offset) { XRRigidTransform* additional_offset) {
auto matrix = auto matrix =
OriginOffsetMatrix().Multiply(additional_offset->TransformMatrix()); NativeFromOffsetMatrix().Multiply(additional_offset->TransformMatrix());
auto* result_transform = MakeGarbageCollected<XRRigidTransform>(matrix); auto* result_transform = MakeGarbageCollected<XRRigidTransform>(matrix);
return cloneWithOriginOffset(result_transform); return cloneWithOriginOffset(result_transform);
......
...@@ -36,17 +36,17 @@ class XRReferenceSpace : public XRSpace { ...@@ -36,17 +36,17 @@ class XRReferenceSpace : public XRSpace {
Type type); Type type);
~XRReferenceSpace() override; ~XRReferenceSpace() override;
std::unique_ptr<TransformationMatrix> SpaceFromMojo() override; std::unique_ptr<TransformationMatrix> NativeFromMojo() override;
std::unique_ptr<TransformationMatrix> SpaceFromViewer( std::unique_ptr<TransformationMatrix> NativeFromViewer(
const TransformationMatrix* mojo_from_viewer) override; const TransformationMatrix* mojo_from_viewer) override;
// MojoFromSpace is final to enforce that children should be returning // MojoFromNative is final to enforce that children should be returning
// SpaceFromMojo, since this is simply written to always provide the inverse // NativeFromMojo, since this is simply written to always provide the inverse
// of SpaceFromMojo // of NativeFromMojo
std::unique_ptr<TransformationMatrix> MojoFromSpace() final; std::unique_ptr<TransformationMatrix> MojoFromNative() final;
TransformationMatrix OriginOffsetMatrix() override; TransformationMatrix NativeFromOffsetMatrix() override;
TransformationMatrix InverseOriginOffsetMatrix() override; TransformationMatrix OffsetFromNativeMatrix() override;
// We override getPose to ensure that the viewer pose in viewer space returns // We override getPose to ensure that the viewer pose in viewer space returns
// the identity pose instead of the result of multiplying inverse matrices. // the identity pose instead of the result of multiplying inverse matrices.
......
...@@ -576,28 +576,28 @@ ScriptPromise XRSession::CreateAnchor(ScriptState* script_state, ...@@ -576,28 +576,28 @@ ScriptPromise XRSession::CreateAnchor(ScriptState* script_state,
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
// Transformation from passed in |space| to mojo space. // Transformation from passed in |space| to mojo space.
std::unique_ptr<TransformationMatrix> mojo_from_space = std::unique_ptr<TransformationMatrix> mojo_from_native =
space->MojoFromSpace(); space->MojoFromNative();
DVLOG(3) << __func__ DVLOG(3) << __func__
<< ": mojo_from_space = " << mojo_from_space->ToString(true); << ": mojo_from_native = " << mojo_from_native->ToString(true);
// Matrix will be null if transformation from object space to mojo space is // Matrix will be null if transformation from object space to mojo space is
// not invertible, log & bail out in that case. // not invertible, log & bail out in that case.
if (!mojo_from_space || !mojo_from_space->IsInvertible()) { if (!mojo_from_native || !mojo_from_native->IsInvertible()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
kNonInvertibleMatrix); kNonInvertibleMatrix);
return ScriptPromise(); return ScriptPromise();
} }
auto space_from_mojo = mojo_from_space->Inverse(); auto native_from_mojo = mojo_from_native->Inverse();
DVLOG(3) << __func__ DVLOG(3) << __func__
<< ": space_from_mojo = " << space_from_mojo.ToString(true); << ": native_from_mojo = " << native_from_mojo.ToString(true);
// Transformation from passed in pose to |space|. // Transformation from passed in pose to |space|.
auto mojo_from_initial_pose = initial_pose->TransformMatrix(); auto mojo_from_initial_pose = initial_pose->TransformMatrix();
auto space_from_initial_pose = space_from_mojo * mojo_from_initial_pose; auto space_from_initial_pose = native_from_mojo * mojo_from_initial_pose;
DVLOG(3) << __func__ << ": mojo_from_initial_pose = " DVLOG(3) << __func__ << ": mojo_from_initial_pose = "
<< mojo_from_initial_pose.ToString(true); << mojo_from_initial_pose.ToString(true);
...@@ -741,11 +741,10 @@ ScriptPromise XRSession::requestHitTestSource( ...@@ -741,11 +741,10 @@ ScriptPromise XRSession::requestHitTestSource(
// 2. Convert the XRRay to be expressed in terms of passed in XRSpace. This // 2. Convert the XRRay to be expressed in terms of passed in XRSpace. This
// should only matter for spaces whose transforms are not fully known on the // should only matter for spaces whose transforms are not fully known on the
// device (for example any space containing origin-offset). // device (for example any space containing origin-offset).
TransformationMatrix origin_from_space = // Null checks not needed since native origin wouldn't be set if options_init
options_init->space() // or space() were null.
->OriginOffsetMatrix(); // Null checks not needed since native origin TransformationMatrix native_from_offset =
// wouldn't be set if options_init or space() options_init->space()->NativeFromOffsetMatrix();
// were null.
if (options_init->hasEntityTypes() && options_init->entityTypes().IsEmpty()) { if (options_init->hasEntityTypes() && options_init->entityTypes().IsEmpty()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
...@@ -756,7 +755,7 @@ ScriptPromise XRSession::requestHitTestSource( ...@@ -756,7 +755,7 @@ ScriptPromise XRSession::requestHitTestSource(
auto entity_types = GetEntityTypesForHitTest(options_init); auto entity_types = GetEntityTypesForHitTest(options_init);
DVLOG(3) << __func__ DVLOG(3) << __func__
<< ": origin_from_space = " << origin_from_space.ToString(true); << ": native_from_offset = " << native_from_offset.ToString(true);
// Transformation from passed in pose to |space|. // Transformation from passed in pose to |space|.
...@@ -764,7 +763,7 @@ ScriptPromise XRSession::requestHitTestSource( ...@@ -764,7 +763,7 @@ ScriptPromise XRSession::requestHitTestSource(
? options_init->offsetRay() ? options_init->offsetRay()
: MakeGarbageCollected<XRRay>(); : MakeGarbageCollected<XRRay>();
auto space_from_ray = offsetRay->RawMatrix(); auto space_from_ray = offsetRay->RawMatrix();
auto origin_from_ray = origin_from_space * space_from_ray; auto origin_from_ray = native_from_offset * space_from_ray;
DVLOG(3) << __func__ DVLOG(3) << __func__
<< ": space_from_ray = " << space_from_ray.ToString(true); << ": space_from_ray = " << space_from_ray.ToString(true);
......
...@@ -17,28 +17,28 @@ XRSpace::XRSpace(XRSession* session) : session_(session) {} ...@@ -17,28 +17,28 @@ XRSpace::XRSpace(XRSession* session) : session_(session) {}
XRSpace::~XRSpace() = default; XRSpace::~XRSpace() = default;
std::unique_ptr<TransformationMatrix> XRSpace::SpaceFromViewer( std::unique_ptr<TransformationMatrix> XRSpace::NativeFromViewer(
const TransformationMatrix* mojo_from_viewer) { const TransformationMatrix* mojo_from_viewer) {
if (!mojo_from_viewer) if (!mojo_from_viewer)
return nullptr; return nullptr;
std::unique_ptr<TransformationMatrix> space_from_mojo = SpaceFromMojo(); std::unique_ptr<TransformationMatrix> native_from_mojo = NativeFromMojo();
if (!space_from_mojo) if (!native_from_mojo)
return nullptr; return nullptr;
space_from_mojo->Multiply(*mojo_from_viewer); native_from_mojo->Multiply(*mojo_from_viewer);
// This is now space_from_viewer // This is now native_from_viewer
return space_from_mojo; return native_from_mojo;
; ;
} }
TransformationMatrix XRSpace::OriginOffsetMatrix() { TransformationMatrix XRSpace::NativeFromOffsetMatrix() {
TransformationMatrix identity; TransformationMatrix identity;
return identity; return identity;
} }
TransformationMatrix XRSpace::InverseOriginOffsetMatrix() { TransformationMatrix XRSpace::OffsetFromNativeMatrix() {
TransformationMatrix identity; TransformationMatrix identity;
return identity; return identity;
} }
...@@ -57,47 +57,45 @@ bool XRSpace::EmulatedPosition() const { ...@@ -57,47 +57,45 @@ bool XRSpace::EmulatedPosition() const {
} }
XRPose* XRSpace::getPose(XRSpace* other_space) { XRPose* XRSpace::getPose(XRSpace* other_space) {
std::unique_ptr<TransformationMatrix> mojo_from_space = MojoFromSpace(); // Named mojo_from_offset because that is what we will leave it as, though it
if (!mojo_from_space) { // starts mojo_from_native.
std::unique_ptr<TransformationMatrix> mojo_from_offset = MojoFromNative();
if (!mojo_from_offset) {
return nullptr; return nullptr;
} }
// Add any origin offset now. // Add any origin offset now.
mojo_from_space->Multiply(OriginOffsetMatrix()); mojo_from_offset->Multiply(NativeFromOffsetMatrix());
std::unique_ptr<TransformationMatrix> other_from_mojo = std::unique_ptr<TransformationMatrix> other_from_mojo =
other_space->SpaceFromMojo(); other_space->NativeFromMojo();
if (!other_from_mojo) if (!other_from_mojo)
return nullptr; return nullptr;
TransformationMatrix offset_other_from_mojo = // Add any origin offset from the other space now.
other_space->InverseOriginOffsetMatrix().Multiply(*other_from_mojo); TransformationMatrix other_offset_from_mojo =
other_space->OffsetFromNativeMatrix().Multiply(*other_from_mojo);
// TODO(crbug.com/969133): Update how EmulatedPosition is determined here once // TODO(crbug.com/969133): Update how EmulatedPosition is determined here once
// spec issue https://github.com/immersive-web/webxr/issues/534 has been // spec issue https://github.com/immersive-web/webxr/issues/534 has been
// resolved. // resolved.
TransformationMatrix other_from_space = TransformationMatrix other_offset_from_offset =
offset_other_from_mojo.Multiply(*mojo_from_space); other_offset_from_mojo.Multiply(*mojo_from_offset);
return MakeGarbageCollected<XRPose>( return MakeGarbageCollected<XRPose>(
other_from_space, EmulatedPosition() || other_space->EmulatedPosition()); other_offset_from_offset,
EmulatedPosition() || other_space->EmulatedPosition());
} }
std::unique_ptr<TransformationMatrix> XRSpace::OffsetSpaceFromViewer() { std::unique_ptr<TransformationMatrix> XRSpace::OffsetFromViewer() {
std::unique_ptr<TransformationMatrix> space_from_viewer = std::unique_ptr<TransformationMatrix> native_from_viewer =
SpaceFromViewer(base::OptionalOrNullptr(session()->MojoFromViewer())); NativeFromViewer(base::OptionalOrNullptr(session()->MojoFromViewer()));
if (!space_from_viewer) { if (!native_from_viewer) {
return nullptr; return nullptr;
} }
// Account for any changes made to the reference space's origin offset so that
// things like teleportation works.
//
// This is offset_from_viewer = offset_from_space * space_from_viewer,
// where offset_from_viewer = inverse(viewer_from_offset).
// TODO(https://crbug.com/1008466): move originOffset to separate class?
return std::make_unique<TransformationMatrix>( return std::make_unique<TransformationMatrix>(
InverseOriginOffsetMatrix().Multiply(*space_from_viewer)); OffsetFromNativeMatrix().Multiply(*native_from_viewer));
} }
ExecutionContext* XRSpace::GetExecutionContext() const { ExecutionContext* XRSpace::GetExecutionContext() const {
......
...@@ -32,27 +32,38 @@ class XRSpace : public EventTargetWithInlineData { ...@@ -32,27 +32,38 @@ class XRSpace : public EventTargetWithInlineData {
~XRSpace() override; ~XRSpace() override;
// Gets the pose of this space's native origin in mojo space. This transform // Gets the pose of this space's native origin in mojo space. This transform
// maps from this space to mojo space (aka device space). Unless noted // maps from this space's native origin to mojo space (aka device space).
// otherwise, all data returned over vr_service.mojom interfaces is expressed // Unless noted otherwise, all data returned over vr_service.mojom interfaces
// in mojo space coordinates. Returns nullptr if computing a transform is not // is expressed in mojo space coordinates.
// possible. // Returns nullptr if computing a transform is not possible.
virtual std::unique_ptr<TransformationMatrix> MojoFromSpace() = 0; virtual std::unique_ptr<TransformationMatrix> MojoFromNative() = 0;
// Gets the pose of the mojo origin in this reference space, corresponding // Convenience method to try to get the inverse of the above. This will return
// to a transform from mojo coordinates to reference space coordinates. // the pose of the mojo origin in this space's native origin.
// Note that it is expected to be the inverse of the above. // Returns nullptr if computing a transform is not possible.
virtual std::unique_ptr<TransformationMatrix> SpaceFromMojo() = 0; virtual std::unique_ptr<TransformationMatrix> NativeFromMojo() = 0;
// Gets the viewer pose in this space, corresponding to a transform from // Gets the viewer pose in the native coordinates of this space, corresponding
// viewer coordinates to this space's coordinates. (The position elements of // to a transform from viewer coordinates to this space's native coordinates.
// the transformation matrix are the viewer's location in this space's // (The position elements of the transformation matrix are the viewer's
// coordinates.) // location in this space's coordinates.)
// Prefer this helper method over querying SpaceFromMojo and multiplying // Prefer this helper method over querying NativeFromMojo and multiplying
// on the calling side, as this allows the viewer space to return identity // on the calling side, as this allows the viewer space to return identity
// instead of something near to, but not quite, identity. // instead of something near to, but not quite, identity.
virtual std::unique_ptr<TransformationMatrix> SpaceFromViewer( // Returns nullptr if computing a transform is not possible.
virtual std::unique_ptr<TransformationMatrix> NativeFromViewer(
const TransformationMatrix* mojo_from_viewer); const TransformationMatrix* mojo_from_viewer);
// Convenience method for calling NativeFromViewer with the current
// MojoFromViewer of the session associated with this space. This also handles
// the multiplication of OffsetFromNative onto the result of NativeFromViewer.
// Returns nullptr if computing a transform is not possible.
std::unique_ptr<TransformationMatrix> OffsetFromViewer();
// Return origin offset matrix, aka native_origin_from_offset_space.
virtual TransformationMatrix NativeFromOffsetMatrix();
virtual TransformationMatrix OffsetFromNativeMatrix();
// Indicates whether or not the position portion of the native origin of this // Indicates whether or not the position portion of the native origin of this
// space is emulated. // space is emulated.
virtual bool EmulatedPosition() const; virtual bool EmulatedPosition() const;
...@@ -61,23 +72,12 @@ class XRSpace : public EventTargetWithInlineData { ...@@ -61,23 +72,12 @@ class XRSpace : public EventTargetWithInlineData {
// that maps from this space to the other's space, or in other words: // that maps from this space to the other's space, or in other words:
// other_from_this. // other_from_this.
virtual XRPose* getPose(XRSpace* other_space); virtual XRPose* getPose(XRSpace* other_space);
// Gets the viewer pose in this space, including using an appropriate
// default pose (i.e. if tracking is lost), and applying originOffset
// as applicable. TODO(https://crbug.com/1008466): consider moving
// the originOffset handling to a separate class?
std::unique_ptr<TransformationMatrix> OffsetSpaceFromViewer();
XRSession* session() const { return session_; } XRSession* session() const { return session_; }
// EventTarget overrides. // EventTarget overrides.
ExecutionContext* GetExecutionContext() const override; ExecutionContext* GetExecutionContext() const override;
const AtomicString& InterfaceName() const override; const AtomicString& InterfaceName() const override;
// Return origin offset matrix, aka native_origin_from_offset_space.
virtual TransformationMatrix OriginOffsetMatrix();
virtual TransformationMatrix InverseOriginOffsetMatrix();
virtual base::Optional<XRNativeOriginInformation> NativeOrigin() const = 0; virtual base::Optional<XRNativeOriginInformation> NativeOrigin() const = 0;
void Trace(blink::Visitor* visitor) override; void Trace(blink::Visitor* visitor) override;
......
...@@ -15,7 +15,7 @@ namespace blink { ...@@ -15,7 +15,7 @@ namespace blink {
XRTargetRaySpace::XRTargetRaySpace(XRSession* session, XRInputSource* source) XRTargetRaySpace::XRTargetRaySpace(XRSession* session, XRInputSource* source)
: XRSpace(session), input_source_(source) {} : XRSpace(session), input_source_(source) {}
std::unique_ptr<TransformationMatrix> XRTargetRaySpace::MojoFromSpace() { std::unique_ptr<TransformationMatrix> XRTargetRaySpace::MojoFromNative() {
auto mojo_from_viewer = session()->MojoFromViewer(); auto mojo_from_viewer = session()->MojoFromViewer();
switch (input_source_->TargetRayMode()) { switch (input_source_->TargetRayMode()) {
case device::mojom::XRTargetRayMode::TAPPING: { case device::mojom::XRTargetRayMode::TAPPING: {
...@@ -49,8 +49,8 @@ std::unique_ptr<TransformationMatrix> XRTargetRaySpace::MojoFromSpace() { ...@@ -49,8 +49,8 @@ std::unique_ptr<TransformationMatrix> XRTargetRaySpace::MojoFromSpace() {
} }
} }
std::unique_ptr<TransformationMatrix> XRTargetRaySpace::SpaceFromMojo() { std::unique_ptr<TransformationMatrix> XRTargetRaySpace::NativeFromMojo() {
return TryInvert(MojoFromSpace()); return TryInvert(MojoFromNative());
} }
bool XRTargetRaySpace::EmulatedPosition() const { bool XRTargetRaySpace::EmulatedPosition() const {
......
...@@ -15,8 +15,8 @@ class XRTargetRaySpace : public XRSpace { ...@@ -15,8 +15,8 @@ class XRTargetRaySpace : public XRSpace {
public: public:
XRTargetRaySpace(XRSession* session, XRInputSource* input_space); XRTargetRaySpace(XRSession* session, XRInputSource* input_space);
std::unique_ptr<TransformationMatrix> MojoFromSpace() override; std::unique_ptr<TransformationMatrix> MojoFromNative() override;
std::unique_ptr<TransformationMatrix> SpaceFromMojo() override; std::unique_ptr<TransformationMatrix> NativeFromMojo() override;
bool EmulatedPosition() const override; bool EmulatedPosition() const override;
base::Optional<XRNativeOriginInformation> NativeOrigin() const override; base::Optional<XRNativeOriginInformation> NativeOrigin() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment