//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TGMatrix 类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TGMatrix 声明 三维变换矩阵,右乘 // = Maintainers: cpp中336行,为; // //-------------------------------------------------------------------------------------------------------+ #ifndef _TGMATRIX_H_ #define _TGMATRIX_H_ #ifndef _TGVECTOR2D_H_ #include "TGVector2D.h" #endif #ifndef _TGVECTOR3D_H_ #include "TGVector3D.h" #endif #ifndef _TPGECOORDSYS_H_ #include "TPGeCoordSys.h" #endif #ifndef _TPGELINE3D_H_ #include "TPGeLine3D.h" #endif #ifndef _TGPOINT_H_ #include "TGPoint.h" #endif #ifndef _TPGEPLANE_H_ #include "TPGePlane.h" #endif typedef double GTransformMatrix[4][4]; class GEOAPI TGMatrix { public: TGMatrix(); TGMatrix(const TGMatrix& m2); TGMatrix& operator = (const TGMatrix& m2); TGMatrix& operator = (const float *m); virtual ~TGMatrix(); //data double *operator [](int i) const; //Set void Init(); void InitIdentity(); TGMatrix& operator *= (const TGMatrix & m2); //逆矩阵 bool Reverse(); //翻转矩阵 void Swap(); //TPGeCoordSys void SetCoordSys(const TGPoint& pt,const TGVector3D& x,const TGVector3D& y,const TGVector3D& z); void SetCoordSys(const TGPoint& pt,const TGVector3D& z,bool bRight = true); void SetCoordSys(const TPGePlane& plane,bool bRight = true); void SetCoordSys(const TGPoint& pt,const TGVector3D& x,const TGVector3D& vt,bool bRight = true); void SetCoordSys(const TGPoint& pt,const TGPoint& xPt,const TGPoint& yPt,bool bRight = true); void GetCoordSys(TPGeCoordSys& sys) const; //构造具体变换矩阵,调用之前保证初始化为单位矩阵(用InitIdentity())! //二维变换矩阵 void CreateMoveMatrix(double cx,double cy); void CreateMoveMatrix(const TGVector2D& vt); void CreateScaleMatrix(double sx,double sy); void CreateScaleMatrix(double sx,double sy,const TGPoint& basePoint); void CreateRotateMatrix(double angle,const TGPoint& basePoint); //三维变换 void CreateMoveMatrix(double cx,double cy,double cz); void CreateMoveMatrix(const TGVector3D& vt); void CreateScaleMatrix(double sx,double sy,double sz); void CreateScaleMatrix(double sx,double sy,double sz,const TGPoint & basePoint); void CreateXRotateMatrix(double angle); void CreateYRotateMatrix(double angle); void CreateZRotateMatrix(double angle); void CreateRotateMatrix(double angle,const TPGeLine3D & axis); //投影 //正平行投影到XY平面,使所有Z分量变为0 void CreateXYProjectMatrix(); //投影到XY平面,选择平行投影或一点透视投影 bool CreateXYProjectMatrix(const TGPoint& pt,bool bParallel = true); //投影到plane平面,选择平行投影或一点透视投影 bool CreateProjectMatrix(const TPGePlane& plane,const TGPoint& pt,bool bParallel = true); //transform void Transform2D(TGPoint & point) const; void Transform3D(TGPoint & point) const; void Transform(TGVector3D& vt) const; void Transform(TGVector2D& vt) const; //other TGMatrix operator *(const TGMatrix& m2) const; double Rank() const; bool CanReverse() const; //转化为float矩阵 void Export(float*m) const; public: GTransformMatrix matrix; }; inline void TGMatrix::SetCoordSys(const TGPoint& pt,const TGVector3D& x,const TGVector3D& y,const TGVector3D& z) { TPGeCoordSys coord(pt,x,y,z); coord.GetMatrixTo(this); } inline void TGMatrix::SetCoordSys(const TGPoint& pt,const TGVector3D& z,bool bRight) { TPGeCoordSys coord(pt,z,bRight); coord.GetMatrixTo(this); } inline void TGMatrix::SetCoordSys(const TPGePlane& plane,bool bRight) { TPGeCoordSys coord(plane,bRight); coord.GetMatrixTo(this); } inline void TGMatrix::SetCoordSys(const TGPoint& pt,const TGPoint& xPt,const TGPoint& yPt,bool bRight) { TPGeCoordSys coord(pt,xPt,yPt,bRight); coord.GetMatrixTo(this); } inline void TGMatrix::SetCoordSys(const TGPoint& pt,const TGVector3D& x,const TGVector3D& vt,bool bRight) { TPGeCoordSys coord(pt,x,vt,bRight); coord.GetMatrixTo(this); } //正平行投影到XY平面,使所有Z分量变为0 inline void TGMatrix::CreateXYProjectMatrix() { matrix[2][0] = matrix[2][1] = matrix[2][2] = matrix[2][3] = 0; } #endif