tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

XRReferenceSpace.cpp (1953B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozilla/dom/XRReferenceSpace.h"
      8 
      9 #include "VRDisplayClient.h"
     10 #include "mozilla/dom/XRRigidTransform.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 XRReferenceSpace::XRReferenceSpace(nsIGlobalObject* aParent,
     15                                   XRSession* aSession,
     16                                   XRNativeOrigin* aNativeOrigin,
     17                                   XRReferenceSpaceType aType)
     18    : XRSpace(aParent, aSession, aNativeOrigin), mType(aType) {}
     19 
     20 already_AddRefed<XRReferenceSpace> XRReferenceSpace::GetOffsetReferenceSpace(
     21    const XRRigidTransform& aOriginOffset) {
     22  RefPtr<XRReferenceSpace> offsetReferenceSpace =
     23      new XRReferenceSpace(GetParentObject(), mSession, mNativeOrigin, mType);
     24 
     25  // https://immersive-web.github.io/webxr/#multiply-transforms
     26  // An XRRigidTransform is essentially a rotation followed by a translation
     27  gfx::QuaternionDouble otherOrientation = aOriginOffset.RawOrientation();
     28  // The resulting rotation is the two combined
     29  offsetReferenceSpace->mOriginOffsetOrientation =
     30      mOriginOffsetOrientation * otherOrientation;
     31  // We first apply the rotation of aOriginOffset to
     32  // mOriginOffsetPosition offset, then translate by the offset of
     33  // aOriginOffset
     34  offsetReferenceSpace->mOriginOffsetPosition =
     35      otherOrientation.RotatePoint(mOriginOffsetPosition) +
     36      aOriginOffset.RawPosition();
     37 
     38  return offsetReferenceSpace.forget();
     39 }
     40 
     41 JSObject* XRReferenceSpace::WrapObject(JSContext* aCx,
     42                                       JS::Handle<JSObject*> aGivenProto) {
     43  return XRReferenceSpace_Binding::Wrap(aCx, this, aGivenProto);
     44 }
     45 
     46 }  // namespace mozilla::dom