Skip to content

Commit

Permalink
Added browser resize handler
Browse files Browse the repository at this point in the history
  • Loading branch information
picosonic committed Aug 26, 2021
1 parent a0fb020 commit 9d6496c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ function rafcallback(timestamp)
window.requestAnimationFrame(rafcallback);
}

// Action a browser resize
function resize()
{
var aspectratio=1280/720;
var newx, newy;

if ((window.innerWidth/window.innerHeight)<aspectratio)
{
newx=window.innerWidth;
newy=window.innerWidth/aspectratio;
}
else
{
newy=window.innerHeight;
newx=window.innerHeight*aspectratio;
}

gs.static_canvas.style.width=newx+"px";
gs.static_canvas.style.height=newy+"px";

gs.dynamic_canvas.style.width=newx+"px";
gs.dynamic_canvas.style.height=newy+"px";

gs.threedee.canvas.style.width=newx+"px";
gs.threedee.canvas.style.height=newy+"px";
}

// Startup called once when page is loaded
function startup()
{
Expand All @@ -74,6 +101,10 @@ function startup()
console.log(gs);
gs.threedee=new engine3D;
gs.threedee.start();

// Handle resizing and device rotation
resize();
window.addEventListener("resize", resize);
}

// Run the startup() once page has loaded
Expand Down

0 comments on commit 9d6496c

Please sign in to comment.