-
-GLenum MatrixStack::current_mode = GL_MODELVIEW;
-
-MatrixStack::MatrixStack(GLenum m):
- mode(m)
-{
- matrices.push_back(Matrix());
-}
-
-MatrixStack::MatrixStack():
- mode(0)
-{
- 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 InvalidState("Can't pop the last matrix");
-
- 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;
-}
-
-
-// Deprecated stuff
-
-MatrixStack *active_stack = &MatrixStack::modelview();
-
-void matrix_mode(MatrixMode m)
-{
- if(m==MODELVIEW)
- active_stack = &MatrixStack::modelview();
- else if(m==PROJECTION)
- active_stack = &MatrixStack::projection();
- else
- throw InvalidParameterValue("Texture matrices are not supported");
-}
-
-void load_identity()
-{
- *active_stack = Matrix();
-}
-
-void load_matrix(const float *matrix)
-{
- *active_stack = Matrix(matrix);
-}
-
-void load_matrix(const double *matrix)
-{
- *active_stack = Matrix(matrix);
-}
-
-void mult_matrix(const float *matrix)
-{
- *active_stack *= Matrix(matrix);
-}
-
-void mult_matrix(const double *matrix)
-{
- *active_stack *= Matrix(matrix);
-}
-
-void push_matrix()
-{
- active_stack->push();
-}
-
-void pop_matrix()
-{
- active_stack->pop();
-}
-
-void translate(float x, float y, float z)
-{
- *active_stack *= Matrix::translation(x, y, z);
-}
-
-void rotate(float a, float x, float y, float z)
-{
- *active_stack *= Matrix::rotation_deg(a, x, y, z);
-}
-
-void scale(float x, float y, float z)
-{
- *active_stack *= Matrix::scaling(x, y, z);
-}
-
-void scale_uniform(float s)
-{
- *active_stack *= Matrix::scaling(s);
-}
-