1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Three.js】ブラウザサイズに合わせたアスペクト比を間違えて画面が歪む

Posted at

立方体や球を作成した時に、すごい違和感を感じました。なんか長さがおかしく感じるのですよ。下記に画像を載せておきます。

threejs_01_141012.jpg

threejs_02_141012.jpg

アスペクト比を間違えると画面が歪む

原因は画面のサイズとアスペクト比が合っていないことでした。私は現在、ブラウザウィンドウ最大のサイズで描写しています。なのに、下記のようにアスペクト比を定義していました。

var aspect = 600 / 600;

実際のウィンドウは600 * 600を使用しているわけではありません。最大サイズの場合は、下記がお勧めです。

var aspect = window.innerWidth / window.innerHeight;

これならウィンドウのサイズを変更されても対応できます。それではもう一度レンダリングしてみましょう。

threejs_03_141012.jpg

threejs_04_141012.jpg

明らかに前と見栄えが違いますよね?あー、スッキリした♪

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?