3d-interface/js/l3d/apps/prototype/replay/main.js

102 lines
2.0 KiB
JavaScript
Raw Normal View History

var onWindowResize = (function() {
2015-05-19 15:43:09 +02:00
// Disable scrolling
window.onscroll = function () { window.scrollTo(0, 0); };
window.onload = main;
var renderer, scene, container;
var recommendations;
2015-05-19 15:43:09 +02:00
var stats;
var camera1;
var coins = [];
2015-05-19 15:43:09 +02:00
var previousTime;
function main() {
2015-05-19 15:43:09 +02:00
container = document.getElementById('container');
initThreeElements();
init();
2015-05-19 15:43:09 +02:00
onWindowResize();
setInterval(render, 20);
}
function initThreeElements() {
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer({alpha:true, antialias: true});
2015-05-19 15:43:09 +02:00
renderer.setClearColor(0x87ceeb);
}
function init() {
2015-05-19 15:43:09 +02:00
// Initialize stats counter
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = 'absolute';
stats.domElement.style.cssFloat = "top-left";
// Add elements to page
2015-07-07 10:42:37 +02:00
container.appendChild(Coin.domElement);
2015-05-19 15:43:09 +02:00
container.appendChild( stats.domElement );
container.appendChild(renderer.domElement);
// Initialize replay camera
camera1 = new L3D.ReplayCamera(50, container_size.width() / container_size.height(), 0.01, 100000, coins);
recommendations = initMainScene(camera1, scene, coins);
camera1.cameras = recommendations;
2015-05-19 15:43:09 +02:00
// Add listeners
initListeners();
2015-06-30 14:21:51 +02:00
2015-05-19 15:43:09 +02:00
}
function initListeners() {
window.addEventListener('resize', onWindowResize, false);
}
function render() {
stats.begin();
2015-05-19 15:43:09 +02:00
// Update coins
coins.forEach(function(coin) { coin.update(); });
// Update main camera
var currentTime = Date.now() - previousTime;
camera1.update(isNaN(currentTime) ? 20 : currentTime);
2015-05-19 15:43:09 +02:00
previousTime = Date.now();
// Update the recommendations
recommendations.map(function(camera) {camera.update(camera1);});
2015-05-19 15:43:09 +02:00
// Set current position of camera
camera1.look();
2015-05-19 15:43:09 +02:00
renderer.render(scene, camera1);
2015-05-19 15:43:09 +02:00
stats.end();
2015-05-19 15:43:09 +02:00
}
function onWindowResize() {
resizeElements(renderer, container, Coin);
2015-05-19 15:43:09 +02:00
recommendations.forEach(function(reco) {resetCameraAspect(reco.camera);});
2015-05-19 15:43:09 +02:00
render();
2015-05-19 15:43:09 +02:00
}
return onWindowResize;
})();