aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/xrstationaryreferencespace.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-04-04 11:36:56 -0400
committerGitHub <noreply@github.com>2019-04-04 11:36:56 -0400
commitf1b82f8573d825a40e4fe0d32559b1acb169ac9c (patch)
treef2d1912d54abfe3f00186b177c5804d0af38952d /components/script/dom/xrstationaryreferencespace.rs
parent3e86aec26e8f0626a6c66faa56d6edb0fce8d793 (diff)
parente055884564f6bf1db0ea2ca6af3b3aaafd4fd17b (diff)
downloadservo-f1b82f8573d825a40e4fe0d32559b1acb169ac9c.tar.gz
servo-f1b82f8573d825a40e4fe0d32559b1acb169ac9c.zip
Auto merge of #23159 - Manishearth:rigid-transforms, r=asajeffrey
Update XR code to use rigid transforms and new pose/transform stuff from the spec This updates our XR code to use euclid's new [RigidTransform3D type](https://github.com/servo/euclid/pull/328), which is more efficent and convenient to work with. It additionally brings us up to speed with the spec: - `XRViewerPose` was made a subclass of `XRPose` (https://github.com/immersive-web/webxr/pull/496) - `XRView.viewMatrix` was removed in favor of `XRRigidTransform.inverse.matrix` (https://github.com/immersive-web/webxr/pull/531) - `XRRigidTransform.inverse` is an attribute (https://github.com/immersive-web/webxr/pull/560) - `XRRigidTransform` now validates positions in its constructor (https://github.com/immersive-web/webxr/pull/568) Furthermore, it adds support for `XRRigidTransform.matrix`. While fixing this I also noticed that our view matrix code was incorrect, we calculated view matrices as `pose.to_column_major_array()`, whereas it *should* be `pose.inverse().to_row_major_array()` (since Euclid uses row vectors, whenever the spec says it wants a column major array we should use `.to_row_major_array()` since all web specs implicitly use column vectors). For 3DOF devices poses are mostly rotations anyway, so the effective transpose behaved _like_ an inversion, but was incorrect. This PR gets rid of `view.viewMatrix` anyway, however I felt like I should mention this discrepancy, since otherwise the replacement of `view.viewMatrix` with `view.transform.inverse.matrix` doesn't make sense r? @jdm <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23159) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/xrstationaryreferencespace.rs')
-rw-r--r--components/script/dom/xrstationaryreferencespace.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/components/script/dom/xrstationaryreferencespace.rs b/components/script/dom/xrstationaryreferencespace.rs
index e8349ef3581..ddba9aaa20b 100644
--- a/components/script/dom/xrstationaryreferencespace.rs
+++ b/components/script/dom/xrstationaryreferencespace.rs
@@ -6,12 +6,12 @@ use crate::dom::bindings::codegen::Bindings::XRStationaryReferenceSpaceBinding;
use crate::dom::bindings::codegen::Bindings::XRStationaryReferenceSpaceBinding::XRStationaryReferenceSpaceSubtype;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
-use crate::dom::window::Window;
+use crate::dom::globalscope::GlobalScope;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
-use euclid::{Rotation3D, Transform3D};
+use euclid::{RigidTransform3D, Rotation3D, Vector3D};
use webvr_traits::WebVRFrameData;
#[dom_struct]
@@ -34,16 +34,16 @@ impl XRStationaryReferenceSpace {
}
pub fn new(
- window: &Window,
+ global: &GlobalScope,
session: &XRSession,
ty: XRStationaryReferenceSpaceSubtype,
) -> DomRoot<XRStationaryReferenceSpace> {
- let transform = XRRigidTransform::identity(window);
+ let transform = XRRigidTransform::identity(global);
reflect_dom_object(
Box::new(XRStationaryReferenceSpace::new_inherited(
session, ty, &transform,
)),
- window,
+ global,
XRStationaryReferenceSpaceBinding::Wrap,
)
}
@@ -53,11 +53,10 @@ impl XRStationaryReferenceSpace {
/// Gets pose represented by this space
///
/// Does not apply originOffset, use get_viewer_pose instead
- pub fn get_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
+ pub fn get_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
// XXXManishearth add floor-level transform for floor-level and disable position in position-disabled
let pos = base_pose.pose.position.unwrap_or([0., 0., 0.]);
- let translation =
- Transform3D::create_translation(pos[0] as f64, pos[1] as f64, pos[2] as f64);
+ let translation = Vector3D::new(pos[0] as f64, pos[1] as f64, pos[2] as f64);
let orient = base_pose.pose.orientation.unwrap_or([0., 0., 0., 0.]);
let rotation = Rotation3D::quaternion(
orient[0] as f64,
@@ -65,6 +64,6 @@ impl XRStationaryReferenceSpace {
orient[2] as f64,
orient[3] as f64,
);
- translation.pre_mul(&rotation.to_transform())
+ RigidTransform3D::new(rotation, translation)
}
}