blob: 0f8895ba96ea70b1aa4cd27320f21f8b4ffc3a5f [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/xr/xr_utils.h"
#include <cmath>
namespace blink {
DOMFloat32Array* transformationMatrixToDOMFloat32Array(
const TransformationMatrix& matrix) {
float array[] = {
static_cast<float>(matrix.M11()), static_cast<float>(matrix.M12()),
static_cast<float>(matrix.M13()), static_cast<float>(matrix.M14()),
static_cast<float>(matrix.M21()), static_cast<float>(matrix.M22()),
static_cast<float>(matrix.M23()), static_cast<float>(matrix.M24()),
static_cast<float>(matrix.M31()), static_cast<float>(matrix.M32()),
static_cast<float>(matrix.M33()), static_cast<float>(matrix.M34()),
static_cast<float>(matrix.M41()), static_cast<float>(matrix.M42()),
static_cast<float>(matrix.M43()), static_cast<float>(matrix.M44())};
return DOMFloat32Array::Create(array, 16);
}
// Normalize to have length = 1.0
DOMPointReadOnly* makeNormalizedQuaternion(double x,
double y,
double z,
double w) {
double length = std::sqrt((x * x) + (y * y) + (z * z) + (w * w));
if (length == 0.0) {
// Return a default value instead of crashing.
return DOMPointReadOnly::Create(0.0, 0.0, 0.0, 1.0);
}
return DOMPointReadOnly::Create(x / length, y / length, z / length,
w / length);
}
} // namespace blink