func Rebase(ms *TransformStack, from int, m *TransformStack) (*TransformStack, error) {
	if from <= 0 || from >= len(*ms) {
		return nil, errors.New("Cannot rebase, index out of range")
	}
	tmp := ms.Copy()
	if from == 1 {
		(*tmp) = append(*tmp, mgl32.Mat4{})
	}
	copy((*tmp)[1:], (*tmp)[from-1:])
	if from-2 > 0 {
		(*tmp) = (*tmp)[:len(*tmp)-(from-2)]
	}
	err := tmp.Reseed(1, m.Peek())
	if err != nil {
		return nil, err
	}
	(*tmp) = append(*m, (*tmp)[2:]...)
	return tmp, nil
}
Rebase replays the current matrix stack as if the transformation that occurred at index "from"
in ms had instead started at the top of m.

This returns a brand new stack containing all of m followed by all transformations
at from and after on ms as if they has been done on m instead.
package matstack
import (
	"errors"
	"fmt"
	"github.com/go-gl/mathgl/mgl32"
)
type TransformStack []mgl32.Mat4
func NewTransformStack() *TransformStack {
	ms := make(TransformStack, 1)
	ms[0] = mgl32.Ident4()
	return &ms
}
func (ms *TransformStack) Push(m mgl32.Mat4) {
	prev := (*ms)[len(*ms)-1]
	(*ms) = append(*ms, prev.Mul4(m))
}
func (ms *TransformStack) Pop() (mgl32.Mat4, error) {
	if len(*ms) == 1 {
		return mgl32.Mat4{}, errors.New("attempt to pop last element of the stack; Matrix Stack must have at least one element")
	}
	retVal := (*ms)[len(*ms)-1]
	(*ms) = (*ms)[:len(*ms)-1]
	return retVal, nil
}
func (ms *TransformStack) Peek() mgl32.Mat4 {
	return (*ms)[len(*ms)-1]
}
func (ms *TransformStack) Len() int {
	return len(*ms)
}
func (ms *TransformStack) Unwind(n int) error {
	if n > len(*ms)-1 {
		return errors.New("Cannot unwind a matrix to below 1 value")
	}
	(*ms) = (*ms)[:len(*ms)-n]
	return nil
}
func (ms *TransformStack) Copy() *TransformStack {
	v := append(TransformStack{}, (*ms)...)
	return &v
}
func (ms *TransformStack) Reseed(n int, change mgl32.Mat4) error {
	if n >= len(*ms) || n <= 0 {
		return errors.New("Cannot rebase at the given point on the stack, it is out of bounds.")
	}
	return ms.reseed(n, change)
}
func (ms *TransformStack) reseed(n int, change mgl32.Mat4) error {
	backup := []mgl32.Mat4((*ms)[n:])
	backup = append([]mgl32.Mat4{}, backup...)  
	curr := (*ms)[n]
	(*ms)[n] = (*ms)[n-1].Mul4(change)
	for i := n + 1; i < len(*ms); i++ {
		inv := curr.Inv()
		blank := mgl32.Mat4{}
		if inv == blank {
			ms.undoRebase(n, backup)
			return NoInverseError{Loc: i - 1, Mat: curr}
		}
		ghost := inv.Mul4((*ms)[i])
		curr = (*ms)[i]
		(*ms)[i] = (*ms)[i-1].Mul4(ghost)
	}
	return nil
}
func (ms *TransformStack) undoRebase(n int, prev []mgl32.Mat4) {
	for i := n; i < len(*ms); i++ {
		(*ms)[i] = prev[i-n]
	}
}