2021-12-18 17:57:00 +00:00
|
|
|
import { initUiListeners, setupParamPanel, tick } from './game';
|
|
|
|
import { initWorldGl, makeWorld } from './world';
|
2021-12-08 17:24:19 +00:00
|
|
|
import * as se3 from './se3';
|
2021-12-15 20:00:10 +00:00
|
|
|
|
2021-12-08 17:24:19 +00:00
|
|
|
async function main() {
|
|
|
|
const canvas = document.querySelector('#game');
|
|
|
|
const gl = canvas.getContext('webgl');
|
|
|
|
|
|
|
|
if (gl === null) {
|
|
|
|
console.error('webgl not available')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
projMatrix: se3.perspective(Math.PI / 3, canvas.clientWidth / canvas.clientHeight, 0.1, 100.0),
|
|
|
|
camera: {
|
|
|
|
position: [0.0, 70.5, 0.0],
|
|
|
|
orientation: [0.0, Math.PI, 0.0],
|
2021-12-12 23:42:25 +00:00
|
|
|
velocity: [0, 0, 0],
|
2021-12-08 17:24:19 +00:00
|
|
|
},
|
2021-12-12 08:46:24 +00:00
|
|
|
keys: new Set(),
|
2021-12-12 19:36:47 +00:00
|
|
|
lightDirection: [-0.2, -0.5, 0.4],
|
|
|
|
ambiantLight: 0.7,
|
2021-12-17 23:26:29 +00:00
|
|
|
blockSelectDistance: 8,
|
2021-12-12 23:42:25 +00:00
|
|
|
flying: false,
|
|
|
|
isOnGround: false,
|
2021-12-15 22:36:31 +00:00
|
|
|
world: makeWorld(),
|
2021-12-17 14:15:07 +00:00
|
|
|
worldGl: await initWorldGl(gl),
|
2021-12-12 19:36:47 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 17:57:00 +00:00
|
|
|
setupParamPanel(params);
|
|
|
|
initUiListeners(params, canvas);
|
2021-12-17 14:14:16 +00:00
|
|
|
|
2021-12-12 08:46:24 +00:00
|
|
|
requestAnimationFrame(time => tick(time, gl, params));
|
2021-12-08 17:24:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-12 23:42:25 +00:00
|
|
|
window.onload = main;
|