diff options
Diffstat (limited to 'js/3D_Landscape.js')
| -rw-r--r-- | js/3D_Landscape.js | 39 |
1 files changed, 21 insertions, 18 deletions
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();
}
|
