mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Precompute XRRigidTransform's matrices
This commit is contained in:
parent
77e857891a
commit
6fda2f28a6
2 changed files with 27 additions and 14 deletions
|
@ -56,7 +56,7 @@ use cssparser::RGBA;
|
||||||
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
||||||
use encoding_rs::{Decoder, Encoding};
|
use encoding_rs::{Decoder, Encoding};
|
||||||
use euclid::Length as EuclidLength;
|
use euclid::Length as EuclidLength;
|
||||||
use euclid::{Point2D, Rect, Transform2D, Transform3D, TypedScale, TypedSize2D, Vector2D};
|
use euclid::{Point2D, Rect, Rotation3D, Transform2D, Transform3D, TypedScale, TypedSize2D, Vector2D};
|
||||||
use html5ever::buffer_queue::BufferQueue;
|
use html5ever::buffer_queue::BufferQueue;
|
||||||
use html5ever::{LocalName, Namespace, Prefix, QualName};
|
use html5ever::{LocalName, Namespace, Prefix, QualName};
|
||||||
use http::header::HeaderMap;
|
use http::header::HeaderMap;
|
||||||
|
@ -582,6 +582,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl JSTraceable for Rotation3D<f64> {
|
||||||
|
#[inline]
|
||||||
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl JSTraceable for Transform2D<f32> {
|
unsafe impl JSTraceable for Transform2D<f32> {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
|
|
@ -20,6 +20,10 @@ pub struct XRRigidTransform {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
position: Dom<DOMPointReadOnly>,
|
position: Dom<DOMPointReadOnly>,
|
||||||
orientation: Dom<DOMPointReadOnly>,
|
orientation: Dom<DOMPointReadOnly>,
|
||||||
|
#[ignore_malloc_size_of = "defined in euclid"]
|
||||||
|
translate: Transform3D<f64>,
|
||||||
|
#[ignore_malloc_size_of = "defined in euclid"]
|
||||||
|
rotate: Rotation3D<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRRigidTransform {
|
impl XRRigidTransform {
|
||||||
|
@ -27,10 +31,22 @@ impl XRRigidTransform {
|
||||||
position: &DOMPointReadOnly,
|
position: &DOMPointReadOnly,
|
||||||
orientation: &DOMPointReadOnly,
|
orientation: &DOMPointReadOnly,
|
||||||
) -> XRRigidTransform {
|
) -> XRRigidTransform {
|
||||||
|
let translate = Transform3D::create_translation(
|
||||||
|
position.X() as f64,
|
||||||
|
position.Y() as f64,
|
||||||
|
position.Z() as f64,
|
||||||
|
);
|
||||||
|
let rotate = Rotation3D::unit_quaternion(
|
||||||
|
orientation.X() as f64,
|
||||||
|
orientation.Y() as f64,
|
||||||
|
orientation.Z() as f64,
|
||||||
|
orientation.W() as f64,
|
||||||
|
);
|
||||||
XRRigidTransform {
|
XRRigidTransform {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
position: Dom::from_ref(position),
|
position: Dom::from_ref(position),
|
||||||
orientation: Dom::from_ref(orientation),
|
orientation: Dom::from_ref(orientation),
|
||||||
|
translate, rotate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,18 +102,8 @@ impl XRRigidTransformMethods for XRRigidTransform {
|
||||||
|
|
||||||
impl XRRigidTransform {
|
impl XRRigidTransform {
|
||||||
pub fn matrix(&self) -> Transform3D<f64> {
|
pub fn matrix(&self) -> Transform3D<f64> {
|
||||||
// XXXManishearth compute this during initialization
|
// Spec says the orientation applies first,
|
||||||
let translate = Transform3D::create_translation(
|
// so post-multiply (?)
|
||||||
self.position.X(),
|
self.translate.post_mul(&self.rotate.to_transform())
|
||||||
self.position.Y(),
|
|
||||||
self.position.Z(),
|
|
||||||
);
|
|
||||||
let rotation = Rotation3D::unit_quaternion(
|
|
||||||
self.orientation.X(),
|
|
||||||
self.orientation.Y(),
|
|
||||||
self.orientation.Z(),
|
|
||||||
self.orientation.W(),
|
|
||||||
);
|
|
||||||
translate.pre_mul(&rotation.to_transform())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue