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