メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ | 関連ページ

Affine.h

説明を見る。
00001 #ifndef AFFINE_H
00002 #define AFFINE_H
00003 
00004 /** @page Affine @!JPアフィン行列クラスライブラリ @!EN Affine Matrix Library @!*
00005     @section intro @!JP はじめに @!EN Introduction @!*
00006         @!JP
00007         このドキュメントはAffine行列クラスライブラリのドキュメントです.
00008         Affine行列クラスライブラリは,3Dシミュレーションに必須な
00009         Affine行列をC++のクラスにしたものです.
00010         @!EN
00011         This is a document for Affine Matrix Library.
00012         Affine Matrix Library is a set of classes for affine matrix,
00013         which are necessary for 3D simulation.
00014         @!*
00015     @section affine_usage @!JP 使い方 @!EN Usage @!*
00016     @!JP
00017     Affine 行列クラスライブラリは,ヘッダファイルだけからなる
00018     クラスライブラリなので, TAffine.h, TinyVec.h, TinyMat.h, TMatrix.h, TMatrixUtility.h, TVector.h
00019     を同じフォルダに入れておき,.cppファイルからヘッダをインクルードするだけで
00020     使用できます.
00021     @!EN
00022     Affine Matrix Library consist only from some header files.
00023     You can use this library just coping some header files
00024     (TAffine.h, TinyVec.h, TinyMat.h, TMatrix.h, TMatrixUtility.h, TVector.h)
00025     and including them from your .cpp files.
00026     @!*
00027     @subsection sample @!JA サンプル @!EN Sample
00028     @verbatim
00029 #include "Affine.h"                         //  TAffine行列ライブラリのインクルードする.
00030 #include <iostream>
00031     //  @!JA Affine行列クラスはSpr名前空間の中で宣言されている.
00032         @!EN Affine matrix class is declared in the name space of Spr.
00033         @!*
00034 void main(){
00035     Affinef af=Affinef::Rad(Rad(30), 'z');  //  @!JA要素がfloatなTAffine行列を宣言. 
00036                                                 @!ENDeclare an Affine matrix of float element.
00037                                                 @!*
00038                                                 @!JPz軸回り30度回転行列に初期化
00039                                                 @!ENInitializing as a matrix of rotation of 30 degrees around z axis.
00040                                                 @!*
00041                                                 
00042     Vec3f vec(1,0,0);                       //  @!JA要素がfloatな3次元のベクトルを宣言
00043                                                 @!ENDeclare a vector of float element.
00044                                                 @!*
00045     std::cout << af;
00046     std::cout << vec << std::endl;
00047     std::cout << af * vec << std::endl;
00048 }@endverbatim
00049     @subsection af_vec @!JA Affine行列・ベクトルの機能 @!EN Functions of Affine matrixs and vectors. @!*
00050     @!JA
00051     普通に演算ができます.
00052     <ul>
00053     <li> +:和, -:差, *:積/内積, /:定数分の1
00054     <li> ==:比較, =:代入
00055     <li> <<:出力, >>:入力
00056     <li> %:ベクトルの外積
00057     </ul>
00058     @!EN Normal calculations are supported.
00059     <ul>
00060     <li> +:addition, -:subtraction, *:multiplication/inner product, /:division
00061     <li> ==:comparison, =:assign
00062     <li> <<:output, >>:input
00063     <li> %:cross product
00064     </ul>
00065     @!*
00066     @!JA
00067     Affine変換は,
00068     @verbatim
00069     TAffine<float> af; TVec3<float> v, af_v;
00070     af_v = af * v;@endverbatim
00071     とすればできます.
00072     @!EN
00073     Affine transformation is executed by:
00074     @verbatim
00075     TAffine<float> af; TVec3<float> v, af_v;
00076     af_v = af * v;@endverbatim
00077     @!*
00078     @!JA
00079     また,次のようにTAffine行列の部分を取り出すことができます.
00080     <ul>
00081         <li> af.Ex():   X軸基底ベクトル.(3次元ベクトル).
00082         <li> af.Ey():   Y軸基底ベクトル.(3次元ベクトル).
00083         <li> af.Ez():   Z軸基底ベクトル.(3次元ベクトル).
00084         <li> af.Trn():  平行移動部分.(3次元ベクトル).
00085         <li> af.Rot():  回転変換部分.(3×3行列).
00086     </ul>
00087     @!EN
00088     You can extract some portion of the Affine matrix as:
00089     <ul>
00090         <li> af.Ex():   base vector for x axis (3 dimensional vector)
00091         <li> af.Ey():   base vector for y axis (3 dimensional vector)
00092         <li> af.Ez():   base vector for z axis (3 dimensional vector)
00093         <li> af.Trn():  portion of translation.(3 dimensional vector)
00094         <li> af.Rot():  portion of rotation.(3x3 matrix)
00095     </ul>
00096     @!*
00097     @!JA 部分への代入などもできます.
00098     @!EN You can assign portion of affine matrx.
00099     @!*
00100     @verbatim
00101     TAffine<float> af;
00102     af.Pos() = Vec3f(10,0,0);
00103     af.Rot() = TAffine<float>::Rot(Rad(30), 'x').Rot() * af.Rot();@endverbatim
00104     @!JA ベクトルは次のようなメンバ関数を持ちます.
00105     @!EN a vector has following members.
00106     @!*
00107     <ul>
00108     <li> unit(): @!JA 向きが等しい単位ベクトルを返す.
00109                  @!EN return a unit vector.
00110                  @!*
00111     <li> norm(): @!JA ベクトルの大きさ(ノルム)を返す.
00112                  @!EN return the size (norm) of a vector.
00113                  @!*
00114     </ul>
00115     @subsection affConstract Affine行列の初期化機能
00116     TAffine行列(Spr::TAffine)には便利なコンストラクタや初期化関数を用意しました.
00117     いくつかをここで紹介します.
00118     <ul>
00119         <li> Affinef(float x, float y, float z):        (x,y,z) 平行移動する行列に初期化
00120         <li> Affinef(Vec3f ex, Vec3f ey, Vec3f pos):    直接代入して初期化, ez = ex%ey とする.
00121         <li> Affinef::Rot(float rad, char axis):        回転行列を返す. axisは,'x', 'y', 'z'.
00122         <li> Affinef::Rot(float rad, Vec3f axis):       回転行列を返す.
00123         <li> Affinef::ProjectionD3D(Vec3f screen, Vec2f size, float f, float b): D3D用射影行列として初期化.
00124         <li> Affinef::ProjectionGL(Vec3f screen, Vec2f size, float f, float b):  D3D用射影行列として初期化.
00125         <br>
00126             OpenGL用射影行列として初期化(-Zが前).
00127             <ul>
00128                 <li> screen   カメラから見たビューポートの中心の位置  
00129                 <li> size   ビューポートのサイズ  
00130                 <li> f      手前のクリッピング平面とカメラの距離  
00131                 <li> b      奥のクリッピング平面とカメラの距離  
00132             </ul>
00133         <li> void LookAtGL(Vec3f posz, Vec3f posy):位置はそのままで,poszに-Ez(), posy に Ey()
00134             が向くようなTAffine行列
00135     </ul>
00136     
00137     @section thanks 謝辞
00138     LU分解,逆行列,ガウス消去法などの行列計算アルゴリズムは,<br>
00139     「『C言語による最新アルゴリズム事典』全ソースコード」<br>
00140     ftp://ftp.matsusaka-u.ac.jp/pub/algorithms<br>
00141     奥村 晴彦 Haruhiko Okumura<br>
00142     を改変して流用させていただきました.
00143     自由にコードを使わせてくださって,ありがとうございます.
00144     
00145 */
00146 
00147 #include "TMatrix.h"
00148 #include "TMatrixUtility.h"
00149 #include "TinyVec.h"
00150 #include "TinyMat.h"
00151 #include "TQuaternion.h"
00152 
00153 /** @file Affine.h 2/3次元アフィン行列*/
00154 
00155 #ifndef PTM_PACK    //  単体で使用する場合は,namespace に入れない
00156 namespace Spr {
00157 #endif
00158 
00159 #ifdef _WIN32
00160  #ifdef _DEBUG
00161   #pragma optimize ("awgity", on)
00162   #pragma auto_inline(on)
00163   #pragma inline_recursion(on)
00164  #endif
00165 #endif
00166 
00167 /**@defgroup TAffine    2/3次元ベクトル・TAffine行列    */
00168 //@{
00169 #undef M_PI
00170 /// 円周率π
00171 #ifdef __BORLANDC__
00172 #define M_PI 3.14159265358979323846
00173 #else
00174 const double M_PI = 3.14159265358979323846;
00175 #endif
00176 
00177 #undef abs
00178 /** 絶対値.BCB6が違う関数をリンクしてしまう(たぶんバグ)ので,template は使用していない
00179     std::abs とぶつかるためだと思われる.   */
00180 #ifdef __BORLANDC__
00181 #define DEF_ABS_FUNC(T)     inline T abs(T t){ return t > T()  ?  t  :  -t; }
00182 DEF_ABS_FUNC(float)
00183 DEF_ABS_FUNC(double)
00184 DEF_ABS_FUNC(char)
00185 DEF_ABS_FUNC(int)
00186 DEF_ABS_FUNC(long)
00187 #else
00188 template <class T> T abs(T t){ return t > T()  ?  t  :  -t; }
00189 #endif
00190 
00191 #undef sign
00192 /// 符号(正なら1, 負なら -1 を返す)
00193 template <class T> T sign(T t){
00194     return t > T()  ?  T(1)  :  T(-1);
00195 }
00196 
00197 #undef min
00198 /// 小さい方を返す
00199 template <class T> T min(T a, T b){return a < b ? a : b;}
00200 
00201 #undef max
00202 /// 大きい方を返す
00203 template <class T> T max(T a, T b){return a > b ? a : b;}
00204 
00205 /// 度をラジアンに変換
00206 inline double Rad(double deg){
00207     return ((double)deg/360*2*M_PI);
00208 }
00209 inline float Radf(double deg){
00210     return (float)((double)deg/360*2*M_PI);
00211 }
00212 /// ラジアンを度に変換
00213 inline double Deg(double rad){
00214     return (rad/(2*M_PI)) * 360;
00215 }
00216 inline float Degf(double rad){
00217     return (float)(rad/(2*M_PI)) * 360;
00218 }
00219 /// 2乗
00220 template <class SC>
00221 inline SC Square(SC x){
00222     return x*x;
00223 }
00224 /// 2x2行列の行列式
00225 template <class SC>
00226 inline SC Det2(SC a, SC b, SC c, SC d){
00227     return ((a)*(d) - (b)*(c));
00228 }
00229 
00230 //-----------------------------------------------------------------------------
00231 //  TAffine2
00232 
00233 /** TAffine2行列(回転,拡大,平行移動を表す)行列のクラス. */
00234 template <class T>
00235 class TAffine2:public PTM::TMatrixBase<DIMENC(3),DIMENC(3),
00236     PTM::TMatrixDescCol< TAffine2<T>, PTM::TMatrixRow<3,3,T>, 3,3,3,T> >{
00237 public:
00238     typedef PTM::TMatrixDescCol< TAffine2<T>, PTM::TMatrixRow<3,3,T>, 3,3,3,T> desc;
00239     typedef PTM::TMatrixBase<DIMENC(3),DIMENC(3),desc> base_type;
00240     /// 基本的なメンバの定義 @see ::DEF_TMATRIX_BASIC_MEMBER
00241     DEF_MATRIX_BASIC_MEMBER(TAffine2);
00242     union{
00243         struct{
00244             T xx, xy, xz;
00245             T yx, yy, yz;
00246             T px, py, pz;
00247         };
00248         T data[3][3];
00249     };
00250     /// 要素のアクセス
00251     element_type& item_impl(size_t i, size_t j){ return data[j][i]; }
00252     const element_type& item_impl(size_t i, size_t j) const { return data[j][i]; }
00253     
00254     /**@name    基底ベクトルへのアクセス    */
00255     //@{
00256     /// 
00257     TVec2<element_type>& Ex(){
00258         return *(TVec2<element_type>*) &item(0,0);
00259     }
00260     /// 
00261     const TVec2<element_type>& Ex() const{
00262         return *(TVec2<element_type>*) &item(0,0);
00263     }
00264     /// 
00265     TVec2<element_type>& Ey(){
00266         return *(TVec2<element_type>*) &item(0,1);
00267     }
00268     /// 
00269     const TVec2<element_type>& Ey() const{
00270         return *(TVec2<element_type>*) &item(0,1);
00271     }
00272     /// 
00273     TVec2<element_type>& Trn(){
00274         return *(TVec2<element_type>*) &item(0,2);
00275     }
00276     /// 
00277     const TVec2<element_type>& Trn() const{
00278         return *(TVec2<element_type>*) &item(0,2);
00279     }
00280     /// 
00281     TVec2<element_type>& Pos(){ return Trn(); }
00282     /// 
00283     const TVec2<element_type>& Pos() const { return Trn(); }
00284     //@}
00285 
00286     /**@name    要素へのアクセス    */
00287     //@{
00288     /// 
00289     element_type& ExX() {return Ex().X();}
00290     /// 
00291     element_type& ExY() {return Ex().Y();}
00292     /// 
00293     element_type& EyX() {return Ey().X();}
00294     /// 
00295     element_type& EyY() {return Ey().Y();}
00296     /// 
00297     element_type& TrnX() {return Trn().X();}
00298     /// 
00299     element_type& TrnY() {return Trn().Y();}
00300     /// TrnX()の別名
00301     element_type& PosX() {return Trn().X();}
00302     /// TrnY()の別名
00303     element_type& PosY() {return Trn().Y();}
00304     //@}
00305 
00306     /// 回転拡大変換部を取り出す.
00307     PTM::TSubMatrixCol<2,2, desc>& Rot() { return sub_matrix(0,0,PTM::TSubMatrixCol<2,2, desc>()); }
00308     /// 回転拡大変換部を取り出す (const版).
00309     const PTM::TSubMatrixCol<2,2, desc>& Rot() const { return sub_matrix(0,0,PTM::TSubMatrixCol<2,2, desc>()); }
00310     
00311     /**@name    初期化と構築    */
00312     //@{
00313     /// 単位行列
00314     static TAffine2<T> Unit(){
00315         TAffine2<T> y;
00316         PTM::init_unitize(y);
00317         return y;
00318     }
00319     /// 平行移動
00320     static TAffine2<T> Trn(element_type px, element_type py){
00321         TAffine2<T> y;
00322         y.Trn().X() = px;
00323         y.Trn().Y() = py;
00324         return y;
00325     }
00326     /// 回転,なぜか引数がひとつだとVC.netでエラーになる.
00327     static TAffine2<T> Rot(element_type th, int d=0){
00328         TAffine2 y;
00329         PTM::init_rot(y.Rot(), th);
00330         return y;
00331     }
00332     /// 拡大
00333     static TAffine2<T> Scale(element_type sx, element_type sy){
00334         TAffine2<T> y;
00335         y.item(0, 0) = sx; y.item(1, 1) = sy;
00336         return y;
00337     }
00338     ///コンストラクタ
00339     void set_default(){PTM::init_unitize(*this);}
00340     //@}
00341 };
00342 
00343 //-----------------------------------------------------------------------------
00344 //  TAffine
00345 /// TAffine行列(回転,拡大,平行移動を表す)行列のもとになるクラス.
00346 template <class T>
00347 class TAffine:public PTM::TMatrixBase<DIMENC(4),DIMENC(4),
00348     PTM::TMatrixDescCol< TAffine<T>, PTM::TMatrixRow<4,4,T>, 4,4,4,T> >{
00349 public:
00350     typedef PTM::TMatrixDescCol< TAffine<T>, PTM::TMatrixRow<4,4,T>, 4,4,4,T> desc;
00351     typedef PTM::TMatrixBase<DIMENC(4),DIMENC(4),desc> base_type;
00352     /** 継承されない基本的なメンバの定義.
00353         @see ::DEF_TVECTOR_BASIC_MEMBER */
00354     DEF_MATRIX_BASIC_MEMBER(TAffine);
00355     union{
00356         struct{
00357             T xx, xy, xz, xw;
00358             T yx, yy, yz, yw;
00359             T zx, zy, zz, zw;
00360             T px, py, pz, pw;
00361         };
00362         T data[4][4];
00363     };
00364     /// 要素のアクセス
00365     element_type& item_impl(size_t i, size_t j){ return data[j][i]; }
00366     const element_type& item_impl(size_t i, size_t j) const { return data[j][i]; }
00367 
00368     /**@name    基底ベクトルへのアクセス    */
00369     //@{
00370     /// 
00371     TVec3<element_type>& Ex() { return (TVec3<element_type>&)col(0); }
00372     /// 
00373     const TVec3<element_type>& Ex() const { return (TVec3<element_type>&)col(0); }
00374     /// 
00375     TVec3<element_type>& Ey() { return (TVec3<element_type>&)col(1); }
00376     /// 
00377     const TVec3<element_type>& Ey() const { return (TVec3<element_type>&)col(1); }
00378     /// 
00379     TVec3<element_type>& Ez() { return (TVec3<element_type>&)col(2); }
00380     /// 
00381     const TVec3<element_type>& Ez() const { return (TVec3<element_type>&)col(2); }
00382     /// 
00383     TVec3<element_type>& Trn() { return (TVec3<element_type>&)col(3); }
00384     /// 
00385     const TVec3<element_type>& Trn() const { return (TVec3<element_type>&)col(3); }
00386     /// 平行移動成分(Trn()の別名)
00387     TVec3<element_type>& Pos() {return Trn();}
00388     /// 平行移動成分(Trn()の別名,const 版)
00389     const TVec3<element_type>& Pos() const {return Trn();}
00390     //@}
00391 
00392     /**@name    要素へのアクセス    */
00393     //@{
00394     /// 
00395     element_type& ExX() {return Ex().X();}
00396     const element_type& ExX() const {return Ex().X();}
00397     /// 
00398     element_type& ExY() {return Ex().Y();}
00399     const element_type& ExY() const {return Ex().Y();}
00400     /// 
00401     element_type& ExZ() {return Ex().Z();}
00402     const element_type& ExZ() const {return Ex().Z();}
00403     /// 
00404     element_type& EyX() {return Ey().X();}
00405     const element_type& EyX() const {return Ey().X();}
00406     /// 
00407     element_type& EyY() {return Ey().Y();}
00408     const element_type& EyY() const {return Ey().Y();}
00409     /// 
00410     element_type& EyZ() {return Ey().Z();}
00411     const element_type& EyZ() const {return Ey().Z();}
00412     /// 
00413     element_type& EzX() {return Ez().X();}
00414     const element_type& EzX() const {return Ez().X();}
00415     /// 
00416     element_type& EzY() {return Ez().Y();}
00417     const element_type& EzY() const {return Ez().Y();}
00418     /// 
00419     element_type& EzZ() {return Ez().Z();}
00420     const element_type& EzZ() const {return Ez().Z();}
00421     /// 
00422     element_type& TrnX() {return Trn().X();}
00423     const element_type& TrnX() const {return Trn().X();}
00424     /// 
00425     element_type& TrnY() {return Trn().Y();}
00426     const element_type& TrnY() const {return Trn().Y();}
00427     /// 
00428     element_type& TrnZ() {return Trn().Z();}
00429     const element_type& TrnZ() const {return Trn().Z();}
00430     /// TrnX()の別名
00431     element_type& PosX() {return TrnX();}
00432     const element_type& PosX() const {return TrnX();}
00433     /// TrnY()の別名
00434     element_type& PosY() {return TrnY();}
00435     const element_type& PosY() const {return TrnY();}
00436     /// TrnZ()の別名
00437     element_type& PosZ() {return TrnZ();}
00438     const element_type& PosZ() const {return TrnZ();}
00439     ///
00440     element_type& ExW() {return item(3,0);}
00441     const element_type& ExW() const {return item(3,0);}
00442     ///
00443     element_type& EyW() {return item(3,1);}
00444     const element_type& EyW() const {return item(3,1);}
00445     ///
00446     element_type& EzW() {return item(3,2);}
00447     const element_type& EzW() const {return item(3,2);}
00448     ///
00449     element_type& TrnW() {return item(3,3);}
00450     const element_type& TrnW() const {return item(3,3);}
00451     ///
00452     element_type& PosW() {return item(3,3);}
00453     const element_type& PosW() const {return item(3,3);}
00454     //@}
00455 
00456     /// 回転拡大変換部への参照を返す.
00457     PTM::TSubMatrixCol<3,3, desc>& Rot(){ return sub_matrix(PTM::TSubMatrixDim<0,0,3,3>()); }
00458     /// 回転拡大変換部への参照を返す (const版).
00459     const PTM::TSubMatrixCol<3,3, desc>& Rot() const { return sub_matrix(PTM::TSubMatrixDim<0,0,3,3>()); }
00460 
00461     /**@name    初期化と構築    */
00462     /// 単位行列
00463     static TAffine<T> Unit(){
00464         TAffine<T> y;
00465         PTM::init_unitize(y);
00466         return y;
00467     }
00468     /// 平行移動
00469     static TAffine<T> Trn(element_type px, element_type py, element_type pz){
00470         TAffine<T> y;
00471         y.Trn().X() = px;
00472         y.Trn().Y() = py;
00473         y.Trn().Z() = pz;
00474         return y;
00475     }
00476     /// x/y/z軸まわり回転
00477     static TAffine<T> Rot(element_type th, char axis)
00478     {
00479         TAffine<T> y;
00480 #ifdef __BORLANDC__
00481         TMatrix3<T> r = y.Rot();
00482         PTM::init_rot(r, th, axis);
00483 #else
00484         PTM::init_rot(y.Rot(), th, axis);
00485 #endif
00486         return y;
00487     }
00488     /** 任意軸まわり回転 @verbatim
00489         +                                                                      +
00490         |u^2+(1-u^2)cos(th)      uv(1-cos(th))-wsin(th)  wu(1-cos(th))+vsin(th)|
00491     R = |uv(1-cos(th))+wsin(th)  v^2+(1-v^2)cos(th)      vw(1-cos(th))-usin(th)|
00492         |wu(1-cos(th))-vsin(th)  vw(1-cos(th))+usin(th)  w^2+(1-w^2)cos(th)    |
00493         +                                                                      +@endverbatim*/
00494     template <class BUF>
00495     static TAffine<T> Rot(element_type th, const PTM::TVectorBase<DIMENC(3), BUF>& axis)
00496     {
00497         TAffine<T> y;
00498         Matrix3f r;
00499         PTM::init_rot(r, th, axis);
00500         y.Rot() = r;
00501         return y;
00502     }
00503     /// 拡大
00504     static TAffine<T> Scale(element_type sx, element_type sy, element_type sz){
00505         TAffine<T> y;
00506         y.item(0, 0) = sx; y.item(1, 1) = sy; y.item(2, 2) = sz;
00507         return y;
00508     }
00509     /** OpenGLの射影行列として初期化
00510         @param screen   カメラから見たビューポートの中心の位置
00511         @param size     ビューポートのサイズ
00512         @param front    手前のクリッピング平面とカメラの距離
00513         @param back     奥のクリッピング平面とカメラの距離  */
00514     template <class BUFS, class BUFZ>
00515     static TAffine<T> ProjectionGL(
00516         const PTM::TVectorBase<DIMENC(3), BUFS>& screen,
00517         const PTM::TVectorBase<DIMENC(2), BUFZ>& size,
00518         element_type front=1.0f, element_type back=10000.0f)
00519     {
00520         TAffine<T> y;
00521         PTM::init_projection_gl(y, screen, size, front, back);
00522         return y;
00523     }
00524     /** Direct3Dの射影行列として初期化
00525         @param screen   カメラから見たビューポートの中心の位置
00526         @param size     ビューポートのサイズ
00527         @param front    手前のクリッピング平面とカメラの距離
00528         @param back     奥のクリッピング平面とカメラの距離  */
00529     template <class BUFS, class BUFZ>
00530     static TAffine<T> ProjectionD3D(const PTM::TVectorBase<DIMENC(3), BUFS>& screen,
00531     const PTM::TVectorBase<DIMENC(2), BUFZ>& size,
00532         element_type front=1.0f, element_type back=10000.0f)
00533     {
00534         TAffine<T> y;
00535         PTM::init_projection_d3d(y, screen, size, front, back);
00536         return y;
00537     }
00538 
00539     /// posiにEz()が向いたTAffine行列
00540     template <class BUF>
00541     void LookAt(const PTM::TVectorBase<DIMENC(3), BUF>& posi)
00542     {
00543         PTM::init_look_at(*this, posi);
00544     }
00545     /// poszにEz(), posy に Ey() が向いたTAffine行列
00546     template <class BUFZ, class BUFY>
00547     void LookAt(const PTM::TVectorBase<DIMENC(3), BUFZ>& posz, const PTM::TVectorBase<DIMENC(3), BUFY>& posy)
00548     {
00549         PTM::init_look_at(*this, posz, posy);
00550     }
00551     /// posiに-Ez()が向いたTAffine行列
00552     template <class BUF>
00553     void LookAtGL(const PTM::TVectorBase<DIMENC(3), BUF>& posi)
00554     {
00555         PTM::init_look_at_gl(*this, posi);
00556     }
00557     /// poszに-Ez(), posy に Ey() が向いたTAffine行列
00558     template <class BUFZ, class BUFY>
00559     void LookAtGL(const PTM::TVectorBase<DIMENC(3), BUFZ>& posz, const PTM::TVectorBase<DIMENC(3), BUFY>& posy)
00560     {
00561         PTM::init_look_at_gl(*this, posz, posy);
00562     }
00563     
00564     ///コンストラクタ
00565     void set_default(){PTM::init_unitize(*this);}
00566 };
00567 #define DEF_TAFFINE_CONSTRUCTORS(TAffine)                                               \
00568     TAffine(){*this=Unit();}                                                            \
00569     TAffine(element_type px, element_type py, element_type pz){*this=Trn(px, py, pz);}  \
00570     template <class BUFX, class BUFY>                                                   \
00571     TAffine(const PTM::TVectorBase<DIMENC(3), BUFX>& exi,                                   \
00572             const PTM::TVectorBase<DIMENC(3), BUFY>& eyi){                              \
00573             PTM::init_direct(Rot(), exi, eyi, 'x');                                     \
00574             item(3, 0) = 0; item(3, 1) = 0; item(3, 2) = 0; item(3, 3) = 1;             \
00575             item(0, 3) = 0; item(1, 3) = 0; item(2, 3) = 0;                             \
00576     }                                                                                   \
00577     template <class BUFX, class BUFY, class BUFP>                                       \
00578     TAffine(    const PTM::TVectorBase<DIMENC(3), BUFX>& exi,                               \
00579             const PTM::TVectorBase<DIMENC(3), BUFY>& eyi,                                   \
00580             const PTM::TVectorBase<DIMENC(3), BUFP>& posi){                             \
00581             PTM::init_direct(Rot(), exi, eyi, 'x');                                     \
00582             item(3, 0) = 0; item(3, 1) = 0; item(3, 2) = 0; item(3, 3) = 1;             \
00583             item(0, 3) = posi.X(); item(1, 3) = posi.Y(); item(2, 3) = posi.Z();        \
00584     }                                                                                   \
00585     template <class BUFA, class BUFB>                                                   \
00586     TAffine(    const PTM::TVectorBase<DIMENC(3), BUFA>& a,                             \
00587             const PTM::TVectorBase<DIMENC(3), BUFB>& b,                                 \
00588             char axis){                                                                 \
00589             PTM::init_direct(Rot(), exi, eyi, axis);                                    \
00590             item(3, 0) = 0; item(3, 1) = 0; item(3, 2) = 0; item(3, 3) = 1;             \
00591             item(0, 3) = 0; item(1, 3) = 0; item(2, 3) = 0;                             \
00592     }                                                                                   \
00593     template <class BUFA, class BUFB, class BUFP>                                       \
00594     TAffine(    const PTM::TVectorBase<DIMENC(3), BUFA>& a,                             \
00595             const PTM::TVectorBase<DIMENC(3), BUFB>& b,                                 \
00596             char axis, const PTM::TVectorBase<DIMENC(3), BUFP>& posi){                  \
00597             PTM::init_direct(Rot(), exi, eyi, axis);                                    \
00598             item(3, 0) = 0; item(3, 1) = 0; item(3, 2) = 0; item(3, 3) = 1;             \
00599             item(0, 3) = posi.X(); item(1, 3) = posi.Y(); item(2, 3) = posi.Z();        \
00600             }
00601 
00602 #define DEF_TAFFINE_CONSTRUCTORS2(TAffine)                                              \
00603     TAffine(element_type th, char axis) {                                               \
00604         *this=Rot(th, axis);                                                            \
00605     }                                                                                   \
00606     template <class BUF>                                                                \
00607     TAffine(element_type th, char axis,                                                 \
00608         const PTM::TVectorBase<DIMENC(3), BUF>& posi) {                                 \
00609         *this = Rot(th, axis); Pos() = posi; }                                          \
00610     template <class BUFA>                                                               \
00611     TAffine(element_type th, const PTM::TVectorBase<DIMENC(3), BUFA>& axis){                \
00612         *this = Rot(th, axis.unit());                                                   \
00613     }                                                                                   \
00614     template <class BUFA, class BUFP>                                                   \
00615     TAffine(element_type th, const PTM::TVectorBase<DIMENC(3), BUFA>& axis , const PTM::TVectorBase<DIMENC(3), BUFP>& posi){    \
00616         *this = Rot(th, axis.unit()); Pos() = posi;                                     \
00617     }                                                                                   \
00618     template <class BUFS, class BUFZ>                                                   \
00619     TAffine(const PTM::TVectorBase<DIMENC(3), BUFS>& screen, const PTM::TVectorBase<DIMENC(2), BUFZ>& size, element_type front=1.0f, element_type back=10000.0f){   \
00620         *this = ProjectionGL(screen, size, front, back);                                \
00621     }                                                                                   \
00622     template <class BUF, class BUFV>                                                    \
00623     TAffine(const PTM::TMatrixOp<3, 3, BUF>& m, const PTM::TVectorBase<DIMENC(3), BUFV> posi){\
00624         Rot() = m; Pos() = posi; ExW() = 0; EyW() = 0; EzW() = 0; PosW() = 1;           \
00625     }
00626 
00627 
00628 #ifdef _WIN32
00629  #pragma warning (disable: 4700)
00630 #endif
00631 /// TAffineとベクトルの掛け算
00632 template <class T, class TV>
00633 TVec3<TV> operator * (
00634     const TAffine<T>& a,
00635     const TVec3<TV>& b){
00636     TVec3<TV> r;
00637     r[0] = a[0][0]*b[0] + a[0][1]*b[1] + a[0][2]*b[2] + a[0][3];
00638     r[1] = a[1][0]*b[0] + a[1][1]*b[1] + a[1][2]*b[2] + a[1][3];
00639     r[2] = a[2][0]*b[0] + a[2][1]*b[1] + a[2][2]*b[2] + a[2][3];
00640     return r;
00641 }
00642 #ifdef _WIN32
00643  #pragma warning (default: 4700)
00644 #endif
00645 
00646 /// float版2次元アフィン行列.
00647 typedef TAffine2<float> Affine2f;
00648 /// double版2次元アフィン行列.
00649 typedef TAffine2<double> Affine2d;
00650 /// float版3次元アフィン行列.
00651 typedef TAffine<float> Affinef;
00652 /// double版3次元アフィン行列.
00653 typedef TAffine<double> Affined;
00654 //@}
00655 
00656 #ifdef _WIN32
00657  #ifdef _DEBUG
00658   #pragma optimize ("", on)
00659   #pragma auto_inline(off)
00660   #pragma inline_recursion(off)
00661  #endif
00662 #endif
00663 
00664 #ifndef PTM_PACK    //  単体で使用する場合は,namespace に入れない
00665 }   //  namespace Spr
00666 #endif
00667 
00668 #endif

Springheadに対してSun Apr 16 01:57:49 2006に生成されました。  doxygen 1.4.1