Browse files

Merge branch 'bug130' of https://github.com/Callaghan/c3dl.git into t…

…estingspeed
  • Loading branch information...
2 parents c62b5f4 + c339532 commit 6217c88e8ffcced7dda0b0df4ba394673b99402e unknown committed Mar 13, 2011
Showing with 53 additions and 38 deletions.
  1. +14 −1 c3dl/c3dapi.js
  2. +39 −37 c3dl/scene.js
View
15 c3dl/c3dapi.js
@@ -171,4 +171,17 @@ c3dl_require('init.js');
//interaction
c3dl_require('interaction/collision.js');
c3dl_require('interaction/picking.js');
-c3dl_require('interaction/pickingresult.js');
+c3dl_require('interaction/pickingresult.js');
+
+//Function to call the various versions of requestAnimationFrame
+//To be updated when this is properly standardized.
+window.requestAnimFrame = (function(callback){
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function(/* function */ callback, /* DOMElement */ element){
+ window.setTimeout(callback, 1000 / 60);
+ };
+ })();
View
76 c3dl/scene.js
@@ -58,7 +58,6 @@ c3dl.Scene = function ()
var updateHandler = null;
// Performance variables
- var timerID = 0;
var lastTimeTaken = Date.now();
var numFramesSinceSceneStart = 0;
@@ -948,41 +947,8 @@ c3dl.Scene = function ()
return isFound;
}
-
- /**
- Start scene sets a default ambient light to white with full
- intensity. If this ambient lighting is not desired, call
- setAmbientLight(..) after this method, which will undo the
- default ambient light values.
- */
- this.startScene = function ()
- {
- if (c3dl.debug.SHARK === true)
- {
- connectShark();
- startShark();
- }
- numFramesSinceSceneStart = 0;
- frameCounter = 0;
-
- // Safety Checks
- if (glCanvas3D == null) return false;
- if (renderer == null) return false;
- if (camera == null) return false;
-
- // Start the timer
- lastTimeTaken = Date.now();
-
- // Benchmark hook:
- if (typeof(benchmarkSetupDone) == "function") benchmarkSetupDone();
-
- // Create a timer for this object
- timerID = setInterval(this.render, 5);
-
- this.setAmbientLight([ambientLight[0], ambientLight[1], ambientLight[2]]);
- }
-
- /**
+
+/**
@private
Render Loop
*/
@@ -1001,7 +967,6 @@ c3dl.Scene = function ()
// If a user wants to stop rendering, this is where it happens
if (exitRender)
{
- timerID = clearInterval(timerID);
if (c3dl.debug.SHARK === true)
{
stopShark();
@@ -1061,6 +1026,43 @@ c3dl.Scene = function ()
FPS_Counter++;
}
+ this.refresh = function() {
+ thisScn.render();
+ requestAnimFrame(thisScn.refresh);
+ }
+
+ /**
+ Start scene sets a default ambient light to white with full
+ intensity. If this ambient lighting is not desired, call
+ setAmbientLight(..) after this method, which will undo the
+ default ambient light values.
+ */
+ this.startScene = function ()
+ {
+ if (c3dl.debug.SHARK === true)
+ {
+ connectShark();
+ startShark();
+ }
+ numFramesSinceSceneStart = 0;
+ frameCounter = 0;
+
+ // Safety Checks
+ if (glCanvas3D == null) return false;
+ if (renderer == null) return false;
+ if (camera == null) return false;
+
+ // Start the timer
+ lastTimeTaken = Date.now();
+
+ // Benchmark hook:
+ if (typeof(benchmarkSetupDone) == "function") benchmarkSetupDone();
+
+ this.refresh();
+
+ this.setAmbientLight([ambientLight[0], ambientLight[1], ambientLight[2]]);
+ }
+
/**
@private
Updates all objects based on time.

0 comments on commit 6217c88

Please sign in to comment.