Skip to content

Instantly share code, notes, and snippets.

@vthibault
Last active November 6, 2016 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vthibault/9d5c08c111db2eabfc37 to your computer and use it in GitHub Desktop.
Save vthibault/9d5c08c111db2eabfc37 to your computer and use it in GitHub Desktop.
roBrowser - Keyboard support to move
// Dependencies
var glMatrix = require('Vendors/gl-matrix');
var Camera = require('Renderer/Camera');
var vec2 = glMatrix.vec2;
var mat2 = glMatrix.mat2;
// Object to initialize
var direction = vec2.create();
var rotate = mat2.create();
//---- Now the job ----
function processKeyEvent( event ) {
// Get direction from keyboard
direction[0] = (event.which === KEYS.RIGHT ? -1 :
event.which === KEYS.LEFT ? +1 :
0);
direction[1] = (event.which === KEYS.UP ? +1 :
event.which === KEYS.DOWN ? -1 :
0);
// Initialize matrix, based on Camera direction
mat2.identity(rotate);
mat2.rotate(rotate, rotate, -Camera.direction * 45 / 180 * Math.PI);
// Apply matrix to vector
vec2.transformMat2( direction, direction, rotate);
// You now have "direction" containing the direction based on the camera.
// (value from -1 to 1).
direction;
}
@Yump999
Copy link

Yump999 commented Nov 6, 2016

please accept me forum 'robrowser' email applive3@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment