| Index: content/browser/vr/vr_transform_util_unittest.cc
|
| diff --git a/content/browser/vr/vr_transform_util_unittest.cc b/content/browser/vr/vr_transform_util_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2ba893468aa4a1cef9d720267b00d4347ac7d205
|
| --- /dev/null
|
| +++ b/content/browser/vr/vr_transform_util_unittest.cc
|
| @@ -0,0 +1,59 @@
|
| +// Copyright 2015 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 "content/browser/vr/vr_transform_util.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace content {
|
| +
|
| +void EXPECT_QUATERNION(
|
| + float x, float y, float z, float w,
|
| + const VRVector4Ptr& quat) {
|
| + EXPECT_NEAR(x, quat->x, 0.0001f);
|
| + EXPECT_NEAR(y, quat->y, 0.0001f);
|
| + EXPECT_NEAR(z, quat->z, 0.0001f);
|
| + EXPECT_NEAR(w, quat->w, 0.0001f);
|
| +}
|
| +
|
| +TEST(VRTransformUtilTest, IdentityMatrixToQuaternion) {
|
| + float matrix[9] = {
|
| + 1.0f, 0.0f, 0.0f,
|
| + 0.0f, 1.0f, 0.0f,
|
| + 0.0f, 0.0f, 1.0f
|
| + };
|
| +
|
| + VRVector4Ptr orientation = MatrixToOrientationQuaternion(
|
| + &matrix[0], &matrix[3], &matrix[6]);
|
| +
|
| + EXPECT_QUATERNION(0.0f, 0.0f, 0.0f, 1.0f, orientation);
|
| +}
|
| +
|
| +TEST(VRTransformUtilTest, 90DegXMatrixToQuaternion) {
|
| + float rad = M_PI * 0.5f;
|
| + float matrix[9] = {
|
| + 1.0f, 0.0f, 0.0f,
|
| + 0.0f, cos(rad), -sin(rad),
|
| + 0.0f, sin(rad), cos(rad)
|
| + };
|
| +
|
| + VRVector4Ptr orientation = MatrixToOrientationQuaternion(
|
| + &matrix[0], &matrix[3], &matrix[6]);
|
| +
|
| + EXPECT_QUATERNION(0.7071f, 0.0f, 0.0f, 0.7071f, orientation);
|
| +}
|
| +
|
| +TEST(VRTransformUtilTest, 180DegYMatrixToQuaternion) {
|
| + float matrix[9] = {
|
| + cos(M_PI), 0.0f, sin(M_PI),
|
| + 0.0f, 1.0f, 0.0f,
|
| + -sin(M_PI), 0.0f, cos(M_PI)
|
| + };
|
| +
|
| + VRVector4Ptr orientation = MatrixToOrientationQuaternion(
|
| + &matrix[0], &matrix[3], &matrix[6]);
|
| +
|
| + EXPECT_QUATERNION(0.0f, 1.0f, 0.0f, 0.0f, orientation);
|
| +}
|
| +
|
| +} // namespace content
|
|
|