유니티의 Frustum Testing 에 대해 알아본다.


Frustum Testing 은 원하는 시점에 특정 게임 오브젝트가 화면에 보이는지를 알아보는 방법이다.



1. 먼저 아래처럼 카메라 객체로부터 절두체를 구성하는 각 평면들을 얻는다.

Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);



2. 다음은 게임 오브젝트의 영역 정보인 Bounds 를 얻는다. 보통은 렌더러에서 얻는데, 특수한 경우로 컬라이더에서 얻기도 한다.

Bounds bounds = targetGameObject.renderer.bounds;    // 렌더러에서 얻음

Bounds bounds = targetGameObject.collider.bounds;    // 컬라이더에서 얻음



3. 이제 아래의 코드를 통해 화면에 보이는지를 체크할 수 있다.

bool isVisible = GeometryUtility.TestPlanesAABB(planes, bounds);

Posted by 카코데몬
,