don't store player instance

This commit is contained in:
2023-02-07 12:53:21 +01:00
parent 013708f3b2
commit b2c509e9cb

View File

@@ -31,15 +31,11 @@ namespace EscapeRoomEngine.Portal.Runtime
/// </summary> /// </summary>
[SerializeField] public MeshRenderer screen; [SerializeField] public MeshRenderer screen;
private Player _player;
private Camera _camera; private Camera _camera;
private readonly Dictionary<Camera.StereoscopicEye, RenderTexture> _textures = new(); private readonly Dictionary<Camera.StereoscopicEye, RenderTexture> _textures = new();
private void Awake() private void Awake()
{ {
// get player camera
_player = Player.Instance;
// get portal camera // get portal camera
_camera = GetComponent<Camera>(); _camera = GetComponent<Camera>();
} }
@@ -59,7 +55,7 @@ namespace EscapeRoomEngine.Portal.Runtime
private void Render(ScriptableRenderContext scriptableRenderContext, Camera _) private void Render(ScriptableRenderContext scriptableRenderContext, Camera _)
{ {
// check whether the portal plane is visible from the player camera // check whether the portal plane is visible from the player camera
var frustumPlanes = GeometryUtility.CalculateFrustumPlanes(_player.camera); var frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Player.Instance.camera);
if (!GeometryUtility.TestPlanesAABB(frustumPlanes, portal.linkedPortal.portalCamera.screen.bounds)) if (!GeometryUtility.TestPlanesAABB(frustumPlanes, portal.linkedPortal.portalCamera.screen.bounds))
// don't render this portal if it is not visible // don't render this portal if it is not visible
return; return;
@@ -84,9 +80,9 @@ namespace EscapeRoomEngine.Portal.Runtime
// position portal camera // position portal camera
var m = portal.portalTransform.localToWorldMatrix * Portal.HalfRotation * var m = portal.portalTransform.localToWorldMatrix * Portal.HalfRotation *
portal.linkedPortal.portalTransform.worldToLocalMatrix * portal.linkedPortal.portalTransform.worldToLocalMatrix *
_player.GetEye(eye).localToWorldMatrix; Player.Instance.GetEye(eye).localToWorldMatrix;
transform.SetPositionAndRotation(m.GetPosition(), m.rotation); transform.SetPositionAndRotation(m.GetPosition(), m.rotation);
_camera.projectionMatrix = _player.camera.GetStereoProjectionMatrix(eye); _camera.projectionMatrix = Player.Instance.camera.GetStereoProjectionMatrix(eye);
// set camera clip plane to portal (otherwise the wall behind the portal would be rendered) // set camera clip plane to portal (otherwise the wall behind the portal would be rendered)
// calculating the clip plane: https://computergraphics.stackexchange.com/a/1506 // calculating the clip plane: https://computergraphics.stackexchange.com/a/1506