| 1 | /*! | 
|---|
| 2 |  * @file mapped_water.h | 
|---|
| 3 |  *  worldentity for flat, cool looking, mapped water | 
|---|
| 4 | */ | 
|---|
| 5 | /*! example input in .oxw file with the standard values | 
|---|
| 6 | <MappedWater> | 
|---|
| 7 |   <waterpos>0,0,0</waterpos> | 
|---|
| 8 |   <watersize>100,100</watersize> | 
|---|
| 9 |   <wateruv>9</wateruv><!-- size of the waves --> | 
|---|
| 10 |   <waterflow>0.08</waterflow> | 
|---|
| 11 |   <lightpos>0,10,0</lightpos> | 
|---|
| 12 |   <waterangle>0</waterangle> | 
|---|
| 13 |   <normalmapscale>0.25</normalmapscale><!-- you won't see a big differnce if you change that --> | 
|---|
| 14 |   <shininess>128</shininess><!-- the bigger the value, the smaller the specular reflection point --> | 
|---|
| 15 |   <watercolor>0.1, 0.2, 0.4</watercolor> | 
|---|
| 16 | </MappedWater> | 
|---|
| 17 | */ | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef _MAPPED_WATER_H | 
|---|
| 21 | #define _MAPPED_WATER_H | 
|---|
| 22 |  | 
|---|
| 23 | #include "world_entity.h" | 
|---|
| 24 | #include "material.h" | 
|---|
| 25 | #include "shader.h" | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | class MappedWater : public WorldEntity | 
|---|
| 29 | { | 
|---|
| 30 | public: | 
|---|
| 31 |   MappedWater(const TiXmlElement* root = NULL); | 
|---|
| 32 |   virtual ~MappedWater(); | 
|---|
| 33 |  | 
|---|
| 34 |   void loadParams(const TiXmlElement* root); | 
|---|
| 35 |  | 
|---|
| 36 |   void draw() const; | 
|---|
| 37 |   void tick(float dt); | 
|---|
| 38 |  | 
|---|
| 39 |   // function to prepare renderpaths for creation of refleaction and reflaction textures | 
|---|
| 40 |   void activateReflection(); | 
|---|
| 41 |   void deactivateReflection(); | 
|---|
| 42 |   void activateRefraction(); | 
|---|
| 43 |   void deactivateRefraction(); | 
|---|
| 44 |  | 
|---|
| 45 |   // functions to set parameters for the water, usually they're called through loadparam | 
|---|
| 46 |   void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); }; | 
|---|
| 47 |   void setWaterPos(float x, float y, float z) { this->waterPos = Vector(x,y,z); }; | 
|---|
| 48 |   void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; }; | 
|---|
| 49 |   void setWaterAngle(float angle) { this->waterAngle = angle; }; | 
|---|
| 50 |   void setWaterUV(float uv) { this->waterUV = uv; }; | 
|---|
| 51 |   void setWaterFlow(float flow) { this->waterFlow = flow; }; | 
|---|
| 52 |   void setNormalMapScale(float scale) { this->kNormalMapScale = scale; }; | 
|---|
| 53 |   void setShininess(float shine) { this->shininess = shine; }; | 
|---|
| 54 |   void setWaterColor(float r, float g, float b) { this->waterColor = Vector(r,g,b); }; | 
|---|
| 55 |  | 
|---|
| 56 |   // functions to change water parameters during runtime | 
|---|
| 57 |   // to reset waterUV and waterFlow just use the normal set functions | 
|---|
| 58 |   void resetWaterColor(float r, float g, float b); | 
|---|
| 59 |   void resetShininess(float shine); | 
|---|
| 60 |   void resetLightPos(float x, float y, float z); | 
|---|
| 61 |  | 
|---|
| 62 |   // fade functions | 
|---|
| 63 |   void fadeWaterColor(float r, float g, float b, float time); | 
|---|
| 64 |   void fadeShininess(float shine, float time); | 
|---|
| 65 |   void fadeLightPos(float x, float y, float z, float time); | 
|---|
| 66 |  | 
|---|
| 67 | private: | 
|---|
| 68 |   void initParams(); | 
|---|
| 69 |   void initTextures(); | 
|---|
| 70 |   void initShaders(); | 
|---|
| 71 |  | 
|---|
| 72 | private: | 
|---|
| 73 |   Vector              waterPos;               //!< position of the water | 
|---|
| 74 |   float               xWidth, zWidth;         //!< size of the water quad | 
|---|
| 75 |   Vector              lightPos;               //!< position of the light that is used to render the reflection | 
|---|
| 76 |   float               waterAngle;             //!< defines how much the water will be turned around the point waterPos | 
|---|
| 77 |   Vector              waterColor;             //!< color of the water | 
|---|
| 78 |   float               move;                   //!< textures coords, speeds, positions for the shaded textures.... | 
|---|
| 79 |   float               move2; | 
|---|
| 80 |   float               waterUV;                //!< size of the waves | 
|---|
| 81 |   float               waterFlow;              //!< speed of the water | 
|---|
| 82 |   float               normalUV; | 
|---|
| 83 |   float               kNormalMapScale; | 
|---|
| 84 |   float               shininess;              //!< the bigger the value, the smaller the specular reflection point | 
|---|
| 85 |  | 
|---|
| 86 |   int                 textureSize;            //!< height and width of the texture | 
|---|
| 87 |   Material            mat; | 
|---|
| 88 |   Shader*             shader; | 
|---|
| 89 |   Shader::Uniform*    cam_uni;                //!< uniform that is used for the camera position | 
|---|
| 90 |   Shader::Uniform*    light_uni;              //!< uniform that is used for the light position | 
|---|
| 91 |   Shader::Uniform*    color_uni;              //!< uniform that is used for the watercolor | 
|---|
| 92 |   Shader::Uniform*    shine_uni;              //!< uniform that is used for the specular shininessd of the water | 
|---|
| 93 |    | 
|---|
| 94 |    | 
|---|
| 95 |   int tempcounter; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | #endif | 
|---|