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
00016
00017
00018
00019
00020
00021
00022
00023
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
00091
00092
00093
00094
00095
00096
00097 UTRef<SGFrame> frame;
00098 int my, mx;
00099 TVec2<int> bound;
00100 TVec2<int> texOffset;
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
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;
00124 double rx;
00125 double ry;
00126
00127 matrix_type p;
00128 matrix_type u, utmp;
00129 matrix_type v, vtmp;
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 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