52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using OpenTK.Mathematics;
 | 
						|
 | 
						|
namespace Dashboard.Drawing.OpenGL
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    /// The current stack of transformations.
 | 
						|
    /// </summary>
 | 
						|
    public class TransformStack
 | 
						|
    {
 | 
						|
        private Matrix4 _top = Matrix4.Identity;
 | 
						|
        private readonly Stack<Matrix4> _stack = new Stack<Matrix4>();
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// The top-most transform matrix.
 | 
						|
        /// </summary>
 | 
						|
        public ref readonly Matrix4 Top => ref _top;
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// The number of matrices in the stack.
 | 
						|
        /// </summary>
 | 
						|
        public int Count => _stack.Count;
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Push a transform.
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="transform">The transform to push.</param>
 | 
						|
        public void Push(in Matrix4 transform)
 | 
						|
        {
 | 
						|
            _stack.Push(_top);
 | 
						|
            _top = transform * _top;
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Pop a transform.
 | 
						|
        /// </summary>
 | 
						|
        public void Pop()
 | 
						|
        {
 | 
						|
            if (!_stack.TryPop(out _top))
 | 
						|
                _top = Matrix4.Identity;
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Clear the stack of transformations.
 | 
						|
        /// </summary>
 | 
						|
        public void Clear()
 | 
						|
        {
 | 
						|
            _stack.Clear();
 | 
						|
            _top = Matrix4.Identity;
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |