From 57ad852b6e7e337b7a86d2f85ac95b480898b057 Mon Sep 17 00:00:00 2001 From: yo mama Date: Thu, 12 Feb 2015 19:33:18 -0800 Subject: working --- js/3D_Landscape.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'js/3D_Landscape.js') diff --git a/js/3D_Landscape.js b/js/3D_Landscape.js index 6871786..ca71ea6 100644 --- a/js/3D_Landscape.js +++ b/js/3D_Landscape.js @@ -1,10 +1,10 @@ var container, stats; var camera, controls, scene, renderer; var mesh, texture, material; +//FIXME experiment with these fixed params var worldWidth = 256, worldDepth = 256, worldHalfWidth = worldWidth / 2, worldHalfDepth = worldDepth / 2; -var textureURL, heightmapURL; -var textureFile = 'img/test2.gif'; //texture doesn't need resizing -var heightmapFile = 'img/testnew.png'; +var textureFile = 'img/Texture.jpg'; +var heightmapFile = 'img/Heightmap.jpg'; var pos_x, pos_y, pos_z, rot_x, rot_y, rot_z; var wf = false; @@ -17,17 +17,15 @@ function runWebGLSimulation(){ } //Start Graphics - initGraphics(function(){ animate() }); + initGraphics(textureFile, heightmapFile, function(){ animate() }); //Start Scene Animation } -function initGraphics(cb) { +function initGraphics(textureFile, heightmapFile, cb) { container = document.getElementById('container'); - //Set camera camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 20000); - //Set scene scene = new THREE.Scene(); @@ -45,7 +43,6 @@ function initGraphics(cb) { var img = new Image(); img.src = heightmapFile; -//FIXME img.onload = function(){ context.drawImage(img, 0, 0); image = context.getImageData(0, 0, worldWidth, worldDepth); @@ -95,12 +92,6 @@ function initGraphics(cb) { container.innerHTML = ""; container.appendChild(renderer.domElement); - // //Add FPS statistics - // stats = new Stats(); - // stats.domElement.style.position = 'absolute'; - // stats.domElement.style.top = '0px'; - // container.appendChild(stats.domElement); - //Get default values pos_x = mesh.position.x; pos_y = mesh.position.y; @@ -182,16 +173,28 @@ function initGraphics(cb) { }; } - +var requestId; +function loop() { + render(); + requestId = window.requestAnimationFrame(loop); +} function animate() { - render(); - requestAnimationFrame(animate); + if (!requestId) { + loop(); + } +} +function stop_animating() { + if (requestId) { + window.cancelAnimationFrame(requestId); + requestId = undefined; + } } + function render() { renderer.render(scene, camera); } window.onload= function(e){ - initGraphics(function(){ animate() }); + runWebGLSimulation(); } -- cgit v1.2.3-70-g09d2