最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - renderer.setSize calculation by percent of screen? (Three.js) - Stack Overflow

programmeradmin6浏览0评论

Are there any way to set renderer.setSize calculation by percent of screen?

For example i want my frame set 80% of device width and 80% of device height, can we do that?

Are there any way to set renderer.setSize calculation by percent of screen?

For example i want my frame set 80% of device width and 80% of device height, can we do that?

Share Improve this question asked Nov 7, 2013 at 2:42 n2g6t1q1n2g6t1q1 1232 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

If you want to update your canvas width and height during a resize of the window (like in css), you can use this code:

function resize() {
    var factor = 0.8; // percentage of the screen
    var w = window.innerWidth * factor;
    var h = window.innerHeight * factor;
    renderer.setSize(w, h);
    camera.aspect = w / h;
    camera.updateProjectionMatrix();
}; 

window.addEventListener("resize", resize);

First you have to get the device height using : window.innerWidth and window.innerHeight.

Then you apply your desired scaling factor when you set the size of the renderer like so :

   renderer.setSize(window.innerWidth * 0.8, window.innerHeight * 0.8);

Hope this help

发布评论

评论列表(0)

  1. 暂无评论