📄 imathmatrix.h
字号:
//---------------------- // Scale the matrix by s //---------------------- template <class S> const Matrix44 & scale (const Vec3<S> &s); //------------------------------------------ // Set matrix to translation by given vector //------------------------------------------ template <class S> const Matrix44 & setTranslation (const Vec3<S> &t); //----------------------------- // Return translation component //----------------------------- const Vec3<T> translation () const; //-------------------------- // Translate the matrix by t //-------------------------- template <class S> const Matrix44 & translate (const Vec3<S> &t); //------------------------------------------------------------- // Set matrix to shear by given vector h. The resulting matrix // will shear x for each y coord. by a factor of h[0] ; // will shear x for each z coord. by a factor of h[1] ; // will shear y for each z coord. by a factor of h[2] . //------------------------------------------------------------- template <class S> const Matrix44 & setShear (const Vec3<S> &h); //------------------------------------------------------------ // Set matrix to shear by given factors. The resulting matrix // will shear x for each y coord. by a factor of h.xy ; // will shear x for each z coord. by a factor of h.xz ; // will shear y for each z coord. by a factor of h.yz ; // will shear y for each x coord. by a factor of h.yx ; // will shear z for each x coord. by a factor of h.zx ; // will shear z for each y coord. by a factor of h.zy . //------------------------------------------------------------ template <class S> const Matrix44 & setShear (const Shear6<S> &h); //-------------------------------------------------------- // Shear the matrix by given vector. The composed matrix // will be <shear> * <this>, where the shear matrix ... // will shear x for each y coord. by a factor of h[0] ; // will shear x for each z coord. by a factor of h[1] ; // will shear y for each z coord. by a factor of h[2] . //-------------------------------------------------------- template <class S> const Matrix44 & shear (const Vec3<S> &h); //------------------------------------------------------------ // Shear the matrix by the given factors. The composed matrix // will be <shear> * <this>, where the shear matrix ... // will shear x for each y coord. by a factor of h.xy ; // will shear x for each z coord. by a factor of h.xz ; // will shear y for each z coord. by a factor of h.yz ; // will shear y for each x coord. by a factor of h.yx ; // will shear z for each x coord. by a factor of h.zx ; // will shear z for each y coord. by a factor of h.zy . //------------------------------------------------------------ template <class S> const Matrix44 & shear (const Shear6<S> &h); //------------------------------------------------- // Limitations of type T (see also class limits<T>) //------------------------------------------------- static T baseTypeMin() {return limits<T>::min();} static T baseTypeMax() {return limits<T>::max();} static T baseTypeSmallest() {return limits<T>::smallest();} static T baseTypeEpsilon() {return limits<T>::epsilon();}};//--------------// Stream output//--------------template <class T>std::ostream & operator << (std::ostream & s, const Matrix33<T> &m); template <class T>std::ostream & operator << (std::ostream & s, const Matrix44<T> &m); //---------------------------------------------// Vector-times-matrix multiplication operators//---------------------------------------------template <class S, class T>const Vec2<S> & operator *= (Vec2<S> &v, const Matrix33<T> &m);template <class S, class T>Vec2<S> operator * (const Vec2<S> &v, const Matrix33<T> &m);template <class S, class T>const Vec3<S> & operator *= (Vec3<S> &v, const Matrix33<T> &m);template <class S, class T>Vec3<S> operator * (const Vec3<S> &v, const Matrix33<T> &m);template <class S, class T>const Vec3<S> & operator *= (Vec3<S> &v, const Matrix44<T> &m);template <class S, class T>Vec3<S> operator * (const Vec3<S> &v, const Matrix44<T> &m);//-------------------------// Typedefs for convenience//-------------------------typedef Matrix33 <float> M33f;typedef Matrix33 <double> M33d;typedef Matrix44 <float> M44f;typedef Matrix44 <double> M44d;//---------------------------// Implementation of Matrix33//---------------------------template <class T>inline T *Matrix33<T>::operator [] (int i){ return x[i];}template <class T>inline const T *Matrix33<T>::operator [] (int i) const{ return x[i];}template <class T>inlineMatrix33<T>::Matrix33 (){ x[0][0] = 1; x[0][1] = 0; x[0][2] = 0; x[1][0] = 0; x[1][1] = 1; x[1][2] = 0; x[2][0] = 0; x[2][1] = 0; x[2][2] = 1;}template <class T>inlineMatrix33<T>::Matrix33 (T a){ x[0][0] = a; x[0][1] = a; x[0][2] = a; x[1][0] = a; x[1][1] = a; x[1][2] = a; x[2][0] = a; x[2][1] = a; x[2][2] = a;}template <class T>inlineMatrix33<T>::Matrix33 (const T a[3][3]) { x[0][0] = a[0][0]; x[0][1] = a[0][1]; x[0][2] = a[0][2]; x[1][0] = a[1][0]; x[1][1] = a[1][1]; x[1][2] = a[1][2]; x[2][0] = a[2][0]; x[2][1] = a[2][1]; x[2][2] = a[2][2];}template <class T>inlineMatrix33<T>::Matrix33 (T a, T b, T c, T d, T e, T f, T g, T h, T i){ x[0][0] = a; x[0][1] = b; x[0][2] = c; x[1][0] = d; x[1][1] = e; x[1][2] = f; x[2][0] = g; x[2][1] = h; x[2][2] = i;}template <class T>inlineMatrix33<T>::Matrix33 (const Matrix33 &v){ x[0][0] = v.x[0][0]; x[0][1] = v.x[0][1]; x[0][2] = v.x[0][2]; x[1][0] = v.x[1][0]; x[1][1] = v.x[1][1]; x[1][2] = v.x[1][2]; x[2][0] = v.x[2][0]; x[2][1] = v.x[2][1]; x[2][2] = v.x[2][2];}template <class T>inline const Matrix33<T> &Matrix33<T>::operator = (const Matrix33 &v){ x[0][0] = v.x[0][0]; x[0][1] = v.x[0][1]; x[0][2] = v.x[0][2]; x[1][0] = v.x[1][0]; x[1][1] = v.x[1][1]; x[1][2] = v.x[1][2]; x[2][0] = v.x[2][0]; x[2][1] = v.x[2][1]; x[2][2] = v.x[2][2]; return *this;}template <class T>inline const Matrix33<T> &Matrix33<T>::operator = (T a){ x[0][0] = a; x[0][1] = a; x[0][2] = a; x[1][0] = a; x[1][1] = a; x[1][2] = a; x[2][0] = a; x[2][1] = a; x[2][2] = a; return *this;}template <class T>inline T *Matrix33<T>::getValue (){ return (T *) &x[0][0];}template <class T>inline const T *Matrix33<T>::getValue () const{ return (const T *) &x[0][0];}template <class T>template <class S>inline voidMatrix33<T>::getValue (Matrix33<S> &v) const{ v.x[0][0] = x[0][0]; v.x[0][1] = x[0][1]; v.x[0][2] = x[0][2]; v.x[1][0] = x[1][0]; v.x[1][1] = x[1][1]; v.x[1][2] = x[1][2]; v.x[2][0] = x[2][0]; v.x[2][1] = x[2][1]; v.x[2][2] = x[2][2];}template <class T>template <class S>inline Matrix33<T> &Matrix33<T>::setValue (const Matrix33<S> &v){ x[0][0] = v.x[0][0]; x[0][1] = v.x[0][1]; x[0][2] = v.x[0][2]; x[1][0] = v.x[1][0]; x[1][1] = v.x[1][1]; x[1][2] = v.x[1][2]; x[2][0] = v.x[2][0]; x[2][1] = v.x[2][1]; x[2][2] = v.x[2][2]; return *this;}template <class T>template <class S>inline Matrix33<T> &Matrix33<T>::setTheMatrix (const Matrix33<S> &v){ x[0][0] = v.x[0][0]; x[0][1] = v.x[0][1]; x[0][2] = v.x[0][2]; x[1][0] = v.x[1][0]; x[1][1] = v.x[1][1]; x[1][2] = v.x[1][2]; x[2][0] = v.x[2][0]; x[2][1] = v.x[2][1]; x[2][2] = v.x[2][2]; return *this;}template <class T>inline voidMatrix33<T>::makeIdentity(){ x[0][0] = 1; x[0][1] = 0; x[0][2] = 0; x[1][0] = 0; x[1][1] = 1; x[1][2] = 0; x[2][0] = 0; x[2][1] = 0; x[2][2] = 1;}template <class T>boolMatrix33<T>::operator == (const Matrix33 &v) const{ return x[0][0] == v.x[0][0] && x[0][1] == v.x[0][1] && x[0][2] == v.x[0][2] && x[1][0] == v.x[1][0] && x[1][1] == v.x[1][1] && x[1][2] == v.x[1][2] && x[2][0] == v.x[2][0] && x[2][1] == v.x[2][1] && x[2][2] == v.x[2][2];}template <class T>boolMatrix33<T>::operator != (const Matrix33 &v) const{ return x[0][0] != v.x[0][0] || x[0][1] != v.x[0][1] || x[0][2] != v.x[0][2] || x[1][0] != v.x[1][0] || x[1][1] != v.x[1][1] || x[1][2] != v.x[1][2] || x[2][0] != v.x[2][0] || x[2][1] != v.x[2][1] || x[2][2] != v.x[2][2];}template <class T>boolMatrix33<T>::equalWithAbsError (const Matrix33<T> &m, T e) const{ for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (!Imath::equalWithAbsError ((*this)[i][j], m[i][j], e)) return false; return true;}template <class T>boolMatrix33<T>::equalWithRelError (const Matrix33<T> &m, T e) const{ for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (!Imath::equalWithRelError ((*this)[i][j], m[i][j], e)) return false; return true;}template <class T>const Matrix33<T> &Matrix33<T>::operator += (const Matrix33<T> &v){ x[0][0] += v.x[0][0]; x[0][1] += v.x[0][1]; x[0][2] += v.x[0][2]; x[1][0] += v.x[1][0]; x[1][1] += v.x[1][1]; x[1][2] += v.x[1][2]; x[2][0] += v.x[2][0]; x[2][1] += v.x[2][1]; x[2][2] += v.x[2][2]; return *this;}template <class T>const Matrix33<T> &Matrix33<T>::operator += (T a){ x[0][0] += a; x[0][1] += a; x[0][2] += a; x[1][0] += a; x[1][1] += a; x[1][2] += a; x[2][0] += a; x[2][1] += a; x[2][2] += a; return *this;}template <class T>Matrix33<T>Matrix33<T>::operator + (const Matrix33<T> &v) const{ return Matrix33 (x[0][0] + v.x[0][0], x[0][1] + v.x[0][1], x[0][2] + v.x[0][2], x[1][0] + v.x[1][0], x[1][1] + v.x[1][1], x[1][2] + v.x[1][2], x[2][0] + v.x[2][0], x[2][1] + v.x[2][1], x[2][2] + v.x[2][2]);}template <class T>const Matrix33<T> &Matrix33<T>::operator -= (const Matrix33<T> &v){ x[0][0] -= v.x[0][0]; x[0][1] -= v.x[0][1]; x[0][2] -= v.x[0][2]; x[1][0] -= v.x[1][0]; x[1][1] -= v.x[1][1]; x[1][2] -= v.x[1][2]; x[2][0] -= v.x[2][0]; x[2][1] -= v.x[2][1]; x[2][2] -= v.x[2][2]; return *this;}template <class T>const Matrix33<T> &Matrix33<T>::operator -= (T a){ x[0][0] -= a; x[0][1] -= a; x[0][2] -= a; x[1][0] -= a; x[1][1] -= a; x[1][2] -= a; x[2][0] -= a; x[2][1] -= a; x[2][2] -= a; return *this;}template <class T>Matrix33<T>Matrix33<T>::operator - (const Matrix33<T> &v) const{ return Matrix33 (x[0][0] - v.x[0][0], x[0][1] - v.x[0][1], x[0][2] - v.x[0][2], x[1][0] - v.x[1][0], x[1][1] - v.x[1][1], x[1][2] - v.x[1][2], x[2][0] - v.x[2][0], x[2][1] - v.x[2][1], x[2][2] - v.x[2][2]);}template <class T>Matrix33<T>Matrix33<T>::operator - () const{ return Matrix33 (-x[0][0], -x[0][1], -x[0][2], -x[1][0], -x[1][1], -x[1][2], -x[2][0], -x[2][1], -x[2][2]);}template <class T>const Matrix33<T> &Matrix33<T>::negate (){ x[0][0] = -x[0][0]; x[0][1] = -x[0][1]; x[0][2] = -x[0][2]; x[1][0] = -x[1][0]; x[1][1] = -x[1][1]; x[1][2] = -x[1][2]; x[2][0] = -x[2][0]; x[2][1] = -x[2][1]; x[2][2] = -x[2][2]; return *this;}template <class T>const Matrix33<T> &Matrix33<T>::operator *= (T a){ x[0][0] *= a; x[0][1] *= a; x[0][2] *= a; x[1][0] *= a; x[1][1] *= a; x[1][2] *= a; x[2][0] *= a; x[2][1] *= a; x[2][2] *= a; return *this;}template <class T>Matrix33<T>Matrix33<T>::operator * (T a) const{ return Matrix33 (x[0][0] * a, x[0][1] * a, x[0][2] * a, x[1][0] * a, x[1][1] * a, x[1][2] * a, x[2][0] * a, x[2][1] * a, x[2][2] * a);}template <class T>inline Matrix33<T>operator * (T a, const Matrix33<T> &v){ return v * a;}template <class T>const Matrix33<T> &Matrix33<T>::operator *= (const Matrix33<T> &v){ Matrix33 tmp (T (0)); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) tmp.x[i][j] += x[i][k] * v.x[k][j]; *this = tmp; return *this;}template <class T>Matrix33<T>Matrix33<T>::operator * (const Matrix33<T> &v) const{ Matrix33 tmp (T (0)); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) tmp.x[i][j] += x[i][k] * v.x[k][j]; return tmp;}template <class T>template <class S>voidMatrix33<T>::multVecMatrix(const Vec2<S> &src, Vec2<S> &dst) const{ S a, b, w; a = src[0] * x[0][0] + src[1] * x[1][0] + x[2][0]; b = src[0] * x[0][1] + src[1] * x[1][1] + x[2][1]; w = src[0] * x[0][2] + src[1] * x[1][2] + x[2][2]; dst.x = a / w; dst.y = b / w;}template <class T>template <class S>voidMatrix33<T>::multDirMatrix(const Vec2<S> &src, Vec2<S> &dst) const{ S a, b; a = src[0] * x[0][0] + src[1] * x[1][0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -