59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import $ from 'jquery';
|
|
|
|
/**
|
|
* UI block to update object
|
|
* @param {any} context the program context
|
|
*/
|
|
export function initUX(context: any) {
|
|
$('#glCanvas').mousemove((event) => {
|
|
if (context.params.mousePrev.x == null) {
|
|
context.params.mousePrev.x = event.pageX;
|
|
context.params.mousePrev.y = event.pageY;
|
|
}
|
|
context.params.camRot.y +=
|
|
(context.params.mousePrev.x - event.pageX) / 100;
|
|
context.params.camRot.x +=
|
|
(context.params.mousePrev.y - event.pageY) / 100;
|
|
context.params.mousePrev.x = event.pageX;
|
|
context.params.mousePrev.y = event.pageY;
|
|
});
|
|
$('#glCanvas').mouseenter((event) => {
|
|
context.params.mousePrev.x = event.pageX;
|
|
context.params.mousePrev.y = event.pageY;
|
|
});
|
|
$(document).keydown((event) => {
|
|
if (event.key == 'Shift') {
|
|
context.params.keyboard.shift = true;
|
|
}
|
|
if (event.key == 'w') {
|
|
context.params.keyboard.w = true;
|
|
}
|
|
if (event.key == 's') {
|
|
context.params.keyboard.s = true;
|
|
}
|
|
if (event.key == 'a') {
|
|
context.params.keyboard.a = true;
|
|
}
|
|
if (event.key == 'd') {
|
|
context.params.keyboard.d = true;
|
|
}
|
|
});
|
|
$(document).keyup((event) => {
|
|
if (event.key == 'Shift') {
|
|
context.params.keyboard.shift = false;
|
|
}
|
|
if (event.key == 'w') {
|
|
context.params.keyboard.w = false;
|
|
}
|
|
if (event.key == 's') {
|
|
context.params.keyboard.s = false;
|
|
}
|
|
if (event.key == 'a') {
|
|
context.params.keyboard.a = false;
|
|
}
|
|
if (event.key == 'd') {
|
|
context.params.keyboard.d = false;
|
|
}
|
|
});
|
|
}
|