xrRigidTransform_matrix.https.html (1654B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/webxr_test_constants.js"></script> 5 <script src="resources/webxr_test_asserts.js"></script> 6 <script src="resources/webxr_math_utils.js"></script> 7 <script> 8 9 let matrix_tests_name = "XRRigidTransform matrix works"; 10 11 let matrix_tests = function() { 12 // Matrix tests for XRRigidTransform. 13 14 // Test 1. Check if matrix rotates the vector the same way as quaternion 15 // used to construct it. This does not perform a translation. 16 { 17 // point 18 const originDict = {x : 0, y : 0, z : 0, w : 1}; 19 // quaternion - should be normalized 20 const orientationDict = {x : 0, y : 0.3805356, z : 0.7610712, w : 0.525322 } 21 22 let rigidTransform = new XRRigidTransform( 23 DOMPoint.fromPoint(originDict), 24 DOMPoint.fromPoint(orientationDict)); 25 26 const point_0 = {x : 10, y : 11, z : 12, w : 1}; 27 28 // transform the point by matrix from rigid transform 29 const point_transformed_0 = normalize_perspective(transform_point_by_matrix(rigidTransform.matrix, point_0)); 30 const point_transformed_1 = transform_point_by_quaternion(orientationDict, point_0); 31 const point_transformed_2 = transform_point_by_quaternion(rigidTransform.orientation, point_0); 32 33 assert_point_approx_equals( 34 point_transformed_1, point_transformed_0, 35 FLOAT_EPSILON, "by-initial-quaternion-and-matrix:"); 36 37 assert_point_approx_equals( 38 point_transformed_2, point_transformed_0, 39 FLOAT_EPSILON, "by-transform's-quaternion-and-matrix:"); 40 } 41 }; 42 43 test(matrix_tests, matrix_tests_name); 44 45 </script>