annotate webGL/test/TestXml3.html @ 0:b67b790dcf4f

upload All File
author e085711@nobuyasuoshiro.local
date Mon, 24 May 2010 21:38:02 +0900
parents
children 94c790cbd930
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
1 <!DOCTYPE html>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
2 <!--
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
3 /*
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
4 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
5 *
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
7 * modification, are permitted provided that the following conditions
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
8 * are met:
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
11 * 2. Redistributions in binary form must reproduce the above copyright
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
12 * notice, this list of conditions and the following disclaimer in the
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
13 * documentation and/or other materials provided with the distribution.
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
14 *
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
26 */
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
27 -->
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
28 <html>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
29 <head>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
30 <title>Earth and Mars</title>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
31 <script src="resources/CanvasMatrix.js"> </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
32 <script src="resources/utils3d.js"> </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
33 <script src="resources/jkl-parsexml.js"> </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
34 <script src="resources/makeXmlObj.js"> </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
35
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
36 <script id="vshader" type="x-shader/x-vertex">
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
37 uniform mat4 u_modelViewProjMatrix;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
38 uniform mat4 u_normalMatrix;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
39 uniform vec3 lightDir;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
40
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
41 attribute vec3 vNormal;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
42 attribute vec4 vTexCoord;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
43 attribute vec4 vPosition;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
44
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
45 varying float v_Dot;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
46 varying vec2 v_texCoord;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
47
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
48 void main()
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
49 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
50 gl_Position = u_modelViewProjMatrix * vPosition;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
51 v_texCoord = vTexCoord.st;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
52 vec4 transNormal = u_normalMatrix * vec4(vNormal,1);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
53 v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
54 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
55 </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
56
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
57 <script id="fshader" type="x-shader/x-fragment">
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
58 uniform sampler2D sampler2d;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
59
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
60 varying float v_Dot;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
61 varying vec2 v_texCoord;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
62
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
63 void main()
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
64 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
65 vec4 color = texture2D(sampler2d,v_texCoord);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
66 color += vec4(0.1,0.1,0.1,1);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
67 gl_FragColor = vec4(color.xyz * v_Dot, color.a);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
68 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
69 </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
70
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
71 <script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
72 function init()
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
73 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
74 var gl = initWebGL("example", "vshader", "fshader",
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
75 [ "vNormal", "vTexCoord", "vPosition"],
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
76 [ 0, 0, 0, 1 ], 10000);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
77
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
78 gl.uniform3f(gl.getUniformLocation(gl.program, "lightDir"), 0, 0, 1);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
79 gl.uniform1i(gl.getUniformLocation(gl.program, "sampler2d"), 0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
80
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
81 gl.enable(gl.TEXTURE_2D);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
82 gl.obj = new Object();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
83 for (var name in xmlObj) {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
84 gl.obj[name] = makeXmlObj(gl, xmlObj[name]);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
85 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
86
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
87 // get the images
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
88 earthTexture = loadImageTexture(gl, "resources/earthmap1k.jpg");
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
89 marsTexture = loadImageTexture(gl, "resources/mars500x250.png");
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
90
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
91
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
92 testTexture = loadImageTexture(gl, testImage);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
93
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
94 return gl;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
95 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
96
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
97 width = -1;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
98 height = -1;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
99
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
100 function reshape(ctx)
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
101 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
102 var canvas = document.getElementById('example');
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
103 if (canvas.width == width && canvas.width == height)
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
104 return;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
105
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
106 width = canvas.width;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
107 height = canvas.height;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
108
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
109 ctx.viewport(0, 0, width, height);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
110
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
111 ctx.perspectiveMatrix = new CanvasMatrix4();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
112 ctx.perspectiveMatrix.lookat(0,0,6, 0, 0, 0, 0, 1, 0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
113 ctx.perspectiveMatrix.perspective(30, width/height, 1, 10000);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
114 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
115
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
116 function drawOne(ctx, glObj, angle, x, y, z, scale, texture)
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
117 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
118 // setup VBOs
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
119 ctx.enableVertexAttribArray(0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
120 ctx.enableVertexAttribArray(1);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
121 ctx.enableVertexAttribArray(2);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
122
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
123 ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.vertexObject);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
124 ctx.vertexAttribPointer(2, 3, ctx.FLOAT, false, 0, 0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
125
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
126 ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.normalObject);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
127 ctx.vertexAttribPointer(0, 3, ctx.FLOAT, false, 0, 0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
128
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
129 ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.texCoordObject);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
130 ctx.vertexAttribPointer(1, 2, ctx.FLOAT, false, 0, 0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
131
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
132 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, glObj.indexObject);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
133
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
134 // generate the model-view matrix
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
135 var mvMatrix = new CanvasMatrix4();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
136 mvMatrix.scale(scale, scale, scale);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
137 mvMatrix.rotate(angle, 0,1,0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
138 mvMatrix.rotate(30, 1,0,0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
139 mvMatrix.translate(x,y,z);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
140
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
141 // construct the normal matrix from the model-view matrix
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
142 var normalMatrix = new CanvasMatrix4(mvMatrix);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
143 normalMatrix.invert();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
144 normalMatrix.transpose();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
145 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_normalMatrix"), false, normalMatrix.getAsWebGLFloatArray());
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
146
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
147 // construct the model-view * projection matrix
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
148 var mvpMatrix = new CanvasMatrix4(mvMatrix);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
149 mvpMatrix.multRight(ctx.perspectiveMatrix);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
150 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray());
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
151
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
152 ctx.bindTexture(ctx.TEXTURE_2D, texture);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
153 ctx.drawElements(ctx.TRIANGLES, glObj.numIndices, ctx.UNSIGNED_SHORT, 0);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
154 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
155
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
156 function drawPicture(ctx)
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
157 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
158 reshape(ctx);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
159 ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
160
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
161 for (var name in ctx.obj) {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
162 // drawOne(ctx, ctx.obj[name], currentAngle, 0, 0, 0, 0.005, testTexture);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
163 drawOne(ctx, ctx.obj[name], currentAngle, 0, 0, 0, 0.005, marsTexture);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
164 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
165
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
166 ctx.flush();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
167
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
168 framerate.snapshot();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
169
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
170 currentAngle += incAngle;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
171 if (currentAngle > 360)
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
172 currentAngle -= 360;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
173 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
174
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
175 function start()
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
176 {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
177 //xmlファイル読み込み
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
178 xmlObj = parseXml("./xml/Companioncube.xml");
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
179
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
180 var url = "./xml/Companioncube.xml";
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
181 var http = new JKL.ParseXML( url );
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
182 var data = http.parse();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
183 xmlObjImage = data["OBJECT-3D"]["surface"]["image"];
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
184 testImage = 'data:image/png;base64,'+xmlObjImage["#text"];
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
185
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
186 document.getElementById("test").src=testImage;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
187
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
188 var c = document.getElementById("example");
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
189 var w = Math.floor(window.innerWidth * 0.9);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
190 var h = Math.floor(window.innerHeight * 0.9);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
191
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
192 c.width = w;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
193 c.height = h;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
194
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
195 var ctx = init();
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
196 currentAngle = 0;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
197 incAngle = 0.2;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
198 var f = function() { drawPicture(ctx) };
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
199 setInterval(f, 10);
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
200 framerate = new Framerate("framerate");
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
201 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
202 </script>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
203 <style type="text/css">
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
204 canvas {
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
205 border: 2px solid black;
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
206 }
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
207 </style>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
208 </head>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
209 <body onload="start()">
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
210 <canvas id="example">
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
211 There is supposed to be an example drawing here, but it's not important.
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
212 </canvas>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
213 <div id="framerate"></div>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
214 <div id="console"></div>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
215
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
216 <img id="test" style="border:1px solid red">
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
217
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
218 </body>
b67b790dcf4f upload All File
e085711@nobuyasuoshiro.local
parents:
diff changeset
219 </html>