Exemplo n.º 1
0
        public void RecalculateMatrix(float scale)
        {
            if (_stack == null)
            {
                CurrentMatrix = Matrix4x4.Identity;
                MatrixDirty   = false;
                return;
            }

            Matrix4x4 mat = Matrix4x4.Identity;

            for (var i = 0; i < _stack.Count; i++)
            {
                MatrixWithId matWithId = _stack[i];
                if (matWithId.ResetToIdentity)
                {
                    mat = Matrix4x4.Identity;
                }
                mat *= matWithId.Matrix;
            }

            // Scale the matrix according to the UI scale.
            var scaleMatrix = Matrix4x4.CreateScale(scale, scale, 1f);

            CurrentMatrix = scaleMatrix.Inverted() * mat * scaleMatrix;
            MatrixDirty   = false;
        }
Exemplo n.º 2
0
        private MatrixWithId?Get(string id)
        {
            if (_stack == null)
            {
                return(null);
            }

            for (var i = 0; i < _stack.Count; i++)
            {
                MatrixWithId matWithId = _stack[i];
                if (matWithId.Id == id)
                {
                    return(matWithId);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public void AddOrUpdate(string id, Matrix4x4 matrix, bool multiply = true)
        {
            _stack ??= new List <MatrixWithId>();

            MatrixWithId?matWithId = Get(id);

            if (matWithId != null)
            {
                matWithId.Matrix          = matrix;
                matWithId.ResetToIdentity = !multiply;
            }
            else
            {
                matWithId = new MatrixWithId(matrix, id, multiply);
                _stack.Add(matWithId);
            }

            MatrixDirty = true;
        }