diff options
author | alon@honor <none@none> | 2010-09-28 20:43:37 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-28 20:43:37 -0700 |
commit | 13110f1a19e4cea2136461e15dd5d73730247faf (patch) | |
tree | 14bac3db675a6e605c1552190238e7d9d150dc34 /demos | |
parent | d451428fb3312717c9e6cdf7c58c2e119d160bfb (diff) |
raytrace demo improvements
Diffstat (limited to 'demos')
-rw-r--r-- | demos/raytrace.html | 54 | ||||
-rw-r--r-- | demos/raytrace.js | 11 |
2 files changed, 37 insertions, 28 deletions
diff --git a/demos/raytrace.html b/demos/raytrace.html index 0996e268..7e98901b 100644 --- a/demos/raytrace.html +++ b/demos/raytrace.html @@ -8,31 +8,51 @@ // print function which the cubescript engine will call function print(text) { document.getElementById('output').innerHTML = text; - printed = true; } + var drawing = false; + var hasSceneData = false; // Do everything - initialize SDL, set up canvas, render - function render() { - _SDL_Init(32); - var canvas = document.getElementById('canvas'); - HEAP[_screen] = _SDL_SetVideoMode(canvas.width, canvas.height, 32, 0, canvas); - var y = canvas.height-1; - function drawLine() { - __ZL10trace_lineiii(canvas.width, canvas.width, y); - print("Generating: " + (canvas.height-y) + "/" + canvas.height); - y--; - if (y >= 0) { - setTimeout(arguments.callee, 1); - } + function render(size) { + if (drawing) return; + drawing = true; + if (!hasSceneData) { + print('Generating scene data, please wait...'); } - drawLine(); + setTimeout(function() { + if (!hasSceneData) { + run(['5']); + _SDL_Init(32); + hasSceneData = true; + } + var canvas = document.getElementById('canvas'); + canvas.width = canvas.height = size; + HEAP[_screen] = _SDL_SetVideoMode(canvas.width, canvas.height, 32, 0, canvas); + var y = canvas.height-1; + function drawLine() { + print("Raytracing line: <b>" + (canvas.height-y) + "/" + canvas.height + '</b>'); + __ZL10trace_lineiii(canvas.width, canvas.width, y); + y--; + if (y >= 0) { + setTimeout(arguments.callee, 1); + } else { + print(''); + drawing = false; + } + } + drawLine(); + }); } </script> </head> -<body onload='render()'> - <canvas id='canvas' width=128 height=128></canvas> +<body> + <canvas id='canvas' width=1 height=1></canvas> <hr> - <div id="output" style="font-family: Courier New,Courier,monospace;">Generating scene data, please wait...</div> + <form onsubmit="setTimeout(function() { render(parseInt(size.value)) }); return false"> + Size (pixels): <input type="text" name="size" value="128"> + <input type="submit" value="Go!"> + </form> + <div id="output" style="font-family: Courier New,Courier,monospace;"></div> <hr> Simple raytracing demo. The <a href="http://ompf.org/ray/sphereflake/">original C++ source</a> was automatically converted to JavaScript using <a href="http://emscripten.org">Emscripten</a>. diff --git a/demos/raytrace.js b/demos/raytrace.js index 1d36c6dd..0308d08f 100644 --- a/demos/raytrace.js +++ b/demos/raytrace.js @@ -1,5 +1,3 @@ -arguments = ['5'] // 6! - //==================================================================================== // Auto-generated code. Original source + changes are // sphere flake bvh raytracer (c) 2005, thierry berger-perrin <tbptbp@gmail.com> @@ -2089,12 +2087,3 @@ function run(args) { } } -try { - run(this.arguments ? arguments : []); -} catch (e) { - print("Fatal exception: " + e.stack); - throw e; -} - - - |