wmc/index.js

38 lines
1.0 KiB
JavaScript

import { initUiListeners, setupParamPanel, tick } from './game';
import { initWorldGl, makeWorld } from './world';
import * as se3 from './se3';
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],
velocity: [0, 0, 0],
},
keys: new Set(),
lightDirection: [-0.2, -0.5, 0.4],
ambiantLight: 0.7,
blockSelectDistance: 8,
flying: false,
isOnGround: false,
world: makeWorld(),
worldGl: await initWorldGl(gl),
}
setupParamPanel(params);
initUiListeners(params, canvas);
requestAnimationFrame(time => tick(time, gl, params));
}
window.onload = main;