X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmatrix.cpp;h=311958ab99542574edfe3cda35059d0eade1b24b;hp=4bf550aa090ffc44c2734992cd064e578ebb460a;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=fa5b232a16e11d7950e80764497f0167ec9e3b41 diff --git a/source/matrix.cpp b/source/matrix.cpp index 4bf550aa..311958ab 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -21,45 +21,19 @@ Matrix::Matrix(const LinAl::Matrix &other): Base(other) { } -void Matrix::multiply(const Matrix &other) +Matrix &Matrix::translate(const Vector3 &t) { - *this = *this*other; + return multiply(translation(t)); } -void Matrix::translate(const Vector3 &t) +Matrix &Matrix::rotate(const Angle &a, const Vector3 &x) { - multiply(translation(t)); + return multiply(rotation(a, x)); } -void Matrix::rotate(const Angle &a, const Vector3 &x) +Matrix &Matrix::scale(const Vector3 &s) { - multiply(rotation(a, x)); -} - -void Matrix::scale(const Vector3 &s) -{ - multiply(scaling(s)); -} - -Matrix Matrix::operator*(const Matrix &other) const -{ - return static_cast(*this)*static_cast(other); -} - -Matrix &Matrix::operator*=(const Matrix &other) -{ - multiply(other); - return *this; -} - -Vector4 Matrix::operator*(const Vector4 &vec) const -{ - return static_cast(*this)*LinAl::Vector(vec); -} - -Vector3 Matrix::operator*(const Vector3 &vec) const -{ - return Vector3((*this)*Vector4(vec, 1.0f)); + return multiply(scaling(s)); } float Matrix::operator[](unsigned i) const @@ -142,91 +116,5 @@ Matrix Matrix::perspective(const Angle &h, float a, float n, float f) 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; - } - - glLoadMatrixf(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