00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_WATER_SHAPE_H
00027 #define NL_WATER_SHAPE_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/misc/aabbox.h"
00032 #include "nel/misc/class_id.h"
00033 #include "nel/misc/vector_2f.h"
00034 #include "nel/misc/polygon.h"
00035 #include "3d/track.h"
00036 #include "nel/3d/animation_time.h"
00037
00038
00039
00040
00041
00042
00043
00044 #include "3d/shape.h"
00045 #include "3d/vertex_buffer.h"
00046 #include "3d/driver.h"
00047
00048 #include <memory>
00049
00050 namespace NL3D {
00051
00052
00053 const CVertexBuffer::TValue WATER_VB_POS = CVertexBuffer::Position;
00054 const CVertexBuffer::TValue WATER_VB_DX = CVertexBuffer::TexCoord0;
00055
00056
00057
00058
00059 const NLMISC::CClassId WaterModelClassId = NLMISC::CClassId(0x41a0732e, 0x6c664506);
00060
00061
00062 const NLMISC::CClassId WaveMakerModelClassId = NLMISC::CClassId(0x16da3356, 0x7dec65fd);
00063
00079 class CWaterShape : public IShape
00080 {
00081 public:
00082 NLMISC_DECLARE_CLASS(CWaterShape);
00083
00085
00086
00087 CWaterShape();
00088
00090 ~CWaterShape();
00091
00092
00094 void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00096
00097
00099 virtual CTransformShape *createInstance(CScene &scene);
00100
00102 virtual bool clip(const std::vector<CPlane> &pyramid, const CMatrix &worldMatrix);
00103
00105 virtual void render(IDriver *drv, CTransformShape *trans, bool opaquePass) {}
00106
00108 virtual void getAABBox(NLMISC::CAABBox &bbox) const { bbox = _BBox; }
00109
00111 virtual float getNumTriangles (float distance);
00112
00114 virtual void flushTextures (IDriver &driver);
00115
00116
00118
00119
00120 void setWaterPoolID(uint32 id) { _WaterPoolID = id; }
00121 uint32 getWaterPoolID() const { return _WaterPoolID; }
00123 static void setScreenGridSize(uint32 x, uint32 y);
00125 static void setGridBorderSize(uint32 x, uint32 y);
00126 static uint32 getScreenXGridSize() { return _XScreenGridSize; }
00127 static uint32 getScreenYGridSize() { return _YScreenGridSize; }
00128 static uint32 getXGridBorder() { return _XGridBorder; }
00129 static uint32 getYGridBorder() { return _YGridBorder; }
00130
00131
00132
00133 void setShape(const NLMISC::CPolygon2D &poly);
00134
00136 const NLMISC::CPolygon2D &getShape() const { return _Poly; }
00137
00139 void getShapeInWorldSpace(NLMISC::CPolygon &poly) const;
00140
00142 void setWaveHeightFactor(float f) { _WaveHeightFactor = f; }
00143
00145 float getWaveHeightFactor() const { return _WaveHeightFactor; }
00146
00148
00149
00151
00152
00153 void setEnvMap(uint index, ITexture *envMap);
00154 ITexture *getEnvMap(uint index) { nlassert(index < 2); return (ITexture *) _EnvMap[index];}
00155 const ITexture *getEnvMap(uint index) const { nlassert(index < 2); return (const ITexture *) _EnvMap[index];}
00156
00160 void setHeightMap(uint k, ITexture *hm);
00161 ITexture *getHeightMap(uint k);
00162 const ITexture *getHeightMap(uint k) const;
00163 void setHeightMapScale(uint k, const NLMISC::CVector2f &scale);
00164 NLMISC::CVector2f getHeightMapScale(uint k) const;
00165 void setHeightMapSpeed(uint k, const NLMISC::CVector2f &speed);
00166 NLMISC::CVector2f getHeightMapSpeed(uint k) const;
00167
00168
00169
00170
00171 void setColorMap(ITexture *map);
00172 ITexture *getColorMap() { return _ColorMap; }
00173 const ITexture *getColorMap() const { return _ColorMap; }
00174
00175 void setColorMapMat(const NLMISC::CVector2f &column0, const NLMISC::CVector2f &column1, const NLMISC::CVector2f &pos);
00176 void getColorMapMat(NLMISC::CVector2f &column0, NLMISC::CVector2f &column1, NLMISC::CVector2f &pos);
00178
00180
00181 void setTransitionRatio(float percent) { _TransitionRatio = percent; }
00182 float getTransitionRatio() const { return _TransitionRatio; }
00184
00186
00187 CTrackDefaultVector* getDefaultPos () {return &_DefaultPos;}
00188 CTrackDefaultVector* getDefaultScale () {return &_DefaultScale;}
00189 CTrackDefaultQuat* getDefaultRotQuat () {return &_DefaultRotQuat;}
00190
00191
00192
00194
00196
00197 bool isLightMappingEnabled() const { return _ComputeLightmap; }
00198
00199 private:
00200 friend class CWaterModel;
00201 friend class CWaterRenderObs;
00202 void computeBBox();
00203 void envMapUpdate();
00204 void updateHeightMapNormalizationFactors();
00205 static void initVertexProgram();
00206 static void setupVertexBuffer();
00207 private:
00208 NLMISC::CAABBox _BBox;
00209 NLMISC::CPolygon2D _Poly;
00210 uint32 _WaterPoolID;
00211 NLMISC::CSmartPtr<ITexture> _EnvMap[2];
00212 NLMISC::CSmartPtr<ITexture> _BumpMap[2];
00213 NLMISC::CSmartPtr<ITexture> _ColorMap;
00214
00215 NLMISC::CVector2f _HeightMapScale[2];
00216 NLMISC::CVector2f _HeightMapSpeed[2];
00217 NLMISC::CVector2f _ColorMapMatColumn0, _ColorMapMatColumn1, _ColorMapMatPos;
00218
00219 CTrackDefaultVector _DefaultPos;
00220 CTrackDefaultVector _DefaultScale;
00221 CTrackDefaultQuat _DefaultRotQuat;
00222 float _TransitionRatio;
00223 float _WaveHeightFactor;
00224 bool _ComputeLightmap;
00225 bool _HeightMapTouch[2];
00226 float _HeightMapNormalizationFactor[2];
00227
00228 static uint32 _XScreenGridSize;
00229 static uint32 _YScreenGridSize;
00230 static uint32 _MaxGridSize;
00231 static uint32 _XGridBorder;
00232 static uint32 _YGridBorder;
00233
00234 static CVertexBuffer _VB;
00235 static std::vector<uint32> _IBUpDown;
00236 static std::vector<uint32> _IBDownUp;
00237 static bool _GridSizeTouched;
00238
00239 static std::auto_ptr<CVertexProgram> _VertexProgramBump1;
00240 static std::auto_ptr<CVertexProgram> _VertexProgramBump2;
00241
00242 static std::auto_ptr<CVertexProgram> _VertexProgramBump1Diffuse;
00243 static std::auto_ptr<CVertexProgram> _VertexProgramBump2Diffuse;
00244
00245 static std::auto_ptr<CVertexProgram> _VertexProgramNoBump;
00246 static std::auto_ptr<CVertexProgram> _VertexProgramNoBumpDiffuse;
00247 };
00248
00249
00251 class CWaveMakerShape : public IShape
00252 {
00253 public:
00254 NLMISC_DECLARE_CLASS(CWaveMakerShape);
00256
00257
00258 CWaveMakerShape();
00259
00261 ~CWaveMakerShape();
00262
00263
00265 void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00267
00268
00270 virtual CTransformShape *createInstance(CScene &scene);
00271
00273 virtual bool clip(const std::vector<CPlane> &pyramid, const CMatrix &worldMatrix);
00274
00276 virtual void render(IDriver *drv, CTransformShape *trans, bool opaquePass) {}
00277
00279 virtual void getAABBox(NLMISC::CAABBox &bbox) const;
00280
00282 virtual float getNumTriangles (float distance) { return 0; }
00283
00285 virtual void flushTextures (IDriver &driver) {}
00286
00287
00289 void setPeriod(TAnimationTime period) { _Period = period; }
00290 TAnimationTime getPeriod() const { return _Period; }
00291
00293 void setIntensity(float intensity) { _Intensity = intensity; }
00294 float getIntensity() const { return _Intensity; }
00295
00297 void setRadius(float radius) { _Radius = radius; }
00298 float getRadius() const { return _Radius; }
00299
00301 void setWaterPoolID(uint32 id) { _PoolID = id; }
00302 uint32 getWaterPoolID() const { return _PoolID; }
00303
00305 void setImpulsionMode(bool on = true) { _ImpulsionMode = on; }
00306 bool getImpulsionMode() const { return _ImpulsionMode; }
00307
00308 CTrackDefaultVector* getDefaultPos () {return &_DefaultPos;}
00309 private:
00310 friend class CWaveMakerDetailObs;
00311 TAnimationTime _Period;
00312 float _Radius;
00313 uint32 _PoolID;
00314 float _Intensity;
00315 bool _ImpulsionMode;
00316 CTrackDefaultVector _DefaultPos;
00317 };
00318
00319
00320 }
00321
00322
00323 #endif // NL_WATER_SHAPE_H
00324
00325