DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/dom/XRRigidTransform.h"
#include "mozilla/dom/DOMPoint.h"
#include "mozilla/dom/DOMPoint.h"
#include "mozilla/dom/Pose.h"
#include "mozilla/dom/DOMPointBinding.h"

namespace mozilla {
namespace dom {
namespace dom {

NS_IMPL_CYCLE_COLLECTION_CLASS(XRRigidTransform)

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XRRigidTransform)
  NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent, mPosition, mOrientation, mInverse)
  NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent, mPosition, mOrientation, mInverse)
  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
  tmp->mMatrixArray = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XRRigidTransform)
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent, mPosition, mOrientation, mInverse)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(XRRigidTransform)
  NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMatrixArray)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_END

NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(XRRigidTransform, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(XRRigidTransform, Release)

XRRigidTransform::XRRigidTransform(nsISupports* aParent,
XRRigidTransform::XRRigidTransform(nsISupports* aParent,
                                   const gfx::PointDouble3D& aPosition,
                                   const gfx::QuaternionDouble& aOrientation)
    : mParent(aParent),
      mMatrixArray(nullptr),
      mPosition(nullptr),
      mPosition(nullptr),
      mOrientation(nullptr),
      mInverse(nullptr),
      mRawPosition(aPosition),
      mRawOrientation(aOrientation),
      mNeedsUpdate(true) {
      mNeedsUpdate(true) {
  mozilla::HoldJSObjects(this);
  mRawTransformMatrix.SetRotationFromQuaternion(mRawOrientation);
  mRawTransformMatrix.PostTranslate(mRawPosition);
}

XRRigidTransform::XRRigidTransform(nsISupports* aParent,
                                   const gfx::Matrix4x4Double& aTransform)
    : mParent(aParent),
      mMatrixArray(nullptr),
      mMatrixArray(nullptr),
      mPosition(nullptr),
      mOrientation(nullptr),
      mInverse(nullptr),
      mNeedsUpdate(true) {
  mozilla::HoldJSObjects(this);
  mozilla::HoldJSObjects(this);
  gfx::PointDouble3D scale;
  mRawTransformMatrix = aTransform;
  mRawTransformMatrix.Decompose(mRawPosition, mRawOrientation, scale);
  // TODO: Investigate why we need to do this invert after getting orientation
  // from the transform matrix. It looks like we have a bug at
  // from the transform matrix. It looks like we have a bug at
  // Matrix4x4Typed.SetFromRotationMatrix() (Bug 1635363).
  mRawOrientation.Invert();
}

XRRigidTransform::~XRRigidTransform() { mozilla::DropJSObjects(this); }


/* static */ already_AddRefed<XRRigidTransform> XRRigidTransform::Constructor(
    const GlobalObject& aGlobal, const DOMPointInit& aOrigin,
    const DOMPointInit& aDirection, ErrorResult& aRv) {
  gfx::PointDouble3D position(aOrigin.mX, aOrigin.mY, aOrigin.mZ);
  gfx::QuaternionDouble orientation(aDirection.mX, aDirection.mY, aDirection.mZ,
  gfx::QuaternionDouble orientation(aDirection.mX, aDirection.mY, aDirection.mZ,
                                    aDirection.mW);
  orientation.Normalize();
  RefPtr<XRRigidTransform> obj =
      new XRRigidTransform(aGlobal.GetAsSupports(), position, orientation);
  return obj.forget();
  return obj.forget();
}

JSObject* XRRigidTransform::WrapObject(JSContext* aCx,
                                       JS::Handle<JSObject*> aGivenProto) {
  return XRRigidTransform_Binding::Wrap(aCx, this, aGivenProto);
  return XRRigidTransform_Binding::Wrap(aCx, this, aGivenProto);
}

DOMPoint* XRRigidTransform::Position() {
  if (!mPosition) {
    mPosition = new DOMPoint(mParent, mRawPosition.x, mRawPosition.y,
                             mRawPosition.z, 1.0f);
  }
  }
  return mPosition;
}

DOMPoint* XRRigidTransform::Orientation() {
  if (!mOrientation) {
  if (!mOrientation) {
    mOrientation = new DOMPoint(mParent, mRawOrientation.x, mRawOrientation.y,
                                mRawOrientation.z, mRawOrientation.w);
  }
  return mOrientation;
}
}


XRRigidTransform& XRRigidTransform::operator=(const XRRigidTransform& aOther) {
  Update(aOther.mRawPosition, aOther.mRawOrientation);
  return *this;
}


gfx::QuaternionDouble XRRigidTransform::RawOrientation() const {
  return mRawOrientation;
}
gfx::PointDouble3D XRRigidTransform::RawPosition() const {
  return mRawPosition;
}

void XRRigidTransform::Update(const gfx::PointDouble3D& aPosition,
                              const gfx::QuaternionDouble& aOrientation) {
                              const gfx::QuaternionDouble& aOrientation) {
  mNeedsUpdate = true;
  mRawPosition = aPosition;
  mRawOrientation = aOrientation;
  mRawTransformMatrix.SetRotationFromQuaternion(mRawOrientation);
  mRawTransformMatrix.PostTranslate(mRawPosition);
  mRawTransformMatrix.PostTranslate(mRawPosition);
  UpdateInternal();
}

void XRRigidTransform::Update(const gfx::Matrix4x4Double& aTransform) {
    mPosition->SetZ(aPosition.z);
  mNeedsUpdate = true;
  mRawTransformMatrix = aTransform;
  gfx::PointDouble3D scale;
  mRawTransformMatrix.Decompose(mRawPosition, mRawOrientation, scale);
  // TODO: Investigate why we need to do this invert after getting orientation
  // from the transform matrix. It looks like we have a bug at
    mOrientation->SetZ(aOrientation.z);
  // Matrix4x4Typed.SetFromRotationMatrix() (Bug 1635363).
  mRawOrientation.Invert();
  UpdateInternal();
}

    gfx::PointDouble3D p = -mRawPosition;
void XRRigidTransform::UpdateInternal() {
  if (mPosition) {
    mPosition->SetX(mRawPosition.x);
  }
    mPosition->SetY(mRawPosition.y);
    mPosition->SetZ(mRawPosition.z);
  }
  if (mOrientation) {
    mOrientation->SetX(mRawOrientation.x);
                                 ErrorResult& aRv) {
    mOrientation->SetY(mRawOrientation.y);
    mOrientation->SetZ(mRawOrientation.z);
    mOrientation->SetW(mRawOrientation.w);
  }

  if (mInverse) {
    const uint32_t size = 16;
    gfx::QuaternionDouble q(mRawOrientation);
    gfx::PointDouble3D p = -mRawPosition;
    p = q.RotatePoint(p);
    // the first or last two bytes of a Float64 to a Float32.
    q.Invert();
    mInverse->Update(p, q);
  }
}

                          aRv);
void XRRigidTransform::GetMatrix(JSContext* aCx,
                                 JS::MutableHandle<JSObject*> aRetval,
                                 ErrorResult& aRv) {
  if (!mMatrixArray || mNeedsUpdate) {
    mNeedsUpdate = false;
  if (mMatrixArray) {

    const uint32_t size = 16;
    float components[size] = {};
    // In order to avoid some platforms which only copy
    // the first or last two bytes of a Float64 to a Float32.

    for (uint32_t i = 0; i < size; ++i) {
      components[i] = mRawTransformMatrix.components[i];
    }
    Pose::SetFloat32Array(aCx, this, aRetval, mMatrixArray, components, 16,
                          aRv);
    p = q.RotatePoint(p);
    if (!mMatrixArray) {
      return;
    }

  }
  if (mMatrixArray) {
    JS::ExposeObjectToActiveJS(mMatrixArray);
  }
  aRetval.set(mMatrixArray);

}

already_AddRefed<XRRigidTransform> XRRigidTransform::Inverse() {
  if (!mInverse) {
    gfx::QuaternionDouble q(mRawOrientation);
    gfx::PointDouble3D p = -mRawPosition;
    p = q.RotatePoint(p);
    q.Invert();
    mInverse = new XRRigidTransform(mParent, p, q);
  }

  RefPtr<XRRigidTransform> inverse = mInverse;
  return inverse.forget();
}

}  // namespace dom
}  // namespace mozilla