changeset 4:86eb5933aeb9

fix keyboard.js
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 15 Apr 2012 19:17:56 +0900
parents d17004426a74
children 85896f291a95
files drawObj/drawObj.html drawObj/resources/keyboard.js
diffstat 2 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/drawObj/drawObj.html	Sun Apr 15 19:03:54 2012 +0900
+++ b/drawObj/drawObj.html	Sun Apr 15 19:17:56 2012 +0900
@@ -45,10 +45,10 @@
     {
     vec4 color = texture2D(sampler2d,v_texCoord);
     color += vec4(0.1,0.1,0.1,1);
-    if(color.a == 1.0)color=vec4(1,0,0,1);
-    else color=vec4(0,1,1,1);
+//    if(color.a == 1.0)color=vec4(1,0,0,1);
+//    else color=vec4(0,1,1,1);
     gl_FragColor = vec4(color.xyz * v_Dot, color.a);
-    gl_FragColor = vec4(color.xyz * v_Dot, 0.5);
+//    gl_FragColor = vec4(color.xyz * v_Dot, 0.5);
     }
   </script> 
 		
@@ -102,7 +102,7 @@
     {
     ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
     
-    PutSpriteV(ctx, 0, 0, -10, 2, matrix, object);
+    PutSpriteV(ctx, X, Y, Z, 2, matrix, object);
 
     ctx.flush();
 
@@ -133,6 +133,9 @@
     {
     var ortho = {left:0, right:200, bottom:140, top:0}
     matrix = new J3DIMatrix4(); // global variable
+    X = 0; 
+    Y = 0;
+    Z = -10;
 
 //    var c = document.getElementById("game");
 //    c.width = W;
--- a/drawObj/resources/keyboard.js	Sun Apr 15 19:03:54 2012 +0900
+++ b/drawObj/resources/keyboard.js	Sun Apr 15 19:17:56 2012 +0900
@@ -1,7 +1,22 @@
 function keyboardDown()
 {
-
-
+    var d=-Z/20;
+    switch(String.fromCharCode(event.keyCode)) {
+	case 'w':
+	Z+=d;
+	break;
+	case 'a':
+	X-=d;
+	break;
+	case 's':
+	Z-=d;
+	break;
+	case 'd':
+	X+=d;
+	break;
+	default:
+	break;
+    }
 }
 
 function keyboardUp()
@@ -12,6 +27,22 @@
 
 function keyboardPress()
 {
-
+    var d=-Z/20;
+    switch(String.fromCharCode(event.keyCode)) {
+	case 'w':
+	Z+=d;
+	break;
+	case 'a':
+	X-=d;
+	break;
+	case 's':
+	Z-=d;
+	break;
+	case 'd':
+	X+=d;
+	break;
+	default:
+	break;
+    }
 
 }
\ No newline at end of file