refactor: monogame camera transform caching
This commit is contained in:
		@@ -5,7 +5,7 @@ using Engine.Core;
 | 
			
		||||
 | 
			
		||||
namespace Engine.Integration.MonoGame;
 | 
			
		||||
 | 
			
		||||
public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, IPreDraw
 | 
			
		||||
public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFrameUpdate, IPreDraw
 | 
			
		||||
{
 | 
			
		||||
    public Event<MonoGameCamera3D, ViewChangedArguments> OnViewChanged { get; } = new();
 | 
			
		||||
    public Event<MonoGameCamera3D, ProjectionChangedArguments> OnProjectionChanged { get; } = new();
 | 
			
		||||
@@ -83,7 +83,7 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, IPreDra
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Engine.Core.Quaternion Rotation
 | 
			
		||||
    public Core.Quaternion Rotation
 | 
			
		||||
    {
 | 
			
		||||
        get => Transform.Rotation;
 | 
			
		||||
        set => Transform.Rotation = value;
 | 
			
		||||
@@ -104,10 +104,12 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, IPreDra
 | 
			
		||||
 | 
			
		||||
    public Vector2D WorldToScreenPosition(Vector3D worldPosition) => Viewport.Project(worldPosition.ToVector3(), _projection, _view, Matrix.Identity).ToVector3D();
 | 
			
		||||
 | 
			
		||||
    public void LastActiveFrame() => Transform = null!;
 | 
			
		||||
    public void FirstActiveFrame()
 | 
			
		||||
    {
 | 
			
		||||
        Graphics = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour<MonoGameWindowContainer>().Window.Graphics;
 | 
			
		||||
        Viewport = Graphics.GraphicsDevice.Viewport;
 | 
			
		||||
        Transform = BehaviourController.GetRequiredBehaviour<ITransform3D>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PreDraw()
 | 
			
		||||
@@ -121,9 +123,6 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, IPreDra
 | 
			
		||||
        Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Viewport.AspectRatio, 0.1f, 100f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected sealed override void InitializeInternal() => Transform = BehaviourController.GetRequiredBehaviour<ITransform3D>();
 | 
			
		||||
    protected sealed override void FinalizeInternal() => Transform = null!;
 | 
			
		||||
 | 
			
		||||
    public readonly record struct ViewChangedArguments(Matrix PreviousView);
 | 
			
		||||
    public readonly record struct ProjectionChangedArguments(Matrix PreviousProjection);
 | 
			
		||||
    public readonly record struct ViewportChangedArguments(Viewport PreviousViewport);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user