wmc/index.js

43 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

import { initUiListeners, setupParamPanel, tick } from './game';
import { initWorldGl, makeWorld } from './world';
import * as se3 from './se3';
2021-12-15 20:00:10 +00:00
async function main() {
const canvas = document.querySelector('#game');
2021-12-22 10:50:12 +00:00
// adjust canvas aspect ratio to that of the screen
canvas.height = screen.height / screen.width * canvas.width;
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-12 08:46:24 +00:00
keys: new Set(),
2021-12-12 19:36:47 +00:00
lightDirection: [-0.2, -0.5, 0.4],
2021-12-30 11:47:57 +00:00
skyColor: [0.45, 0.75, 1.0],
2021-12-12 19:36:47 +00:00
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-25 16:22:39 +00:00
gravity: -17,
2021-12-30 11:47:57 +00:00
jumpForce: 6.5,
2021-12-12 19:36:47 +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-12 23:42:25 +00:00
window.onload = main;