Created
October 11, 2021 07:26
-
-
Save Stiner/62154dd964a1e6dc9f36c84ed24150fd to your computer and use it in GitHub Desktop.
Quad를 Camera의 Frustum 내에 맞추는 스크립트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class FillQuadToScreen : MonoBehaviour | |
{ | |
[SerializeField] private Camera m_camera = null; | |
[SerializeField] private float m_distance = 1f; | |
private Transform m_transform = null; | |
private Transform m_cameraTransform = null; | |
private void Awake() | |
{ | |
m_transform = this.transform; | |
m_cameraTransform = m_camera.transform; | |
} | |
private void Update() | |
{ | |
float pos = (m_camera.nearClipPlane + m_distance); | |
m_transform.position = m_cameraTransform.position + m_cameraTransform.forward * pos; | |
m_transform.LookAt(m_camera.transform); | |
m_transform.Rotate(0, 180, 0); | |
Vector3 dist = m_transform.position - m_camera.transform.position; | |
float h = 2.0f * dist.magnitude * Mathf.Tan(m_camera.fieldOfView * 0.5f * Mathf.Deg2Rad); | |
float w = h * (Screen.width / (float)Screen.height); | |
m_transform.localScale = new Vector3(w, h, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment