-Matrix Matrix::operator*(const Matrix &other) const
-{
- if(flags==IDENTITY)
- return other;
- else if(other.flags==IDENTITY)
- return *this;
- else if(flags==TRANSLATE && !(other.flags&ARBITARY))
- {
- Matrix result = other;
- result.matrix[12] += matrix[12];
- result.matrix[13] += matrix[13];
- result.matrix[14] += matrix[14];
- result.flags |= flags;
- return result;
- }
- else if(!(flags&ARBITARY) && other.flags==TRANSLATE)
- {
- Matrix result = *this;
- const double *m = other.matrix;
- result.matrix[12] += matrix[0]*m[12]+matrix[4]*m[13]+matrix[8]*m[14];
- result.matrix[13] += matrix[1]*m[12]+matrix[5]*m[13]+matrix[9]*m[14];
- result.matrix[14] += matrix[2]*m[12]+matrix[6]*m[13]+matrix[10]*m[14];
- result.flags |= other.flags;
- return result;
- }
- else
- {
- Matrix result;
- fill(result.matrix, result.matrix+16, 0.0);
- for(unsigned i=0; i<4; ++i)
- for(unsigned j=0; j<4; ++j)
- for(unsigned k=0; k<4; ++k)
- result.matrix[i+j*4] += matrix[i+k*4]*other.matrix[k+j*4];
- result.flags = flags|other.flags;
- return result;
- }
-}
-
-Matrix &Matrix::operator*=(const Matrix &other)
-{
- multiply(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