00001 // 00002 // Copyright (C) 2005-2006 Rational Discovery LLC 00003 // 00004 // @@ All Rights Reserved @@ 00005 // 00006 #ifndef __RD_TRANSFORM3D_H__ 00007 #define __RD_TRANSFORM3D_H__ 00008 00009 #include "Transform.h" 00010 00011 #include <Numerics/SquareMatrix.h> 00012 00013 namespace RDGeom { 00014 class Point3D; 00015 const unsigned int DIM_3D=4; 00016 00017 class Transform3D : public RDNumeric::SquareMatrix<double> { 00018 public: 00019 //! Constructor 00020 /*! 00021 Initialize to an identity matrix transformation. 00022 This is a 4x4 matrix that includes the rotation and translation parts 00023 see Foley's "Introduction to Computer Graphics" for the representation 00024 00025 Operator *= and = are provided by the parent class square matrix. 00026 Operator *= needs some explanation, since the order matters. This transform gets set to 00027 the combination other and the current state of this transform 00028 If this_old and this_new are the states of this object before and after this function 00029 we have 00030 this_new(point) = this_old(other(point)) 00031 */ 00032 00033 Transform3D() : RDNumeric::SquareMatrix<double>(DIM_3D,0.0) { 00034 unsigned int i, id; 00035 for (i = 0; i < DIM_3D; i++) { 00036 id = i*(DIM_3D+1); 00037 d_data[id] = 1.0; 00038 } 00039 } 00040 00041 void setToIdentity(); 00042 00043 void TransformPoint(Point3D &pt) const; 00044 00045 /*! \brief Set the translation vector 00046 */ 00047 void SetTranslation(const Point3D &move); 00048 00049 /*! \brief set the rotation matrix 00050 * 00051 * The rotation matrix is set to rotation by th specified angle 00052 * about the specified axis 00053 */ 00054 void SetRotation(double angle, AxisType axis); 00055 00056 /*! \brief set the rotation matrix 00057 * 00058 * The rotation matrix is set to rotation by th specified angle 00059 * about an arbitrary axis 00060 */ 00061 void SetRotation(double angle, const Point3D &axis); 00062 void SetRotation(double cosT,double sinT,const Point3D &axis); 00063 00064 //! Set the rotation matrix from a quaternion 00065 void SetRotationFromQuaternion(double quaternion[4]); 00066 00067 //! Reflect the rotation 00068 void Reflect(); 00069 00070 private: 00071 00072 }; 00073 } 00074 00075 /*! \brief Combine two transforms and return the results as a new transform 00076 * 00077 * The order is important here, on two transforms t1 and t2 00078 * t3 = t1*t2 00079 * The resulting transform t3 has the folliwng effect 00080 * t3(point) = t1(t2(point)) 00081 */ 00082 RDGeom::Transform3D operator* (const RDGeom::Transform3D &t1, const RDGeom::Transform3D &t2); 00083 00084 /*! \brief Transform a point: 00085 * 00086 */ 00087 RDGeom::Point3D operator* (const RDGeom::Transform3D &t, const RDGeom::Point3D &pt); 00088 00089 00090 #endif 00091 00092
1.5.3