Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Unified Diff: content/browser/vr/vr_transform_util_unittest.cc

Issue 1200303002: Android WebVR implementation, Cardboard 0.5.5 SDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added Traces Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/vr/vr_transform_util.cc ('k') | content/content.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « content/browser/vr/vr_transform_util.cc ('k') | content/content.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698