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 3 years have passed since last update.

被写体の大きさに関わらず被写体全体が写るためのカメラの設定

1
Last updated at Posted at 2019-12-03

camera.png

このように被写体の大きさがバラバラでも、被写体の全体を写すための方法を紹介します。

概要

図.png
tanθ = y÷x
θ = artan(tanθ)
求まったθをカメラの画角として設定します。
このようにカメラと被写体の距離被写体の高さからカメラの画角を求めます。

コード

Camera camera;   //カメラ
float y;   //被写体の高さ
Vector3 camraPos;   //カメラの座標
Vector3 objectPos;   //被写体の座標   

//上の図でいうところのxを求めます
float x = cameraPos.x - objectPos.x;
//y/xでタンジェントを求めます
float tanθ = y / x;
//求まったタンジェントをアークタンジェントにかけてθを求めます
float θ = atanf(tanθ);
//θをカメラの画角に設定します
camra.SetViewAngle(θ)
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?