Frame.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SOFA_DEFAULTTYPE_FRAME_H
00028 #define SOFA_DEFAULTTYPE_FRAME_H
00029
00030 #include <sofa/defaulttype/Vec.h>
00031 #include <sofa/defaulttype/Mat.h>
00032 #include <sofa/helper/Quater.h>
00033
00034 namespace sofa
00035 {
00036
00037 namespace defaulttype
00038 {
00039
00048 class Frame
00049 {
00050 public:
00051 typedef Vec<3,SReal> Vec3;
00052 typedef helper::Quater<SReal> Quat;
00053 typedef Mat<3,3,SReal> Mat33;
00054 private:
00055 Vec3 origin_;
00056 Mat33 basis_;
00057 public:
00059 Frame (const Vec3 &origin, const Mat33& m );
00060
00062 Frame (const Vec3 &origin, const Quat &orientation, const Vec3& scale=Vec3(1,1,1) );
00063
00065 Frame (const Vec3 &origin );
00066
00068 Frame ();
00069
00071 void setTransform( const Vec3& origin, const Quat& orientation, const Vec3& scale );
00072
00074 void clear();
00075
00077 Vec3& getOrigin ();
00078
00080 const Vec3& getOrigin () const;
00081
00083 void setOrigin( const Vec3& origin );
00084
00086 Mat33& getBasis ();
00087
00089 const Mat33& getBasis () const;
00090
00092 void setBasis( const Mat33& m );
00093
00095 static Frame identity();
00096
00098 void multRight( const Frame& c );
00099
00101 Frame mult( const Frame& c ) const;
00102
00104 void writeOpenGlMatrix( float* m ) const;
00105
00107 void writeOpenGlMatrix( double* m ) const;
00108
00110 template<class V>
00111 V projectVector( const V& v ) const
00112 {
00113 return V(
00114 basis_[0][0]*v[0]+basis_[0][1]*v[1]+basis_[0][2]*v[2],
00115 basis_[1][0]*v[0]+basis_[1][1]*v[1]+basis_[1][2]*v[2],
00116 basis_[2][0]*v[0]+basis_[2][1]*v[1]+basis_[2][2]*v[2]
00117 );
00118 }
00119
00121 template<class V>
00122 V projectPoint( const V& v ) const
00123 {
00124 return projectVector(v)+origin_;
00125 }
00126
00128 Frame inversed() const;
00129
00130 friend std::ostream& operator << (std::ostream& out, const Frame& c );
00131 };
00132 }
00133
00134 }
00135 #endif