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

PHWater.h

00001 #ifndef PHWATER_H
00002 #define PHWATER_H
00003 
00004 #include <Base/Affine.h>
00005 #include <FileIO/FIDocScene.h>
00006 #include <SceneGraph/SGScene.h>
00007 #include <Graphics/GRVisual.h>
00008 #include <Physics/PHSolid.h>
00009 #include <Collision/CDGeometry.h>
00010 
00011 using namespace PTM;
00012 namespace Spr{;
00013 
00014 /*
00015     ・設計によってはWaterContainerという命名が適当かも
00016     ・PHWaterClearForceの対象はSolidに限らず力が加わるもの全般なので、
00017         PHClearForceとすべき
00018 
00019     PHWaterの座標の取り方:
00020     ・Z軸は静水面に直交し、上向き.
00021     ・格子はx軸方向に格子数mx + 1,幅mx * dh,y軸方向に格子数my + 1,幅my + dh.
00022     ・座標原点は格子の中央.
00023     ・今のところ水深depthはスカラ定数だがheightと同じく格子ごとに異なる値をとるように拡張したい
00024 */
00025 
00026 class D3Mesh;
00027 class GLMesh;
00028 class GRMaterial;
00029 class D3Material;
00030 class D3Render;
00031 class GLRender;
00032 
00033 class PHWaterTrackTarget : public SGObject{
00034 public:
00035     SGOBJECTDEF(PHWaterTrackTarget);
00036 
00037     bool        AddChildObject(SGObject* o, SGScene* s);
00038     size_t      NReferenceObjects(){return targets.size();}
00039     SGObject*   ReferenceObject(size_t i){return targets[i];}
00040 
00041     SGFrames targets;
00042 };
00043 #if 0
00044 class PHWFRM : public UTRefCount{
00045 public:
00046     class ForceSet{
00047     public:
00048         
00049     };
00050 public:
00051     int id;
00052     float buo_scl, pres_scl, fric_scl, vel_scl, unit_mass, disp_scl;
00053     float wz, wa;
00054     float dlen;
00055     Affinef posture;
00056     float v0;
00057     FIString    filename;
00058     Vec3f   d, s;
00059 
00060     float dthe, dphi;
00061     int nhsrc, ndata;
00062     float rate;
00063     int nthe, nphi, ntex, sym[3], n;
00064     vector<ForceSet> frc_set;
00065 
00066     bool Load(FIString);
00067 };
00068 #endif
00069 class PHWater : public GRVisual{
00070 public:
00071     SGOBJECTDEF(PHWater);
00072     bool        AddChildObject(SGObject* o, SGScene* s);///< ロード時に使用.
00073     size_t      NReferenceObjects();                    ///< 
00074     SGObject*   ReferenceObject(size_t i);              ///< フレームを返す.
00075     void        Loaded(SGScene* scene);                 ///< ロード終了時の初期化
00076     void        Step(SGScene* s);                       ///< 時刻を進める.
00077     Affinef     GetPosture(){ return frame->GetWorldPosture(); }
00078     float edgeWidth;                                    ///< 描画時に付けるふちの幅
00079 
00080     /// レンダリング
00081     virtual void Render(SGFrame* fr, GRRender* render);
00082     void CalcNormal();
00083 
00084     ///力をクリアする
00085     void ClearForce(){}
00086 
00087     ///格子中間の値を線形補完して返す
00088     double LerpHeight(double x, double y);
00089 /*
00090     double LerpVelocityU(double x, double y);
00091     double LerpVelocityV(double x, double y);
00092     Vec2f LerpVelocity(double x, double y){
00093         return Vec2f(LerpVelocityU(x,y), LerpVelocityV(x,y));
00094     }
00095 */
00096     //パラメータ
00097     UTRef<SGFrame> frame;   //  親フレーム
00098     int     my, mx;         //分割数
00099     TVec2<int> bound;       //境界 このセルと次のセルが境界のセルになる.
00100     TVec2<int> texOffset;   //bound と同じだが,%mx しない.
00101     Vec2d   velocity;       //定常流速.定常的にこの速度で水が流れる.
00102     double  dh, dhinv;      //格子の幅
00103     double  depth;          //水深
00104     double  gravity;        //重力
00105     double  density;        //密度
00106     double  loss;           //損失係数
00107 
00108     PHWater();
00109     friend class PHWaterContactEngine;
00110     friend struct PHWConvexCalc;
00111 
00112 //protected:
00113     typedef VMatrixCol<double> matrix_type;
00114     typedef VMatrixCol<Vec3d>   v3matrix_type;
00115     typedef VVector<double> vector_type;
00116 
00117     //追従対象
00118     UTRef<PHWaterTrackTarget> targets;
00119 
00120     UTRef<GRMaterial> material;
00121     UTRef<D3Material> materialD3;
00122 
00123     int             mxy;    //mx * my
00124     double          rx;     //mx * dh / 2.0
00125     double          ry;     //my * dh / 2.0
00126     
00127     matrix_type     p;              //圧力
00128     matrix_type     u, utmp;        //x方向流速
00129     matrix_type     v, vtmp;        //y方向流速
00130     matrix_type     height, htmp;   //高さ
00131     v3matrix_type   normal;         //法線
00132     v3matrix_type   tvec;           //
00133     Vec3d           vlight;         //光の向き
00134 
00135     ///初期化処理
00136     void Init(SGScene* scene);
00137 
00138     ///境界条件を設定する
00139     void Bound();
00140 
00141     ///積分する
00142     void Integrate(double dt);
00143 
00144     ///屈折ベクトルの計算
00145     Vec3d calRefracVec(Vec3d n, Vec3d v, double ra);
00146 
00147     void RenderD3(SGFrame* fr, D3Render* render);
00148     void RenderGL(SGFrame* fr, GLRender* render);
00149     DWORD GetColor(float h);
00150 };
00151 class CDWater: public CDGeometry{
00152 public:
00153     SGOBJECTDEF(CDWater);
00154     UTRef<PHWater> water;
00155     virtual void CalcBBox(Vec3f& bbMin, Vec3f& bbMax);
00156     virtual int GeometryID();
00157 };
00158 
00159 typedef UTRefArray<PHWater> PHWaters;
00160 
00161 class PHWaterEngine : public /*SGBehaviorEngine*/PHSolverBase{
00162 public:
00163     SGOBJECTDEF(PHWaterEngine);
00164 
00165     PHWaters waters;
00166     
00167     bool AddChildObject(SGObject* o, SGScene* s);
00168     bool DelChildObject(SGObject* o, SGScene* s);
00169     int GetPriority() const {return SGBP_DYNAMICALSYSTEM;}
00170     virtual void Step(SGScene* s);
00171     virtual void ClearForce();
00172     virtual void Loaded(SGScene* scene);
00173     virtual void Clear(SGScene* s);
00174     virtual size_t NChildObjects(){ return waters.size(); }
00175     virtual SGObject* ChildObject(size_t i){ return (SGObject*)&*(waters[i]); }
00176 
00177     /// 状態の読み出し
00178     virtual void LoadState(const SGBehaviorStates& states);
00179     /// 状態の保存
00180     virtual void SaveState(SGBehaviorStates& states) const;
00181 };
00182 
00183 }
00184 
00185 #endif

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