browser/devtools/tilt/test/browser_tilt_math05.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/test/browser_tilt_math05.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +"use strict";
     1.7 +
     1.8 +function test() {
     1.9 +  let m1 = mat4.create([
    1.10 +    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
    1.11 +
    1.12 +  let m2 = mat4.create([
    1.13 +    0, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]);
    1.14 +
    1.15 +  mat4.multiply(m1, m2);
    1.16 +  ok(isApproxVec(m1, [
    1.17 +    275, 302, 329, 356, 304, 336, 368, 400,
    1.18 +    332, 368, 404, 440, 360, 400, 440, 480
    1.19 +  ]), "The mat4.multiply() function didn't set the values correctly.");
    1.20 +
    1.21 +  let v1 = mat4.multiplyVec3(m1, [1, 2, 3]);
    1.22 +  ok(isApproxVec(v1, [2239, 2478, 2717]),
    1.23 +    "The mat4.multiplyVec3() function didn't set the values correctly.");
    1.24 +
    1.25 +  let v2 = mat4.multiplyVec4(m1, [1, 2, 3, 0]);
    1.26 +  ok(isApproxVec(v2, [1879, 2078, 2277, 2476]),
    1.27 +    "The mat4.multiplyVec4() function didn't set the values correctly.");
    1.28 +
    1.29 +  mat4.translate(m1, [1, 2, 3]);
    1.30 +  ok(isApproxVec(m1, [
    1.31 +    275, 302, 329, 356, 304, 336, 368, 400,
    1.32 +    332, 368, 404, 440, 2239, 2478, 2717, 2956
    1.33 +  ]), "The mat4.translate() function didn't set the values correctly.");
    1.34 +
    1.35 +  mat4.scale(m1, [1, 2, 3]);
    1.36 +  ok(isApproxVec(m1, [
    1.37 +    275, 302, 329, 356, 608, 672, 736, 800,
    1.38 +    996, 1104, 1212, 1320, 2239, 2478, 2717, 2956
    1.39 +  ]), "The mat4.scale() function didn't set the values correctly.");
    1.40 +
    1.41 +  mat4.rotate(m1, 0.5, [1, 1, 1]);
    1.42 +  ok(isApproxVec(m1, [
    1.43 +    210.6123046875, 230.2483367919922, 249.88438415527344, 269.5204162597656,
    1.44 +    809.8145751953125, 896.520751953125, 983.2268676757812,
    1.45 +    1069.9329833984375, 858.5731201171875, 951.23095703125,
    1.46 +    1043.8887939453125, 1136.5465087890625, 2239, 2478, 2717, 2956
    1.47 +  ]), "The mat4.rotate() function didn't set the values correctly.");
    1.48 +
    1.49 +  mat4.rotateX(m1, 0.5);
    1.50 +  ok(isApproxVec(m1, [
    1.51 +    210.6123046875, 230.2483367919922, 249.88438415527344, 269.5204162597656,
    1.52 +    1122.301025390625, 1242.8154296875, 1363.3297119140625,
    1.53 +    1483.843994140625, 365.2230224609375, 404.96875, 444.71453857421875,
    1.54 +    484.460205078125, 2239, 2478, 2717, 2956
    1.55 +  ]), "The mat4.rotateX() function didn't set the values correctly.");
    1.56 +
    1.57 +  mat4.rotateY(m1, 0.5);
    1.58 +  ok(isApproxVec(m1, [
    1.59 +    9.732441902160645, 7.909564018249512, 6.086670875549316,
    1.60 +    4.263822555541992, 1122.301025390625, 1242.8154296875, 1363.3297119140625,
    1.61 +    1483.843994140625, 421.48626708984375, 465.78045654296875,
    1.62 +    510.0746765136719, 554.3687744140625, 2239, 2478, 2717, 2956
    1.63 +  ]), "The mat4.rotateY() function didn't set the values correctly.");
    1.64 +
    1.65 +  mat4.rotateZ(m1, 0.5);
    1.66 +  ok(isApproxVec(m1, [
    1.67 +    546.6007690429688, 602.7787475585938, 658.9566650390625, 715.1345825195312,
    1.68 +    980.245849609375, 1086.881103515625, 1193.5162353515625,
    1.69 +    1300.1514892578125, 421.48626708984375, 465.78045654296875,
    1.70 +    510.0746765136719, 554.3687744140625, 2239, 2478, 2717, 2956
    1.71 +  ]), "The mat4.rotateZ() function didn't set the values correctly.");
    1.72 +
    1.73 +
    1.74 +  let m3 = mat4.frustum(0, 100, 200, 0, 0.1, 100);
    1.75 +  ok(isApproxVec(m3, [
    1.76 +    0.0020000000949949026, 0, 0, 0, 0, -0.0010000000474974513, 0, 0, 1, -1,
    1.77 +    -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0
    1.78 +  ]), "The mat4.frustum() function didn't compute the values correctly.");
    1.79 +
    1.80 +  let m4 = mat4.perspective(45, 1.6, 0.1, 100);
    1.81 +  ok(isApproxVec(m4, [1.5088834762573242, 0, 0, 0, 0, 2.4142136573791504, 0,
    1.82 +    0, 0, 0, -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0
    1.83 +  ]), "The mat4.frustum() function didn't compute the values correctly.");
    1.84 +
    1.85 +  let m5 = mat4.ortho(0, 100, 200, 0, -1, 1);
    1.86 +  ok(isApproxVec(m5, [
    1.87 +    0.019999999552965164, 0, 0, 0, 0, -0.009999999776482582, 0, 0,
    1.88 +    0, 0, -1, 0, -1, 1, 0, 1
    1.89 +  ]), "The mat4.ortho() function didn't compute the values correctly.");
    1.90 +
    1.91 +  let m6 = mat4.lookAt([1, 2, 3], [4, 5, 6], [0, 1, 0]);
    1.92 +  ok(isApproxVec(m6, [
    1.93 +    -0.7071067690849304, -0.40824830532073975, -0.5773502588272095, 0, 0,
    1.94 +    0.8164966106414795, -0.5773502588272095, 0, 0.7071067690849304,
    1.95 +    -0.40824830532073975, -0.5773502588272095, 0, -1.4142135381698608, 0,
    1.96 +    3.464101552963257, 1
    1.97 +  ]), "The mat4.lookAt() function didn't compute the values correctly.");
    1.98 +
    1.99 +
   1.100 +  is(mat4.str([
   1.101 +    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
   1.102 +  "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]",
   1.103 +  "The mat4.str() function didn't work properly.");
   1.104 +}

mercurial