Jump to content

time in BabylonJS


dav74
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...