X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmatrix.cpp;h=caa728d0c366708403f31a0776cb85012253e774;hb=5172d32d67595ea0b70184fadcfcb8e023cccbc8;hp=d8f018aaf4835814c4736ac389f8e7426dd6279d;hpb=1d59ea8601436164f8bfc114da3941cb0871e87b;p=libs%2Fgl.git diff --git a/source/matrix.cpp b/source/matrix.cpp index d8f018aa..caa728d0 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -134,6 +134,25 @@ Matrix &Matrix::operator*=(const Matrix &other) return *this; } +Vector4 Matrix::operator*(const Vector4 &vec) const +{ + if(flags==IDENTITY) + return vec; + else if(flags==TRANSLATE) + return Vector4(vec.x+vec.w*matrix[12], vec.y+vec.w*matrix[13], vec.z+vec.w*matrix[14], vec.w); + else if(flags==SCALE) + return Vector4(vec.x*matrix[0], vec.y*matrix[5], vec.z*matrix[10], vec.w); + else + { + Vector4 result; + result.x = vec.x*matrix[0]+vec.y*matrix[4]+vec.z*matrix[8]+vec.w*matrix[12]; + result.y = vec.x*matrix[1]+vec.y*matrix[5]+vec.z*matrix[9]+vec.w*matrix[13]; + result.z = vec.x*matrix[2]+vec.y*matrix[6]+vec.z*matrix[10]+vec.w*matrix[14]; + result.w = vec.x*matrix[3]+vec.y*matrix[7]+vec.z*matrix[11]+vec.w*matrix[15]; + return result; + } +} + double Matrix::operator[](unsigned i) const { if(i>=16) @@ -256,7 +275,7 @@ Matrix Matrix::frustum_centered(double w, double h, double n, double f) Matrix Matrix::perspective(double h, double a, double n, double f) { - double hh = tan(h)*n; + double hh = tan(h/2)*n; return frustum(-hh*a, hh*a, -hh, hh, n, f); } @@ -275,7 +294,7 @@ MatrixStack::MatrixStack(): matrices.push_back(Matrix()); } -const Matrix &MatrixStack::top() +const Matrix &MatrixStack::top() const { return matrices.back(); }