browser/devtools/tilt/test/browser_tilt_math05.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     5 function test() {
     6   let m1 = mat4.create([
     7     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
     9   let m2 = mat4.create([
    10     0, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]);
    12   mat4.multiply(m1, m2);
    13   ok(isApproxVec(m1, [
    14     275, 302, 329, 356, 304, 336, 368, 400,
    15     332, 368, 404, 440, 360, 400, 440, 480
    16   ]), "The mat4.multiply() function didn't set the values correctly.");
    18   let v1 = mat4.multiplyVec3(m1, [1, 2, 3]);
    19   ok(isApproxVec(v1, [2239, 2478, 2717]),
    20     "The mat4.multiplyVec3() function didn't set the values correctly.");
    22   let v2 = mat4.multiplyVec4(m1, [1, 2, 3, 0]);
    23   ok(isApproxVec(v2, [1879, 2078, 2277, 2476]),
    24     "The mat4.multiplyVec4() function didn't set the values correctly.");
    26   mat4.translate(m1, [1, 2, 3]);
    27   ok(isApproxVec(m1, [
    28     275, 302, 329, 356, 304, 336, 368, 400,
    29     332, 368, 404, 440, 2239, 2478, 2717, 2956
    30   ]), "The mat4.translate() function didn't set the values correctly.");
    32   mat4.scale(m1, [1, 2, 3]);
    33   ok(isApproxVec(m1, [
    34     275, 302, 329, 356, 608, 672, 736, 800,
    35     996, 1104, 1212, 1320, 2239, 2478, 2717, 2956
    36   ]), "The mat4.scale() function didn't set the values correctly.");
    38   mat4.rotate(m1, 0.5, [1, 1, 1]);
    39   ok(isApproxVec(m1, [
    40     210.6123046875, 230.2483367919922, 249.88438415527344, 269.5204162597656,
    41     809.8145751953125, 896.520751953125, 983.2268676757812,
    42     1069.9329833984375, 858.5731201171875, 951.23095703125,
    43     1043.8887939453125, 1136.5465087890625, 2239, 2478, 2717, 2956
    44   ]), "The mat4.rotate() function didn't set the values correctly.");
    46   mat4.rotateX(m1, 0.5);
    47   ok(isApproxVec(m1, [
    48     210.6123046875, 230.2483367919922, 249.88438415527344, 269.5204162597656,
    49     1122.301025390625, 1242.8154296875, 1363.3297119140625,
    50     1483.843994140625, 365.2230224609375, 404.96875, 444.71453857421875,
    51     484.460205078125, 2239, 2478, 2717, 2956
    52   ]), "The mat4.rotateX() function didn't set the values correctly.");
    54   mat4.rotateY(m1, 0.5);
    55   ok(isApproxVec(m1, [
    56     9.732441902160645, 7.909564018249512, 6.086670875549316,
    57     4.263822555541992, 1122.301025390625, 1242.8154296875, 1363.3297119140625,
    58     1483.843994140625, 421.48626708984375, 465.78045654296875,
    59     510.0746765136719, 554.3687744140625, 2239, 2478, 2717, 2956
    60   ]), "The mat4.rotateY() function didn't set the values correctly.");
    62   mat4.rotateZ(m1, 0.5);
    63   ok(isApproxVec(m1, [
    64     546.6007690429688, 602.7787475585938, 658.9566650390625, 715.1345825195312,
    65     980.245849609375, 1086.881103515625, 1193.5162353515625,
    66     1300.1514892578125, 421.48626708984375, 465.78045654296875,
    67     510.0746765136719, 554.3687744140625, 2239, 2478, 2717, 2956
    68   ]), "The mat4.rotateZ() function didn't set the values correctly.");
    71   let m3 = mat4.frustum(0, 100, 200, 0, 0.1, 100);
    72   ok(isApproxVec(m3, [
    73     0.0020000000949949026, 0, 0, 0, 0, -0.0010000000474974513, 0, 0, 1, -1,
    74     -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0
    75   ]), "The mat4.frustum() function didn't compute the values correctly.");
    77   let m4 = mat4.perspective(45, 1.6, 0.1, 100);
    78   ok(isApproxVec(m4, [1.5088834762573242, 0, 0, 0, 0, 2.4142136573791504, 0,
    79     0, 0, 0, -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0
    80   ]), "The mat4.frustum() function didn't compute the values correctly.");
    82   let m5 = mat4.ortho(0, 100, 200, 0, -1, 1);
    83   ok(isApproxVec(m5, [
    84     0.019999999552965164, 0, 0, 0, 0, -0.009999999776482582, 0, 0,
    85     0, 0, -1, 0, -1, 1, 0, 1
    86   ]), "The mat4.ortho() function didn't compute the values correctly.");
    88   let m6 = mat4.lookAt([1, 2, 3], [4, 5, 6], [0, 1, 0]);
    89   ok(isApproxVec(m6, [
    90     -0.7071067690849304, -0.40824830532073975, -0.5773502588272095, 0, 0,
    91     0.8164966106414795, -0.5773502588272095, 0, 0.7071067690849304,
    92     -0.40824830532073975, -0.5773502588272095, 0, -1.4142135381698608, 0,
    93     3.464101552963257, 1
    94   ]), "The mat4.lookAt() function didn't compute the values correctly.");
    97   is(mat4.str([
    98     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
    99   "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]",
   100   "The mat4.str() function didn't work properly.");
   101 }

mercurial