build/pgo/js-input/3d-cube.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!DOCTYPE html>
michael@0 2 <head>
michael@0 3 <!--
michael@0 4 Copyright (C) 2007 Apple Inc. All rights reserved.
michael@0 5
michael@0 6 Redistribution and use in source and binary forms, with or without
michael@0 7 modification, are permitted provided that the following conditions
michael@0 8 are met:
michael@0 9 1. Redistributions of source code must retain the above copyright
michael@0 10 notice, this list of conditions and the following disclaimer.
michael@0 11 2. Redistributions in binary form must reproduce the above copyright
michael@0 12 notice, this list of conditions and the following disclaimer in the
michael@0 13 documentation and/or other materials provided with the distribution.
michael@0 14
michael@0 15 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
michael@0 16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 18 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
michael@0 19 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
michael@0 23 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 26 -->
michael@0 27
michael@0 28 <title>SunSpider 3d-cube</title>
michael@0 29
michael@0 30 </head>
michael@0 31
michael@0 32 <body>
michael@0 33 <h3>3d-cube</h3>
michael@0 34 <div id="console">
michael@0 35 </div>
michael@0 36
michael@0 37 <script>
michael@0 38
michael@0 39 var _sunSpiderStartDate = new Date();
michael@0 40
michael@0 41 // 3D Cube Rotation
michael@0 42 // http://www.speich.net/computer/moztesting/3d.htm
michael@0 43 // Created by Simon Speich
michael@0 44
michael@0 45 var Q = new Array();
michael@0 46 var MTrans = new Array(); // transformation matrix
michael@0 47 var MQube = new Array(); // position information of qube
michael@0 48 var I = new Array(); // entity matrix
michael@0 49 var Origin = new Object();
michael@0 50 var Testing = new Object();
michael@0 51 var LoopTimer;
michael@0 52
michael@0 53 var DisplArea = new Object();
michael@0 54 DisplArea.Width = 300;
michael@0 55 DisplArea.Height = 300;
michael@0 56
michael@0 57 function DrawLine(From, To) {
michael@0 58 var x1 = From.V[0];
michael@0 59 var x2 = To.V[0];
michael@0 60 var y1 = From.V[1];
michael@0 61 var y2 = To.V[1];
michael@0 62 var dx = Math.abs(x2 - x1);
michael@0 63 var dy = Math.abs(y2 - y1);
michael@0 64 var x = x1;
michael@0 65 var y = y1;
michael@0 66 var IncX1, IncY1;
michael@0 67 var IncX2, IncY2;
michael@0 68 var Den;
michael@0 69 var Num;
michael@0 70 var NumAdd;
michael@0 71 var NumPix;
michael@0 72
michael@0 73 if (x2 >= x1) { IncX1 = 1; IncX2 = 1; }
michael@0 74 else { IncX1 = -1; IncX2 = -1; }
michael@0 75 if (y2 >= y1) { IncY1 = 1; IncY2 = 1; }
michael@0 76 else { IncY1 = -1; IncY2 = -1; }
michael@0 77 if (dx >= dy) {
michael@0 78 IncX1 = 0;
michael@0 79 IncY2 = 0;
michael@0 80 Den = dx;
michael@0 81 Num = dx / 2;
michael@0 82 NumAdd = dy;
michael@0 83 NumPix = dx;
michael@0 84 }
michael@0 85 else {
michael@0 86 IncX2 = 0;
michael@0 87 IncY1 = 0;
michael@0 88 Den = dy;
michael@0 89 Num = dy / 2;
michael@0 90 NumAdd = dx;
michael@0 91 NumPix = dy;
michael@0 92 }
michael@0 93
michael@0 94 NumPix = Math.round(Q.LastPx + NumPix);
michael@0 95
michael@0 96 var i = Q.LastPx;
michael@0 97 for (; i < NumPix; i++) {
michael@0 98 Num += NumAdd;
michael@0 99 if (Num >= Den) {
michael@0 100 Num -= Den;
michael@0 101 x += IncX1;
michael@0 102 y += IncY1;
michael@0 103 }
michael@0 104 x += IncX2;
michael@0 105 y += IncY2;
michael@0 106 }
michael@0 107 Q.LastPx = NumPix;
michael@0 108 }
michael@0 109
michael@0 110 function CalcCross(V0, V1) {
michael@0 111 var Cross = new Array();
michael@0 112 Cross[0] = V0[1]*V1[2] - V0[2]*V1[1];
michael@0 113 Cross[1] = V0[2]*V1[0] - V0[0]*V1[2];
michael@0 114 Cross[2] = V0[0]*V1[1] - V0[1]*V1[0];
michael@0 115 return Cross;
michael@0 116 }
michael@0 117
michael@0 118 function CalcNormal(V0, V1, V2) {
michael@0 119 var A = new Array(); var B = new Array();
michael@0 120 for (var i = 0; i < 3; i++) {
michael@0 121 A[i] = V0[i] - V1[i];
michael@0 122 B[i] = V2[i] - V1[i];
michael@0 123 }
michael@0 124 A = CalcCross(A, B);
michael@0 125 var Length = Math.sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
michael@0 126 for (var i = 0; i < 3; i++) A[i] = A[i] / Length;
michael@0 127 A[3] = 1;
michael@0 128 return A;
michael@0 129 }
michael@0 130
michael@0 131 function CreateP(X,Y,Z) {
michael@0 132 this.V = [X,Y,Z,1];
michael@0 133 }
michael@0 134
michael@0 135 // multiplies two matrices
michael@0 136 function MMulti(M1, M2) {
michael@0 137 var M = [[],[],[],[]];
michael@0 138 var i = 0;
michael@0 139 var j = 0;
michael@0 140 for (; i < 4; i++) {
michael@0 141 j = 0;
michael@0 142 for (; j < 4; j++) M[i][j] = M1[i][0] * M2[0][j] + M1[i][1] * M2[1][j] + M1[i][2] * M2[2][j] + M1[i][3] * M2[3][j];
michael@0 143 }
michael@0 144 return M;
michael@0 145 }
michael@0 146
michael@0 147 //multiplies matrix with vector
michael@0 148 function VMulti(M, V) {
michael@0 149 var Vect = new Array();
michael@0 150 var i = 0;
michael@0 151 for (;i < 4; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2] + M[i][3] * V[3];
michael@0 152 return Vect;
michael@0 153 }
michael@0 154
michael@0 155 function VMulti2(M, V) {
michael@0 156 var Vect = new Array();
michael@0 157 var i = 0;
michael@0 158 for (;i < 3; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2];
michael@0 159 return Vect;
michael@0 160 }
michael@0 161
michael@0 162 // add to matrices
michael@0 163 function MAdd(M1, M2) {
michael@0 164 var M = [[],[],[],[]];
michael@0 165 var i = 0;
michael@0 166 var j = 0;
michael@0 167 for (; i < 4; i++) {
michael@0 168 j = 0;
michael@0 169 for (; j < 4; j++) M[i][j] = M1[i][j] + M2[i][j];
michael@0 170 }
michael@0 171 return M;
michael@0 172 }
michael@0 173
michael@0 174 function Translate(M, Dx, Dy, Dz) {
michael@0 175 var T = [
michael@0 176 [1,0,0,Dx],
michael@0 177 [0,1,0,Dy],
michael@0 178 [0,0,1,Dz],
michael@0 179 [0,0,0,1]
michael@0 180 ];
michael@0 181 return MMulti(T, M);
michael@0 182 }
michael@0 183
michael@0 184 function RotateX(M, Phi) {
michael@0 185 var a = Phi;
michael@0 186 a *= Math.PI / 180;
michael@0 187 var Cos = Math.cos(a);
michael@0 188 var Sin = Math.sin(a);
michael@0 189 var R = [
michael@0 190 [1,0,0,0],
michael@0 191 [0,Cos,-Sin,0],
michael@0 192 [0,Sin,Cos,0],
michael@0 193 [0,0,0,1]
michael@0 194 ];
michael@0 195 return MMulti(R, M);
michael@0 196 }
michael@0 197
michael@0 198 function RotateY(M, Phi) {
michael@0 199 var a = Phi;
michael@0 200 a *= Math.PI / 180;
michael@0 201 var Cos = Math.cos(a);
michael@0 202 var Sin = Math.sin(a);
michael@0 203 var R = [
michael@0 204 [Cos,0,Sin,0],
michael@0 205 [0,1,0,0],
michael@0 206 [-Sin,0,Cos,0],
michael@0 207 [0,0,0,1]
michael@0 208 ];
michael@0 209 return MMulti(R, M);
michael@0 210 }
michael@0 211
michael@0 212 function RotateZ(M, Phi) {
michael@0 213 var a = Phi;
michael@0 214 a *= Math.PI / 180;
michael@0 215 var Cos = Math.cos(a);
michael@0 216 var Sin = Math.sin(a);
michael@0 217 var R = [
michael@0 218 [Cos,-Sin,0,0],
michael@0 219 [Sin,Cos,0,0],
michael@0 220 [0,0,1,0],
michael@0 221 [0,0,0,1]
michael@0 222 ];
michael@0 223 return MMulti(R, M);
michael@0 224 }
michael@0 225
michael@0 226 function DrawQube() {
michael@0 227 // calc current normals
michael@0 228 var CurN = new Array();
michael@0 229 var i = 5;
michael@0 230 Q.LastPx = 0;
michael@0 231 for (; i > -1; i--) CurN[i] = VMulti2(MQube, Q.Normal[i]);
michael@0 232 if (CurN[0][2] < 0) {
michael@0 233 if (!Q.Line[0]) { DrawLine(Q[0], Q[1]); Q.Line[0] = true; };
michael@0 234 if (!Q.Line[1]) { DrawLine(Q[1], Q[2]); Q.Line[1] = true; };
michael@0 235 if (!Q.Line[2]) { DrawLine(Q[2], Q[3]); Q.Line[2] = true; };
michael@0 236 if (!Q.Line[3]) { DrawLine(Q[3], Q[0]); Q.Line[3] = true; };
michael@0 237 }
michael@0 238 if (CurN[1][2] < 0) {
michael@0 239 if (!Q.Line[2]) { DrawLine(Q[3], Q[2]); Q.Line[2] = true; };
michael@0 240 if (!Q.Line[9]) { DrawLine(Q[2], Q[6]); Q.Line[9] = true; };
michael@0 241 if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; };
michael@0 242 if (!Q.Line[10]) { DrawLine(Q[7], Q[3]); Q.Line[10] = true; };
michael@0 243 }
michael@0 244 if (CurN[2][2] < 0) {
michael@0 245 if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; };
michael@0 246 if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; };
michael@0 247 if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; };
michael@0 248 if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; };
michael@0 249 }
michael@0 250 if (CurN[3][2] < 0) {
michael@0 251 if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; };
michael@0 252 if (!Q.Line[8]) { DrawLine(Q[5], Q[1]); Q.Line[8] = true; };
michael@0 253 if (!Q.Line[0]) { DrawLine(Q[1], Q[0]); Q.Line[0] = true; };
michael@0 254 if (!Q.Line[11]) { DrawLine(Q[0], Q[4]); Q.Line[11] = true; };
michael@0 255 }
michael@0 256 if (CurN[4][2] < 0) {
michael@0 257 if (!Q.Line[11]) { DrawLine(Q[4], Q[0]); Q.Line[11] = true; };
michael@0 258 if (!Q.Line[3]) { DrawLine(Q[0], Q[3]); Q.Line[3] = true; };
michael@0 259 if (!Q.Line[10]) { DrawLine(Q[3], Q[7]); Q.Line[10] = true; };
michael@0 260 if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; };
michael@0 261 }
michael@0 262 if (CurN[5][2] < 0) {
michael@0 263 if (!Q.Line[8]) { DrawLine(Q[1], Q[5]); Q.Line[8] = true; };
michael@0 264 if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; };
michael@0 265 if (!Q.Line[9]) { DrawLine(Q[6], Q[2]); Q.Line[9] = true; };
michael@0 266 if (!Q.Line[1]) { DrawLine(Q[2], Q[1]); Q.Line[1] = true; };
michael@0 267 }
michael@0 268 Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false];
michael@0 269 Q.LastPx = 0;
michael@0 270 }
michael@0 271
michael@0 272 function Loop() {
michael@0 273 if (Testing.LoopCount > Testing.LoopMax) return;
michael@0 274 var TestingStr = String(Testing.LoopCount);
michael@0 275 while (TestingStr.length < 3) TestingStr = "0" + TestingStr;
michael@0 276 MTrans = Translate(I, -Q[8].V[0], -Q[8].V[1], -Q[8].V[2]);
michael@0 277 MTrans = RotateX(MTrans, 1);
michael@0 278 MTrans = RotateY(MTrans, 3);
michael@0 279 MTrans = RotateZ(MTrans, 5);
michael@0 280 MTrans = Translate(MTrans, Q[8].V[0], Q[8].V[1], Q[8].V[2]);
michael@0 281 MQube = MMulti(MTrans, MQube);
michael@0 282 var i = 8;
michael@0 283 for (; i > -1; i--) {
michael@0 284 Q[i].V = VMulti(MTrans, Q[i].V);
michael@0 285 }
michael@0 286 DrawQube();
michael@0 287 Testing.LoopCount++;
michael@0 288 Loop();
michael@0 289 }
michael@0 290
michael@0 291 function Init(CubeSize) {
michael@0 292 // init/reset vars
michael@0 293 Origin.V = [150,150,20,1];
michael@0 294 Testing.LoopCount = 0;
michael@0 295 Testing.LoopMax = 50;
michael@0 296 Testing.TimeMax = 0;
michael@0 297 Testing.TimeAvg = 0;
michael@0 298 Testing.TimeMin = 0;
michael@0 299 Testing.TimeTemp = 0;
michael@0 300 Testing.TimeTotal = 0;
michael@0 301 Testing.Init = false;
michael@0 302
michael@0 303 // transformation matrix
michael@0 304 MTrans = [
michael@0 305 [1,0,0,0],
michael@0 306 [0,1,0,0],
michael@0 307 [0,0,1,0],
michael@0 308 [0,0,0,1]
michael@0 309 ];
michael@0 310
michael@0 311 // position information of qube
michael@0 312 MQube = [
michael@0 313 [1,0,0,0],
michael@0 314 [0,1,0,0],
michael@0 315 [0,0,1,0],
michael@0 316 [0,0,0,1]
michael@0 317 ];
michael@0 318
michael@0 319 // entity matrix
michael@0 320 I = [
michael@0 321 [1,0,0,0],
michael@0 322 [0,1,0,0],
michael@0 323 [0,0,1,0],
michael@0 324 [0,0,0,1]
michael@0 325 ];
michael@0 326
michael@0 327 // create qube
michael@0 328 Q[0] = new CreateP(-CubeSize,-CubeSize, CubeSize);
michael@0 329 Q[1] = new CreateP(-CubeSize, CubeSize, CubeSize);
michael@0 330 Q[2] = new CreateP( CubeSize, CubeSize, CubeSize);
michael@0 331 Q[3] = new CreateP( CubeSize,-CubeSize, CubeSize);
michael@0 332 Q[4] = new CreateP(-CubeSize,-CubeSize,-CubeSize);
michael@0 333 Q[5] = new CreateP(-CubeSize, CubeSize,-CubeSize);
michael@0 334 Q[6] = new CreateP( CubeSize, CubeSize,-CubeSize);
michael@0 335 Q[7] = new CreateP( CubeSize,-CubeSize,-CubeSize);
michael@0 336
michael@0 337 // center of gravity
michael@0 338 Q[8] = new CreateP(0, 0, 0);
michael@0 339
michael@0 340 // anti-clockwise edge check
michael@0 341 Q.Edge = [[0,1,2],[3,2,6],[7,6,5],[4,5,1],[4,0,3],[1,5,6]];
michael@0 342
michael@0 343 // calculate squad normals
michael@0 344 Q.Normal = new Array();
michael@0 345 for (var i = 0; i < Q.Edge.length; i++) Q.Normal[i] = CalcNormal(Q[Q.Edge[i][0]].V, Q[Q.Edge[i][1]].V, Q[Q.Edge[i][2]].V);
michael@0 346
michael@0 347 // line drawn ?
michael@0 348 Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false];
michael@0 349
michael@0 350 // create line pixels
michael@0 351 Q.NumPx = 9 * 2 * CubeSize;
michael@0 352 for (var i = 0; i < Q.NumPx; i++) CreateP(0,0,0);
michael@0 353
michael@0 354 MTrans = Translate(MTrans, Origin.V[0], Origin.V[1], Origin.V[2]);
michael@0 355 MQube = MMulti(MTrans, MQube);
michael@0 356
michael@0 357 var i = 0;
michael@0 358 for (; i < 9; i++) {
michael@0 359 Q[i].V = VMulti(MTrans, Q[i].V);
michael@0 360 }
michael@0 361 DrawQube();
michael@0 362 Testing.Init = true;
michael@0 363 Loop();
michael@0 364 }
michael@0 365
michael@0 366 for ( var i = 20; i <= 160; i *= 2 ) {
michael@0 367 Init(i);
michael@0 368 }
michael@0 369
michael@0 370 Q = null;
michael@0 371 MTrans = null;
michael@0 372 MQube = null;
michael@0 373 I = null;
michael@0 374 Origin = null;
michael@0 375 Testing = null;
michael@0 376 LoopTime = null;
michael@0 377 DisplArea = null;
michael@0 378
michael@0 379
michael@0 380 var _sunSpiderInterval = new Date() - _sunSpiderStartDate;
michael@0 381
michael@0 382 document.getElementById("console").innerHTML = _sunSpiderInterval;
michael@0 383 </script>
michael@0 384
michael@0 385
michael@0 386 </body>
michael@0 387 </html>

mercurial