8
|
1 <!DOCTYPE html>
|
|
2 <!--
|
|
3 /*
|
|
4 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
|
|
5 *
|
|
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.
|
|
14 *
|
|
15 * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 */
|
|
27 -->
|
|
28 <html>
|
|
29 <head>
|
|
30 <title>WebGL dandy</title>
|
|
31 <script src="resources/CanvasMatrix.js"> </script>
|
|
32 <script src="resources/utils3d.js"> </script>
|
|
33 <script src="resources/jkl-parsexml.js"> </script>
|
|
34 <script src="resources/makePanel.js"> </script>
|
|
35 <script src="resources/Character_state.js"> </script>
|
|
36 <script src="resources/Character.js"> </script>
|
|
37 <script src="resources/schedule.js"> </script>
|
|
38 <script src="resources/Player.js"> </script>
|
|
39 <script src="resources/enemy.js"> </script>
|
|
40 <script src="resources/bullet.js"> </script>
|
|
41 <script src="resources/collision.js"> </script>
|
|
42 <script src="resources/constKey.js"> </script>
|
|
43 <script src="resources/keybord.js"> </script>
|
|
44 <script src="resources/boss.js"> </script>
|
|
45 <script src="resources/parse.js"> </script>
|
9
|
46 <script src="resources/bom.js"> </script>
|
11
|
47 <script src="resources/pause.js"> </script>
|
|
48 <script src="resources/tama.js"> </script>
|
|
49 <script src="resources/sankaku.js"> </script>
|
8
|
50
|
|
51 <script id="vshader" type="x-shader/x-vertex">
|
|
52 uniform mat4 u_modelViewProjMatrix;
|
|
53 uniform mat4 u_normalMatrix;
|
|
54 uniform vec3 lightDir;
|
|
55
|
|
56 attribute vec3 vNormal;
|
|
57 attribute vec4 vTexCoord;
|
|
58 attribute vec4 vPosition;
|
|
59
|
|
60 varying float v_Dot;
|
|
61 varying vec2 v_texCoord;
|
|
62
|
|
63 void main()
|
|
64 {
|
|
65 gl_Position = u_modelViewProjMatrix * vPosition;
|
|
66 v_texCoord = vTexCoord.st;
|
|
67 vec4 transNormal = u_normalMatrix * vec4(vNormal,1);
|
|
68 v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
|
|
69 // v_Dot = min(dot(transNormal.xyz, lightDir), 1.0);
|
|
70 }
|
|
71 </script>
|
|
72
|
|
73 <script id="fshader" type="x-shader/x-fragment">
|
|
74 uniform sampler2D sampler2d;
|
|
75
|
|
76 varying float v_Dot;
|
|
77 varying vec2 v_texCoord;
|
|
78
|
|
79 void main()
|
|
80 {
|
|
81 vec4 color = texture2D(sampler2d,v_texCoord);
|
|
82 color += vec4(0.1,0.1,0.1,1);
|
|
83 gl_FragColor = vec4(color.xyz * v_Dot, color.a);
|
|
84 // gl_FragColor = vec4(color.xyz * v_Dot, 0.5);
|
|
85 }
|
|
86 </script>
|
|
87
|
|
88 <script>
|
|
89 //audioの試運転
|
|
90 var audio = window.Audio && new Audio("sound/sample.wav");
|
|
91 var audioShoot = window.Audio && new Audio("sound/shota.wav");
|
|
92
|
|
93 //画面(canvas)の大きさ
|
|
94 var w = 1024;
|
|
95 var h = 640;
|
|
96
|
|
97
|
|
98
|
|
99 function init()
|
|
100 {
|
|
101 var gl = initWebGL("example", "vshader", "fshader",
|
|
102 [ "vNormal", "vTexCoord", "vPosition"],
|
|
103 [ 0, 0, 0, 1 ], 10000);
|
|
104
|
|
105 gl.uniform3f(gl.getUniformLocation(gl.program, "lightDir"), 0, 0, 1);
|
|
106 gl.uniform1i(gl.getUniformLocation(gl.program, "sampler2d"), 0);
|
|
107
|
|
108 gl.enable(gl.TEXTURE_2D);
|
|
109
|
11
|
110 sankakuf();//mycos,mysinの作成 sankaku.js
|
9
|
111
|
|
112 parseXml(gl);//parse.js
|
8
|
113
|
|
114 return gl;
|
|
115 }
|
|
116
|
|
117 width = -1;
|
|
118 height = -1;
|
|
119
|
|
120 function reshape(ctx, ortho)
|
|
121 {
|
|
122 var canvas = document.getElementById('example');
|
|
123 if (canvas.width == width && canvas.width == height)
|
|
124 return;
|
|
125
|
|
126
|
|
127 width = canvas.width;
|
|
128 height = canvas.height;
|
|
129
|
|
130 ctx.viewport(0, 0, width, height);
|
|
131
|
|
132 ctx.perspectiveMatrix = new CanvasMatrix4();
|
|
133 ctx.perspectiveMatrix.lookat(0,0,-60, 0, 0, 0, 0, 1, 0);
|
|
134 ctx.perspectiveMatrix.ortho(ortho.left, ortho.right, ortho.top, -ortho.bottom, 0, 10000);
|
|
135 }
|
|
136
|
|
137
|
|
138
|
|
139 function loop(ctx, ortho)
|
|
140 {
|
|
141 reshape(ctx, ortho);
|
|
142 ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
|
|
143
|
11
|
144
|
8
|
145 Player(ctx, jiki, pad, ortho);
|
11
|
146
|
8
|
147 obj_draw(ctx);
|
|
148
|
11
|
149 PutBom(ctx);
|
|
150 pause();
|
|
151
|
|
152
|
8
|
153 ctx.flush();
|
|
154
|
|
155 filpcount++;
|
|
156 schedule();
|
11
|
157
|
8
|
158 state_update();
|
11
|
159
|
8
|
160 collision_detect();
|
11
|
161 delete_obj( ctx )
|
9
|
162
|
8
|
163 framerate.snapshot();
|
|
164 }
|
|
165
|
11
|
166 function opening(ctx, ortho)
|
|
167 {
|
|
168 reshape(ctx, ortho);
|
|
169 ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
|
|
170
|
|
171 PutSpriteF(ctx, 100, 70, 1, font[10]);
|
|
172 PutSpriteF(ctx, 170, 50, 1, font[11]);
|
|
173 PutSpriteF(ctx, 40, 120, 1, font[12]);
|
|
174
|
|
175 ctx.flush();
|
|
176 if(pad.start == 0) {setTimeout(o, 10);}
|
|
177 if(pad.start != 0) { audio && audio.play();//audio Test
|
|
178 setInterval(f, 10);}
|
|
179 }
|
8
|
180 function start()
|
|
181 {
|
|
182
|
|
183 var ortho = makeOrthoPara(0,200,140,0);
|
|
184
|
|
185 var c = document.getElementById("example");
|
|
186
|
|
187
|
|
188 //画面の大きさ
|
|
189 c.width = w;
|
|
190 c.height = h;
|
|
191
|
|
192 var ctx = init();
|
|
193
|
|
194 currentAngle = 0;
|
11
|
195 // var f = function() { loop(ctx, ortho) };
|
|
196 f = function() { loop(ctx, ortho) };
|
|
197 o = function() {opening(ctx, ortho)}
|
|
198 setTimeout(o, 10);
|
|
199 // if(pad.start != 0) setInterval(f, 10);
|
|
200 // setInterval(f, 10);
|
8
|
201 framerate = new Framerate("framerate");
|
|
202 }
|
|
203 </script>
|
|
204 <style type="text/css">
|
|
205 canvas {
|
|
206 border: 2px solid black;
|
|
207 }
|
|
208 </style>
|
|
209 </head>
|
|
210 <body onload="start()" onkeydown="keybordDown()" onkeypress="keybordPress()" onkeyup="keybordUp()" style='overflow:hidden'>
|
|
211 <canvas id="example">
|
|
212 There is supposed to be an example drawing here, but it's not important.
|
|
213 </canvas>
|
|
214 <div id="framerate"></div>
|
|
215 <div id="console"></div>
|
|
216
|
|
217 <img id="test" style="border:1px solid red">
|
|
218
|
|
219 </body>
|
|
220 </html>
|