Skip to content
Permalink
Browse files

Switch XRSpace code to using rigid transforms

  • Loading branch information...
Manishearth committed Apr 3, 2019
1 parent 1f3f372 commit 08079c4d2809785bd14359a9a484d5108f8467cb
@@ -13,7 +13,7 @@ use crate::dom::xrsession::XRSession;
use crate::dom::xrspace::XRSpace;
use crate::dom::xrstationaryreferencespace::XRStationaryReferenceSpace;
use dom_struct::dom_struct;
use euclid::Transform3D;
use euclid::RigidTransform3D;
use webvr_traits::WebVRFrameData;

#[dom_struct]
@@ -55,30 +55,25 @@ impl XRReferenceSpaceMethods for XRReferenceSpace {

impl XRReferenceSpace {
/// Gets viewer pose represented by this space
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
let pose = self.get_pose(base_pose);

// This may change, see https://github.com/immersive-web/webxr/issues/567
let offset = self.transform.get().matrix();
// XXXManishearth we can directly compute the inverse from the transform parameters
// (and perhaps cache it)
// XXXManishearth we can also optimize for the unset/identity offset case
let inverse = offset
.inverse()
.expect("rigid transforms are always invertible");
let offset = self.transform.get().transform();
let inverse = offset.inverse();
inverse.pre_mul(&pose)
}

/// Gets pose represented by this space
///
/// Does not apply originOffset, use get_viewer_pose instead if you need it
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
if let Some(stationary) = self.downcast::<XRStationaryReferenceSpace>() {
stationary.get_pose(base_pose)
} else {
// non-subclassed XRReferenceSpaces exist, obtained via the "identity"
// type. The pose does not depend on the base pose.
Transform3D::identity()
RigidTransform3D::identity()
}
}
}
@@ -13,7 +13,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use euclid::{RigidTransform3D, Rotation3D, Transform3D, Vector3D};
use euclid::{RigidTransform3D, Rotation3D, Vector3D};

#[dom_struct]
pub struct XRRigidTransform {
@@ -34,7 +34,6 @@ impl XRRigidTransform {
}
}

#[allow(unused)]
pub fn new(global: &Window, transform: RigidTransform3D<f64>) -> DomRoot<XRRigidTransform> {
reflect_dom_object(
Box::new(XRRigidTransform::new_inherited(transform)),
@@ -43,7 +42,6 @@ impl XRRigidTransform {
)
}

#[allow(unused)]
pub fn identity(window: &Window) -> DomRoot<XRRigidTransform> {
let transform = RigidTransform3D::identity();
XRRigidTransform::new(window, transform)
@@ -97,9 +95,8 @@ impl XRRigidTransformMethods for XRRigidTransform {
}

impl XRRigidTransform {
pub fn matrix(&self) -> Transform3D<f64> {
// Spec says the orientation applies first,
// so post-multiply (?)
self.transform.to_transform()
/// https://immersive-web.github.io/webxr/#dom-xrpose-transform
pub fn transform(&self) -> RigidTransform3D<f64> {
self.transform
}
}
@@ -11,7 +11,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
use euclid::Transform3D;
use euclid::RigidTransform3D;
use webvr_traits::WebVRFrameData;

#[dom_struct]
@@ -41,7 +41,7 @@ impl XRSpace {
impl XRSpace {
/// Gets viewer pose represented by this space
#[allow(unused)]
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
reference.get_viewer_pose(base_pose)
} else {
@@ -53,7 +53,7 @@ impl XRSpace {
///
/// Does not apply originOffset, use get_viewer_pose instead if you need it
#[allow(unused)]
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> Transform3D<f64> {
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
reference.get_pose(base_pose)
} else {
@@ -11,7 +11,7 @@ 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::{Rotation3D, RigidTransform3D, Vector3D};
use webvr_traits::WebVRFrameData;

#[dom_struct]
@@ -53,18 +53,17 @@ 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,
orient[1] as f64,
orient[2] as f64,
orient[3] as f64,
);
translation.pre_mul(&rotation.to_transform())
RigidTransform3D::new(rotation, translation)
}
}
@@ -10,7 +10,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::vrframedata::create_typed_array;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
use euclid::Transform3D;
use euclid::{RigidTransform3D, Vector3D};
use js::jsapi::{Heap, JSContext, JSObject};
use std::ptr::NonNull;
use webvr_traits::WebVRFrameData;
@@ -40,7 +40,7 @@ impl XRView {
global: &GlobalScope,
session: &XRSession,
eye: XREye,
pose: &Transform3D<f64>,
pose: &RigidTransform3D<f64>,
data: &WebVRFrameData,
) -> DomRoot<XRView> {
let ret = reflect_dom_object(
@@ -64,9 +64,8 @@ impl XRView {
)
};

let offset =
Transform3D::create_translation(offset[0] as f64, offset[1] as f64, offset[2] as f64);
let view = pose.post_mul(&offset).cast().to_column_major_array();
let offset = Vector3D::new(offset[0] as f64, offset[1] as f64, offset[2] as f64);
let view = pose.post_mul(&offset.into()).to_transform().cast().to_column_major_array();

let cx = global.get_cx();
unsafe {

0 comments on commit 08079c4

Please sign in to comment.
You can’t perform that action at this time.