Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix stack #25

Closed
UserAB1236872 opened this issue Jul 14, 2014 · 1 comment
Closed

Matrix stack #25

UserAB1236872 opened this issue Jul 14, 2014 · 1 comment

Comments

@UserAB1236872
Copy link
Member

Both OpenGL's old matrix model and GLM provide matrix stacks. I think this is worthing putting in a new package. A Matrix stack is, in essence, a fully-persistent data structure that keeps track of matrix mutations and allows you to roll back and arbitrary number of operations. This is extremely useful for, e.g., scenegraphs.. A sketch of push, for instance:

type MatrixStack []Mat4

func (ms *MatrixStack) Push(m Mat4) error {
    if len(*ms) == 0 {
        return errors.New("Matrix stack is empty, create a new stack or use MatrixStack.Load to add the first matrix")
    }

    prev := (*ms)[len(*ms)-1]
    (*ms) = append(*ms, prev.Mul4(m))

   return nil
}

The biggest question is whether the stack should be Mat4 only (I believe OpenGL took this approach?) or whether there should be support for Mat3 and Mat2 as well. I suspect the basic (push/pop/peek/load) implementation will be fewer than 200 lines per matrix type, so it may be worth just doing all 3.

@UserAB1236872
Copy link
Member Author

I'll note that I somehow got off my gourd and totally misremembered how the matrix stack works. The previous implementation has been named the TransformStack, and the new MatrixStack should work like GL's which is an explicit state COPYING stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant