Mercurial > hg > Members > e105711
changeset 1:4fd71be3fb0b draft
2nd,Get BGM's current time and output it to console.
author | e105711 <yomitan.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Apr 2012 00:34:45 +0900 |
parents | 9285dae61395 |
children | 55702e139f69 |
files | webGL/src/keybord.js webGL/src/sound.js webGL/test2.html |
diffstat | 3 files changed, 179 insertions(+), 176 deletions(-) [+] |
line wrap: on
line diff
--- a/webGL/src/keybord.js Wed Apr 25 23:45:59 2012 +0900 +++ b/webGL/src/keybord.js Thu Apr 26 00:34:45 2012 +0900 @@ -12,116 +12,116 @@ function keybordDown() { - var keyChar = String.fromCharCode(event.keyCode); - if(keyChar == "S" && !SPressed && MODE==MAIN) { + var keyChar = String.fromCharCode(event.keyCode); + if(keyChar == "S" && !SPressed && MODE==MAIN) { SPressed = true; if(HCloseCnt%2==0){ - audioStop(audioHClose2); - audioHClose.play(); + audioStop(audioHClose2); + audioHClose.play(); } else{ - audioStop(audioHClose); - audioHClose2.play(); + audioStop(audioHClose); + audioHClose2.play(); } HCloseCnt++; - } - if(keyChar == "D" && !DPressed && MODE==MAIN) { + } + if(keyChar == "D" && !DPressed && MODE==MAIN) { DPressed = true; if(SnareCnt%2==0){ - audioStop(audioSnare2); - audioSnare.play(); + audioStop(audioSnare2); + audioSnare.play(); } else{ - audioStop(audioSnare); - audioSnare2.play(); + audioStop(audioSnare); + audioSnare2.play(); } SnareCnt++; - } - if(keyChar == "F" && !FPressed && MODE==MAIN) { + } + if(keyChar == "F" && !FPressed && MODE==MAIN) { FPressed = true; if(KickCnt%2==0){ - audioStop(audioKick2); - audioKick.play(); + audioStop(audioKick2); + audioKick.play(); } else{ - audioStop(audioKick); - audioKick2.play(); + audioStop(audioKick); + audioKick2.play(); } KickCnt++; - } - if(keyChar == "J" && !JPressed && MODE==MAIN) { + } + if(keyChar == "J" && !JPressed && MODE==MAIN) { JPressed = true; if(FtomCnt%2==0){ - audioStop(audioFtom2); - audioFtom.play(); + audioStop(audioFtom2); + audioFtom.play(); } else{ - audioStop(audioFtom); - audioFtom2.play(); + audioStop(audioFtom); + audioFtom2.play(); } FtomCnt++; - } - if(keyChar == "K" && !KPressed && MODE==MAIN) { + } + if(keyChar == "K" && !KPressed && MODE==MAIN) { KPressed = true; if(CymbalCnt%2==0){ - audioStop(audioCymbal2); - audioCymbal.play(); + audioStop(audioCymbal2); + audioCymbal.play(); } else{ - audioStop(audioCymbal); - audioCymbal2.play(); + audioStop(audioCymbal); + audioCymbal2.play(); } CymbalCnt++; + } + + if(keyChar == " " && !SpacePressed){ + SpacePressed = true; + if(MODE==TITLE){ + MODE = MAIN; } - - if(keyChar == " " && !SpacePressed){ - SpacePressed = true; - if(MODE==TITLE){ - MODE = MAIN; - } - else{ - if(!PlayingBGM){ - PlayingBGM = true; - console.log("play"); - audioBGM.play(); - } - else{ - console.log("stop"); - audioStop(audioBGM); - PlayingBGM = false; - } - } - } - console.log("Key: Pushed '"+keyChar+"'"); - + else{ + if(!PlayingBGM){ + PlayingBGM = true; + console.log("play"); + audioBGM.play(); + } + else{ + console.log("stop"); + audioStop(audioBGM); + PlayingBGM = false; + } + } + } + console.log("Key: Pushed '"+keyChar+"'"); + } function keybordPress(){} function keybordUp() { - var keyChar = String.fromCharCode(event.keyCode); - if(keyChar == "S"){ + var keyChar = String.fromCharCode(event.keyCode); + if(keyChar == "S"){ SPressed = false; - } - if(keyChar == "D"){ + } + if(keyChar == "D"){ DPressed = false; - } - if(keyChar == "F"){ + } + if(keyChar == "F"){ FPressed = false; - } - if(keyChar == "J"){ + } + if(keyChar == "J"){ JPressed = false; - } - if(keyChar == "K"){ + } + if(keyChar == "K"){ KPressed = false; - } - if(keyChar == "Q"){ + } + if(keyChar == "Q"){ JPressed = false; - } - if(keyChar == "A"){ + } + if(keyChar == "A"){ KPressed = false; - } - if(keyChar == " "){ + } + if(keyChar == " "){ SpacePressed = false; - } + } }
--- a/webGL/src/sound.js Wed Apr 25 23:45:59 2012 +0900 +++ b/webGL/src/sound.js Thu Apr 26 00:34:45 2012 +0900 @@ -29,4 +29,8 @@ function audioStart(audioFile){ audioFile.load(); audioFile.play(); +} + +function getBGMTime(){ + return audioBGM.currentTime; } \ No newline at end of file
--- a/webGL/test2.html Wed Apr 25 23:45:59 2012 +0900 +++ b/webGL/test2.html Thu Apr 26 00:34:45 2012 +0900 @@ -2,124 +2,123 @@ <html> <head> - <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> - <title>WebGL test2</title> - <script src="src/keybord.js"></script> - <script src="src/sound.js"></script> - <script src="src/J3DI.js"></script> - <script src="src/J3DIMath.js"></script> - <script src="src/f4xml.js"></script> - <script src="src/const.js"></script> - <script src="src/mainfunc.js"></script> - <script src="src/jkl-parsexml.js"></script> + <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> + <title>WebGL test2</title> + <script src="src/keybord.js"></script> + <script src="src/sound.js"></script> + <script src="src/J3DI.js"></script> + <script src="src/J3DIMath.js"></script> + <script src="src/f4xml.js"></script> + <script src="src/const.js"></script> + <script src="src/mainfunc.js"></script> + <script src="src/jkl-parsexml.js"></script> </head> <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); - } + 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); + } </script> <script id="fshader" type="x-shader/x-fragment"> - #ifdef GL_ES - precision mediump float; - #endif - - 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); - // 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); - } + #ifdef GL_ES + precision mediump float; + #endif + + 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); + // 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); + } </script> <script> - - var WIDTH = 1024; - var HEIGHT = 640; - var MODE = TITLE; - function start(){ - var c = document.getElementById("example"); - c.width = WIDTH; - c.height = HEIGHT; - var ctx = init(); - l = function(){loop(ctx)}; - setInterval(l,10); - } - - 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); - - return gl; - } - - function loop(ctx){ //main loop - gameRender(ctx,MODE); - } - - width = -1; - height = -1; - - function reshape(ctx) - { - 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 J3DIMatrix4(); - ctx.perspectiveMatrix.ortho(0, -200, 0, -140, 0, 10000); - } - - - - + + var WIDTH = 1024; + var HEIGHT = 640; + var MODE = TITLE; + function start(){ + var c = document.getElementById("example"); + c.width = WIDTH; + c.height = HEIGHT; + var ctx = init(); + l = function(){loop(ctx)}; + setInterval(l,10); + } + + 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); + + return gl; + } + + function loop(ctx){ //main loop + gameRender(ctx,MODE); + if(MODE==MAIN){ + console.log(getBGMTime()); + } + } + + width = -1; + height = -1; + + function reshape(ctx) + { + 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 J3DIMatrix4(); + ctx.perspectiveMatrix.ortho(0, -200, 0, -140, 0, 10000); + } + </script> <style type="text/css"> - canvas { - border: 2px solid black; - } + canvas { + border: 2px solid black; + } </style> <body onload="start()" onkeydown="keybordDown()" onkeypress="keybordPress()" onkeyup="keybordUp()" style='overflow:scroll'> - <font size="4"> - TITLE) SPACE:Go to MAIN MODE<br> - MAIN MODE)S:High-hat D:Snare F:Kick J:Tom K:Cymbal SPACE:Play/Stop <!--A:AUTO PLAY<br>--> -<!-- AUTO PLAY)Q:Quit(Back to MAIN MODE)--> - </font> - <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> + <font size="4"> + TITLE) SPACE:Go to MAIN MODE<br> + MAIN MODE)S:High-hat D:Snare F:Kick J:Tom K:Cymbal SPACE:Play/Stop <!--A:AUTO PLAY<br>--> + <!-- AUTO PLAY)Q:Quit(Back to MAIN MODE)--> + </font> + <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> </body> </html> -