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

SGFrame.h

00001 #ifndef SG_FRAME_H
00002 #define SG_FRAME_H
00003 
00004 #include "SGObject.h"
00005 
00006 namespace Spr {;
00007 /// バウンディングボックスの実装
00008 class SGBBox{
00009     Vec3f bboxCenter;   ///<    BBoxの中心(ローカル系)
00010     Vec3f bboxExtent;   ///<    BBoxの大きさ(ローカル系)
00011 public:
00012     /// バウンディングボックスの設定
00013     void SetBBoxCenterExtent(Vec3f c, Vec3f e){
00014         bboxCenter = c;
00015         bboxExtent = e;
00016     }
00017     /// バウンディングボックスの設定
00018     void SetBBoxMinMax(Vec3f bmin, Vec3f bmax){
00019         bboxCenter = (bmin+bmax)*0.5f;
00020         bboxExtent = (bmax-bmin)*0.5f;
00021     }
00022     /// バウンディングボックスの追加
00023     void AddBBox(Vec3f bmin, Vec3f bmax){
00024         Vec3f bboxMin = GetBBoxMin();
00025         Vec3f bboxMax = GetBBoxMax();
00026         bboxMin.element_min(bmin);
00027         bboxMax.element_max(bmax);
00028         SetBBoxMinMax(bboxMin, bboxMax);
00029     }
00030     /// 中心
00031     Vec3f GetBBoxCenter(){ return bboxCenter; }
00032     /// 大きさ
00033     Vec3f GetBBoxExtent(){ return bboxExtent; }
00034     /// 小さい端点
00035     Vec3f GetBBoxMin(){ return bboxCenter-bboxExtent; }
00036     /// 大きい端点
00037     Vec3f GetBBoxMax(){ return bboxCenter+bboxExtent; }
00038     /// 与えられたベクトルとの内積が最大と最小の点
00039     void GetSupport(const Vec3f& dir, float& minS, float& maxS){
00040         Vec3f ext0( bboxExtent.X(),  bboxExtent.Y(),  bboxExtent.Z());
00041         Vec3f ext1(-bboxExtent.X(),  bboxExtent.Y(),  bboxExtent.Z());
00042         Vec3f ext2( bboxExtent.X(), -bboxExtent.Y(),  bboxExtent.Z());
00043         Vec3f ext3( bboxExtent.X(),  bboxExtent.Y(), -bboxExtent.Z());
00044         float d = abs(dir*ext0);
00045         float d1 = abs(dir*ext1);
00046         if (d < d1) d = d1;
00047         float d2 = abs(dir*ext2);
00048         if (d < d2) d = d2;
00049         float d3 = abs(dir*ext3);
00050         if (d < d3) d = d3;
00051         float c = dir * bboxCenter;
00052         minS = c-d;
00053         maxS = c+d;
00054     }
00055 };
00056 
00057 class SGFrame;
00058 /// Spr::Frame の配列.
00059 class SPR_DLL SGFrames:public std::vector< UTRef<SGFrame> >{
00060 public:
00061 };
00062 
00063 /** シーングラフのインタフェースノード.
00064     シーングラフの操作を受け付けるノード.位置姿勢を保持する.
00065     他のデータのポインタを保持する.    */
00066 class SPR_DLL SGFrame: public SGObject, public UTTreeNode<SGFrame, SGFrames>{
00067 public:
00068     SGOBJECTDEF(SGFrame);
00069     typedef UTTreeNode<SGFrame, SGFrames> Tree;
00070 protected:
00071     /// 姿勢
00072     Affinef posture;
00073 public:
00074     /// バウンディングボックス
00075     SGBBox bbox;
00076     /// フレームの中身(子フレームは含まない)
00077     SGObjects contents;
00078 
00079     ///@name シーングラフ構造の操作
00080     //@{
00081     /// 所有しているオブジェクトの数
00082     virtual size_t NChildObjects();
00083     /// 所有しているオブジェクト
00084     virtual SGObject* ChildObject(size_t i);
00085     /// 子オブジェクトの追加
00086     virtual bool AddChildObject(SGObject* o, SGScene* s);
00087     /// 子オブジェクトの削除
00088     virtual bool DelChildObject(SGObject* o, SGScene* s);
00089 
00090     virtual SGFrame* FindFrame(UTString);
00091 
00092     /// 子になりえるオブジェクトの型情報の配列
00093     virtual const UTTypeInfo** ChildCandidates();
00094     template <class T>
00095     void FindObject(T*& obj){
00096         for(unsigned i=0; i<NChildObjects(); ++i){
00097             obj = DCAST(T, ChildObject(i));
00098             if (obj) return;
00099         }
00100     }
00101     template <class T> void FindObject(UTRef<T>& obj){
00102         T* t = &*obj;
00103         FindObject(t);
00104         obj = t;
00105     }
00106 
00107 
00108     /// 子ノードなどをすべて消去する.
00109     void Clear();
00110     
00111     /// 関連付けられたdocを開放
00112     virtual void ReleaseDoc(){
00113         doc = NULL;
00114         ForEachChild(&SGFrame::ReleaseDoc);
00115         for(SGObjects::iterator it = contents.begin(); it != contents.end(); ++it){
00116             (*it)->ReleaseDoc();
00117         }
00118     }
00119     /// ノードのダンプ表示
00120     void Print(std::ostream& os) const;
00121     //@}
00122     
00123     ///@name 姿勢(位置,向き)
00124     //@{
00125     const Vec3f& GetPosition(){ return posture.Pos(); }
00126     Matrix3f GetRotation(){ return posture.Rot(); }
00127     template<class T> void SetPosition(T p){ posture.Pos() = p; }
00128     template<class T> void SetRotation(T p){ posture.Rot() = p; }
00129     /// 親ノードに対する姿勢(位置と回転をあらわす4x4行列)を返す.
00130     const Affinef& GetPosture(){ return posture;}
00131     /** 親ノードに対する姿勢(位置と回転をあらわす4x4行列)を設定する.
00132         PHSolidを使っているときは,SGFrame::SetPosture()は使ってはならない.
00133         毎回,Solidが姿勢を上書きしてしまうので. */
00134     void SetPosture(const Affinef& a){ posture = a; }
00135     /// ワールド座標系に対する姿勢(位置と回転をあらわす4x4行列)を返す.
00136     Affinef GetWorldPosture(){
00137         Affinef af;
00138         SGFrame* fr = this;
00139         while(fr){
00140             af = fr->posture * af;
00141             fr = fr->GetParent();
00142         }
00143         return af;
00144     }
00145     /** ワールド座標系に対する姿勢(位置と回転をあらわす4x4行列)を設定する.
00146         PHSolidを使っているときは,SGFrame::SetPosture()は使ってはならない.
00147         毎回,Solidが姿勢を上書きしてしまうので. */
00148     void SetWorldPosture(const Affinef& a){
00149         if (GetParent()){
00150             posture = GetParent()->GetWorldPosture().inv() * a;
00151         }else{
00152             posture = a;
00153         }
00154     }
00155     /// バウンディングボックスの計算
00156     virtual void CalcBBox();
00157     /// バウンディングボックスの両端の取得
00158     void GetBBoxSupport(const Vec3f& dir, float& minS, float& maxS){
00159         bbox.GetSupport(GetPosture().Rot().inv()*dir, minS, maxS);
00160         float c = GetPosture().Pos() * dir;
00161         minS += c;
00162         maxS += c;
00163     }
00164     //@}
00165     /// ロード後,参照の解決が終わってから呼び出す関数.
00166     void Loaded(SGScene* scene);
00167 
00168     /// 子フレームを含めて,すべてのContactsを列挙する
00169     void EnumContents(SGObjects& objs);
00170     void EnumContents(SGObjects& objs, SGFrames& frames);
00171 };
00172 
00173 }
00174 #endif

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