-
-GLenum MatrixStack::current_mode = GL_MODELVIEW;
-
-MatrixStack::MatrixStack(GLenum m):
- mode(m)
-{
- matrices.reserve(mode==GL_MODELVIEW ? 32 : 4);
- matrices.push_back(Matrix());
-}
-
-MatrixStack::MatrixStack():
- mode(0)
-{
- matrices.reserve(32);
- matrices.push_back(Matrix());
-}
-
-const Matrix &MatrixStack::top() const
-{
- return matrices.back();
-}
-
-void MatrixStack::load(const Matrix &m)
-{
- matrices.back() = m;
- update();
-}
-
-void MatrixStack::multiply(const Matrix &m)
-{
- matrices.back() *= m;
- update();
-}
-
-void MatrixStack::push()
-{
- matrices.push_back(top());
-}
-
-void MatrixStack::pop()
-{
- if(matrices.size()==1)
- throw stack_underflow("MatrixStack::pop()");
-
- matrices.pop_back();
- update();
-}
-
-void MatrixStack::update()
-{
- if(!mode)
- return;
-
- if(mode!=current_mode)
- {
- glMatrixMode(mode);
- current_mode = mode;
- }
-
- glLoadMatrixd(matrices.back().data());
-}
-
-MatrixStack &MatrixStack::operator=(const Matrix &m)
-{
- load(m);
- return *this;
-}
-
-MatrixStack &MatrixStack::operator*=(const Matrix &m)
-{
- multiply(m);
- return *this;
-}
-
-MatrixStack &MatrixStack::modelview()
-{
- static MatrixStack ms(GL_MODELVIEW);
- return ms;
-}
-
-MatrixStack &MatrixStack::projection()
-{
- static MatrixStack ms(GL_PROJECTION);
- return ms;
-}
-