diff webGL/dandy/dandy4.html @ 8:03b67cd2bde7

upload parse.js
author NOBUYASU Oshiro
date Fri, 09 Jul 2010 01:48:59 +0900
parents
children 1d76f5717ba7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webGL/dandy/dandy4.html	Fri Jul 09 01:48:59 2010 +0900
@@ -0,0 +1,193 @@
+<!DOCTYPE html> 
+<!--
+ /*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+ --> 
+<html> 
+	<head> 
+		<title>WebGL dandy</title> 
+		<script src="resources/CanvasMatrix.js"> </script> 
+		<script src="resources/utils3d.js"> </script> 
+		<script src="resources/jkl-parsexml.js"> </script>    
+		<script src="resources/makePanel.js"> </script> 
+		<script src="resources/Character_state.js"> </script> 
+		<script src="resources/Character.js"> </script> 
+		<script src="resources/schedule.js"> </script> 
+		<script src="resources/Player.js"> </script> 
+		<script src="resources/enemy.js"> </script> 
+		<script src="resources/bullet.js"> </script> 
+		<script src="resources/collision.js"> </script> 
+		<script src="resources/constKey.js"> </script> 
+		<script src="resources/keybord.js"> </script> 
+		<script src="resources/boss.js"> </script> 
+		<script src="resources/parse.js"> </script> 
+        
+		<script id="vshader" type="x-shader/x-vertex"> 
+			uniform mat4 u_modelViewProjMatrix;
+			uniform mat4 u_normalMatrix;
+			uniform vec3 lightDir;
+			
+			attribute vec3 vNormal;
+			attribute vec4 vTexCoord;
+			attribute vec4 vPosition;
+			
+			varying float v_Dot;
+			varying vec2 v_texCoord;
+			
+			void main()
+			{
+				gl_Position = u_modelViewProjMatrix * vPosition;
+				v_texCoord = vTexCoord.st;
+				vec4 transNormal = u_normalMatrix * vec4(vNormal,1);
+				v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
+//				v_Dot = min(dot(transNormal.xyz, lightDir), 1.0);
+			}
+			</script> 
+		
+		<script id="fshader" type="x-shader/x-fragment"> 
+			uniform sampler2D sampler2d;
+			
+			varying float v_Dot;
+			varying vec2 v_texCoord;
+			
+			void main()
+			{
+				vec4 color = texture2D(sampler2d,v_texCoord);
+				color += vec4(0.1,0.1,0.1,1);
+				gl_FragColor = vec4(color.xyz * v_Dot, color.a);
+//				gl_FragColor = vec4(color.xyz * v_Dot, 0.5);
+			}
+			</script> 
+		
+		<script> 
+		        //audioの試運転
+			var audio = window.Audio && new Audio("sound/sample.wav");
+			var audioShoot = window.Audio && new Audio("sound/shota.wav");
+
+			//画面(canvas)の大きさ
+			var w = 1024;
+		        var h = 640;
+
+
+
+			function init()
+			{
+				var gl = initWebGL("example", "vshader", "fshader", 
+								   [ "vNormal", "vTexCoord", "vPosition"],
+								   [ 0, 0, 0, 1 ], 10000);
+				
+				gl.uniform3f(gl.getUniformLocation(gl.program, "lightDir"), 0, 0, 1);
+				gl.uniform1i(gl.getUniformLocation(gl.program, "sampler2d"), 0);
+				
+				gl.enable(gl.TEXTURE_2D);
+
+               			parseXml(gl);//parse.js
+
+				return gl;
+			}
+			
+			width = -1;
+			height = -1;
+			
+			function reshape(ctx, ortho)
+			{
+				var canvas = document.getElementById('example');
+				if (canvas.width == width && canvas.width == height)
+				return;
+
+				
+				width = canvas.width;
+				height = canvas.height;
+				
+				ctx.viewport(0, 0, width, height);
+				
+				ctx.perspectiveMatrix = new CanvasMatrix4();
+			        ctx.perspectiveMatrix.lookat(0,0,-60, 0, 0, 0, 0, 1, 0);
+				ctx.perspectiveMatrix.ortho(ortho.left, ortho.right, ortho.top, -ortho.bottom, 0, 10000);
+			}
+			
+
+
+			function loop(ctx, ortho)
+			{
+
+				reshape(ctx, ortho);
+				ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
+			
+
+			        Player(ctx, jiki, pad, ortho);
+			        obj_draw(ctx);
+
+				ctx.flush();
+
+				filpcount++;
+			        schedule();
+		                state_update();
+			        collision_detect();
+			
+				framerate.snapshot();
+
+			}
+
+			function start()
+			{
+
+               			var ortho = makeOrthoPara(0,200,140,0);
+//               			var ortho = makeOrthoPara(-100,100,-70,70);
+			
+			        audio && audio.play();//audio Test
+
+				var c = document.getElementById("example");
+
+
+			        //画面の大きさ
+				c.width = w;
+				c.height = h;
+
+				var ctx = init();
+
+				currentAngle = 0;
+				var f = function() { loop(ctx, ortho) };
+				setInterval(f, 10);
+				framerate = new Framerate("framerate");
+			}
+			</script> 
+		<style type="text/css"> 
+			canvas {
+				border: 2px solid black;
+			}
+			</style> 
+	</head> 
+	<body onload="start()" onkeydown="keybordDown()" onkeypress="keybordPress()" onkeyup="keybordUp()" style='overflow:hidden'> 
+		<canvas id="example"> 
+			There is supposed to be an example drawing here, but it's not important.
+		</canvas> 
+		<div id="framerate"></div> 
+		<div id="console"></div> 
+		
+		<img id="test" style="border:1px solid red">
+			
+			</body> 
+</html>