]> git.tdb.fi Git - libs/gl.git/blobdiff - source/matrix.cpp
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / matrix.cpp
index 092d2c62ca149cb73764d8c40ab00d7382a8f874..311958ab99542574edfe3cda35059d0eade1b24b 100644 (file)
@@ -14,59 +14,29 @@ Matrix::Matrix():
 { }
 
 Matrix::Matrix(const float *m):
-       Base(LinAl::SquareMatrix<float, 4>(m))
-{ }
-
-Matrix::Matrix(const double *m):
        Base(m)
 { }
 
-Matrix::Matrix(const LinAl::Matrix<double, 4, 4> &other):
+Matrix::Matrix(const LinAl::Matrix<float, 4, 4> &other):
        Base(other)
 { }
 
-void Matrix::multiply(const Matrix &other)
-{
-       *this = *this*other;
-}
-
-void Matrix::translate(const Vector3 &t)
-{
-       multiply(translation(t));
-}
-
-void Matrix::rotate(const Angle &a, const Vector3 &x)
+Matrix &Matrix::translate(const Vector3 &t)
 {
-       multiply(rotation(a, x));
+       return multiply(translation(t));
 }
 
-void Matrix::scale(const Vector3 &s)
+Matrix &Matrix::rotate(const Angle &a, const Vector3 &x)
 {
-       multiply(scaling(s));
+       return multiply(rotation(a, x));
 }
 
-Matrix Matrix::operator*(const Matrix &other) const
+Matrix &Matrix::scale(const Vector3 &s)
 {
-       return static_cast<const Base &>(*this)*static_cast<const Base &>(other);
+       return multiply(scaling(s));
 }
 
-Matrix &Matrix::operator*=(const Matrix &other)
-{
-       multiply(other);
-       return *this;
-}
-
-Vector4 Matrix::operator*(const Vector4 &vec) const
-{
-       return static_cast<const Base &>(*this)*LinAl::Vector<double, 4>(vec);
-}
-
-Vector3 Matrix::operator*(const Vector3 &vec) const
-{
-       return Vector3((*this)*Vector4(vec, 1.0f));
-}
-
-double Matrix::operator[](unsigned i) const
+float Matrix::operator[](unsigned i) const
 {
        if(i>=16)
                throw out_of_range("Matrix::operator[]");
@@ -75,20 +45,20 @@ double Matrix::operator[](unsigned i) const
 
 Matrix Matrix::translation(const Vector3 &t)
 {
-       return Geometry::AffineTransformation<double, 3>::translation(t).get_matrix();
+       return Geometry::AffineTransformation<float, 3>::translation(t).get_matrix();
 }
 
 Matrix Matrix::rotation(const Angle &a, const Vector3 &x)
 {
-       return Geometry::AffineTransformation<double, 3>::rotation(a, x).get_matrix();
+       return Geometry::AffineTransformation<float, 3>::rotation(a, x).get_matrix();
 }
 
 Matrix Matrix::scaling(const Vector3 &s)
 {
-       return Geometry::AffineTransformation<double, 3>::scaling(s).get_matrix();
+       return Geometry::AffineTransformation<float, 3>::scaling(s).get_matrix();
 }
 
-Matrix Matrix::ortho(double l, double r, double b, double t, double n, double f)
+Matrix Matrix::ortho(float l, float r, float b, float t, float n, float f)
 {
        if(l==r || b==t || n==f)
                throw invalid_argument("Matrix::ortho");
@@ -103,22 +73,22 @@ Matrix Matrix::ortho(double l, double r, double b, double t, double n, double f)
        return result;
 }
 
-Matrix Matrix::ortho_centered(double w, double h)
+Matrix Matrix::ortho_centered(float w, float h)
 {
        return ortho(-w/2, w/2, -h/2, h/2, -1, 1);
 }
 
-Matrix Matrix::ortho_bottomleft(double w, double h)
+Matrix Matrix::ortho_bottomleft(float w, float h)
 {
        return ortho(0, w, 0, h, -1, 1);
 }
 
-Matrix Matrix::ortho_topleft(double w, double h)
+Matrix Matrix::ortho_topleft(float w, float h)
 {
        return ortho(0, w, h, 0, -1, 1);
 }
 
-Matrix Matrix::frustum(double l, double r, double b, double t, double n, double f)
+Matrix Matrix::frustum(float l, float r, float b, float t, float n, float f)
 {
        if(l==r || b==t || n<=0 || f<=n)
                throw invalid_argument("Matrix::frustum");
@@ -131,106 +101,20 @@ Matrix Matrix::frustum(double l, double r, double b, double t, double n, double
        result(2, 2) = -(f+n)/(f-n);
        result(3, 2) = -1;
        result(2, 3) = -2*f*n/(f-n);
-       result(3 ,3) = 0;
+       result(33) = 0;
        return result;
 }
 
-Matrix Matrix::frustum_centered(double w, double h, double n, double f)
+Matrix Matrix::frustum_centered(float w, float h, float n, float f)
 {
        return frustum(-w/2, w/2, -h/2, h/2, n, f);
 }
 
-Matrix Matrix::perspective(double h, double a, double n, double f)
+Matrix Matrix::perspective(const Angle &h, float a, float n, float f)
 {
-       double hh = tan(h/2)*n;
+       float hh = tan(h/2.0f)*n;
        return frustum(-hh*a, hh*a, -hh, hh, n, f);
 }
 
-
-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;
-}
-
 } // namespace GL
 } // namespace Msp