| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <math.h> | |
| 6 | |
| 7 #include "content/browser/vr/vr_transform_util.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 const float kPi = 3.14159265f; | |
| 13 | |
| 14 void EXPECT_QUATERNION( | |
| 15 float x, float y, float z, float w, | |
| 16 const VRVector4Ptr& quat) { | |
| 17 EXPECT_NEAR(x, quat->x, 0.0001f); | |
| 18 EXPECT_NEAR(y, quat->y, 0.0001f); | |
| 19 EXPECT_NEAR(z, quat->z, 0.0001f); | |
| 20 EXPECT_NEAR(w, quat->w, 0.0001f); | |
| 21 } | |
| 22 | |
| 23 TEST(VRTransformUtilTest, IdentityMatrixToQuaternion) { | |
| 24 float matrix[9] = { | |
| 25 1.0f, 0.0f, 0.0f, | |
| 26 0.0f, 1.0f, 0.0f, | |
| 27 0.0f, 0.0f, 1.0f | |
| 28 }; | |
| 29 | |
| 30 VRVector4Ptr orientation = MatrixToOrientationQuaternion( | |
| 31 &matrix[0], &matrix[3], &matrix[6]); | |
| 32 | |
| 33 EXPECT_QUATERNION(0.0f, 0.0f, 0.0f, 1.0f, orientation); | |
| 34 } | |
| 35 | |
| 36 TEST(VRTransformUtilTest, 90DegXMatrixToQuaternion) { | |
| 37 float rad = kPi * 0.5f; | |
| 38 float matrix[9] = { | |
| 39 1.0f, 0.0f, 0.0f, | |
| 40 0.0f, cosf(rad), -sinf(rad), | |
| 41 0.0f, sinf(rad), cosf(rad) | |
| 42 }; | |
| 43 | |
| 44 VRVector4Ptr orientation = MatrixToOrientationQuaternion( | |
| 45 &matrix[0], &matrix[3], &matrix[6]); | |
| 46 | |
| 47 EXPECT_QUATERNION(0.7071f, 0.0f, 0.0f, 0.7071f, orientation); | |
| 48 } | |
| 49 | |
| 50 TEST(VRTransformUtilTest, 180DegYMatrixToQuaternion) { | |
| 51 float matrix[9] = { | |
| 52 cosf(kPi), 0.0f, sinf(kPi), | |
| 53 0.0f, 1.0f, 0.0f, | |
| 54 -sinf(kPi), 0.0f, cosf(kPi) | |
| 55 }; | |
| 56 | |
| 57 VRVector4Ptr orientation = MatrixToOrientationQuaternion( | |
| 58 &matrix[0], &matrix[3], &matrix[6]); | |
| 59 | |
| 60 EXPECT_QUATERNION(0.0f, 1.0f, 0.0f, 0.0f, orientation); | |
| 61 } | |
| 62 | |
| 63 } // namespace content | |
| OLD | NEW |