dav74 Posted November 10, 2013 Share Posted November 10, 2013 Hi,I would like to know if this code is correct for the time management in BabylonJS (time-fps independence)var time=0;var t1;var vitesseRotation=10;var canvas = document.getElementById("renderCanvas");var engine = new BABYLON.Engine(canvas, true);var scene = new BABYLON.Scene(engine);var camera = new BABYLON.ArcRotateCamera("Camera",0, Math.PI/4, 15, new BABYLON.Vector3(0, 0, 0), scene);var light = new BABYLON.PointLight("Omnidir", new BABYLON.Vector3(10, 0, 10), scene);var maBox= new BABYLON.Mesh.CreateBox("box_1",5,scene);scene.registerBeforeRender(function(){ t1=new Date().getTime()/1000 maBox.rotation.y=vitesseRotation*time;});engine.runRenderLoop(function () { scene.render(); time=time+((new Date().getTime()/1000)-t1);});thank you for your help PS : I've problem with "getLastFrameDuration();" : lag in my scene Quote Link to comment Share on other sites More sharing options...
dav74 Posted November 10, 2013 Author Share Posted November 10, 2013 other solution :var time=0;var vitesseRotation=3;var canvas = document.getElementById("renderCanvas");var engine = new BABYLON.Engine(canvas, true);var scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera",0, Math.PI/4, 15, new BABYLON.Vector3(0, 0, 0), scene);var light = new BABYLON.PointLight("Omnidir", new BABYLON.Vector3(15, 0, 10), scene);var maBox= new BABYLON.Mesh.CreateBox("box_1",2,scene);scene.registerBeforeRender(function(){ time=time+(1/BABYLON.Tools.GetFps()); maBox.rotation.y=vitesseRotation*time;});engine.runRenderLoop(function () { scene.render();});the good way ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 10, 2013 Share Posted November 10, 2013 Both are good:) But you can also use maBox.rotation.y += vitesseRotation * scene.getAnimationRatio() Quote Link to comment Share on other sites More sharing options...
dav74 Posted November 10, 2013 Author Share Posted November 10, 2013 ok thank you, i think i'll use "time=time+(1/BABYLON.Tools.GetFps());" : it's easier for my students (and i want that they use the "time variable", i think it's more educational) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 11, 2013 Share Posted November 11, 2013 This is perfectly valid:) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.