-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebgl-iostream-v1.0.min.js
5 lines (5 loc) · 1.68 KB
/
webgl-iostream-v1.0.min.js
1
2
3
4
5
var keys={};var mouse={x:0,y:0,dx:0,dy:0,pressed:!1,released:!1,isPressed:!1,leftIsPressed:!1,rightIsPressed:!1,reset:function(){this.dx=0;this.dy=0;this.pressed=!1;this.released=!1;return!0}};var pointerLock=document.body.requestPointerLock||document.body.mozRequestPointerLock;var exitPointerLock=document.body.exitPointerLock||document.body.mozExitPointerLock;function isLocked(){if(document.pointerLockElement!==null){document.addEventListener("mousemove",mouseMove)}else{document.removeEventListener("mousemove",mouseMove)}};function mouseMove(input){mouse.dx=input.movementX;mouse.dy=input.movementY};function mousePress(input){mouse.pressed=!0;mouse.isPressed=!0;if(input.button==0){mouse.button="left";mouse.leftIsPressed=!0}else{mouse.button="right";mouse.rightIsPressed=!0}};function mouseRelease(input){mouse.released=!0;mouse.isPressed=!1;mouse.button=undefined;if(input.button===0){mouse.leftIsPressed=!1}else{mouse.rightIsPressed=!1}};function keyPress(input){let key=input.code;if(key.includes("Key")){key=key.slice(3)}
if(key.includes("Arrow")){key=key.slice(5)}
keys[key.toUpperCase()]=!0};function keyRelease(input){let key=input.code;if(key.includes("Key")){key=key.slice(3)}
if(key.includes("Arrow")){key=key.slice(5)}
keys[key.toUpperCase()]=!1};document.body.addEventListener('keydown',function(event){event.preventDefault()});document.addEventListener("mousedown",mousePress);document.addEventListener("mouseup",mouseRelease);document.getElementsByTagName("canvas")[0].onclick=pointerLock;document.addEventListener("pointerlockchange",isLocked);document.addEventListener("mozpointerlockchange",isLocked);document.addEventListener("keydown",keyPress);document.addEventListener("keyup",keyRelease)