-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.js
38 lines (27 loc) · 1.16 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
window.addEventListener('load', () => {
const sceneElm = document.getElementById("scene");
const cameraElm = document.getElementById("camera");
const worldElm = document.getElementById("world");
const player = new Player();
const world = new World(worldElm);
const editor = new Editor(world, player);
let lastTime = null;
function draw(timestamp) {
// Tell the player to update itself based on the amount of time passed
player.update(lastTime ? timestamp - lastTime : 0);
lastTime = timestamp;
const [ x, y, z ] = player.position;
const [ a, b, c ] = player.orientation;
// Rotate sky texture
sceneElm.style.backgroundPosition = `${b / 360 * 100}%`;
// Rotate camera This value needs to correspond to CSS `perspective` property to undo
// the player's translation: vvvvv
cameraElm.style.transform = `translate3d(0px, 0px, 600px) rotateX(${a}deg) rotateY(${b}deg) rotateZ(${c}deg)`;
// Translate world to right position
worldElm.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
window.requestAnimationFrame(draw);
}
// Bootstrap!
world.render();
draw();
});