Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/environments/mapped_water.h @ 9067

Last change on this file since 9067 was 9021, checked in by bensch, 18 years ago

orxonox/trunk: GUI: mapped water can no be edited with the mouse

File size: 8.8 KB
Line 
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  <shinesize>128</shinesize><!-- the bigger the value, the smaller the specular reflection point -->
15  <shinestrength>0.7</shinestrength>
16  <reflstrength>1</reflstrength>
17  <refraction>0.009</refraction>
18  <watercolor>0.1, 0.2, 0.4</watercolor>
19</MappedWater>
20*/
21
22
23#ifndef _MAPPED_WATER_H
24#define _MAPPED_WATER_H
25
26#include "world_entity.h"
27#include "material.h"
28#include "shader.h"
29
30namespace OrxGui { class GLGuiBox; };
31
32// forward declaration
33template <class T> class tAnimation;
34
35class MappedWater : public WorldEntity
36{
37public:
38  MappedWater(const TiXmlElement* root = NULL);
39  virtual ~MappedWater();
40
41  // worldentity functions
42  void loadParams(const TiXmlElement* root);
43  void saveParams();
44  void draw() const;
45  void tick(float dt);
46
47  // function to prepare renderpaths for creation of refleaction and reflaction textures
48  void activateReflection();
49  void deactivateReflection();
50  void activateRefraction();
51  void deactivateRefraction();
52
53  // slider gui to edit water params during gameplay
54  void toggleGui();
55
56  // functions to set parameters for the water, usually they're called through loadparam
57  void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); }
58  void setWaterPos(float x, float y, float z) { this->waterHeight = y; this->waterVerts[0] = x; this->waterVerts[1] = z; }
59  void setWaterHeight(float y) { this->waterHeight = y;  }
60  void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; }
61  void setWaterAngle(float angle) { this->waterAngle = angle; }
62  void setWaterColor(float r, float g, float b) { this->waterColor = Vector(r,g,b); }
63  void setWaterUV(float uv) { this->waterUV = uv; }
64  void setWaterFlow(float flow) { this->waterFlow = flow; }
65  void setNormalMapScale(float scale) { this->kNormalMapScale = scale; }
66  void setShineSize(float shine) { this->shineSize = shine; }
67  void setShineStrength(float strength) { this->shineStrength = strength; }
68  void setReflStrength(float strength) { this->reflStrength = strength; }
69  void setRefraction(float refraction) { this->refraction = refraction; }
70
71  // functions to change water parameters during runtime
72  // to reset waterUV and waterFlow just use the normal set functions
73  // don't reset kNormalMapScale (because it won't change anything)
74  void resetLightPos(float x, float y, float z);
75  void resetLightPosX(float x) { this->resetLightPos(x, this->lightPos.y, this->lightPos.z); }
76  void resetLightPosY(float y) { this->resetLightPos(this->lightPos.x, y, this->lightPos.z); }
77  void resetLightPosZ(float z) { this->resetLightPos(this->lightPos.x, this->lightPos.y, z); }
78  void resetWaterPos(float x, float y, float z) { this->setWaterPos(x, y, z); this->calcVerts(); }
79  void resetWaterSize(float x, float z) { this->setWaterSize(x, z); this->calcVerts(); }
80  void resetWaterAngle(float angle) { this->setWaterAngle(angle); this->calcVerts(); }
81  void resetWaterColor(float r, float g, float b);
82  void resetWaterColorR(float r) { this->resetWaterColor(r, this->waterColor.y, this->waterColor.z); }
83  void resetWaterColorG(float g) { this->resetWaterColor(this->waterColor.x, g, this->waterColor.z); }
84  void resetWaterColorB(float b) { this->resetWaterColor(this->waterColor.x, this->waterColor.y, b); }
85  void resetShineSize(float shine);
86  void resetShineStrength(float strength);
87  void resetReflStrength(float strength);
88  void resetRefraction(float refraction);
89
90  // fading functions
91  void fadeWaterUV(float uv, float time) { this->newWaterUV = uv; this->waterUVFadeTime = time; this->bFadeWaterUV = true; }
92  void fadeWaterFlow(float flow, float time) { this->newWaterFlow = flow; this->waterFlowFadeTime = time; this->bFadeWaterFlow = true; }
93  void fadeShineSize(float shine, float time) { this->newShineSize = shine; this->shineSizeFadeTime = time; this->bFadeShineSize = true; }
94  void fadeShineStrength(float strength, float time) { this->newShineStrength = strength; this->shineStrengthFadeTime = time; this->bFadeShineStrength = true; }
95  void fadeReflStrength(float strength, float time) { this->newReflStrength = strength; this->reflStrengthFadeTime = time; this->bFadeReflStrength = true; }
96  void fadeRefraction(float refraction, float time) { this->newRefraction = refraction; this->refractionFadeTime = time; this->bFadeRefraction = true; }
97  void fadeWaterHeight(float y, float time) { this->newWaterHeight = y; this->waterHeightFadeTime = time; this->bFadeWaterHeight = true; }
98  void fadeWaterColor(float r, float g, float b, float time) { this->newWaterColor = Vector(r, g, b); this->waterColorFadeTime = time; this->bFadeWaterColor = true; }
99
100private:
101  void initParams();
102  void initTextures();
103  void initShaders();
104  void calcVerts();
105
106private:
107  Material                  mat;
108  Shader*                   shader;
109  OrxGui::GLGuiBox*         box;
110
111  // water size and position
112  float                     waterHeight;            //!< position of the water
113  float                     waterVerts[8];          //!< coords of the 4 vertexes of the water quad
114  float                     xWidth, zWidth;         //!< size of the water quad
115  float                     waterAngle;             //!< defines how much the water will be turned around the point waterPos
116
117  // values for texture size, scale, texture coords
118  float                     move;
119  float                     move2;
120  float                     waterUV;                //!< size of the waves
121  float                     waterFlow;              //!< speed of the water
122  float                     normalUV;
123  float                     kNormalMapScale;
124  int                       textureSize;            //!< height and width of the texture
125
126  // values for the uniforms
127  Vector                    waterColor;             //!< color of the water
128  Vector                    lightPos;               //!< position of the light that is used to render the reflection
129  float                     shineSize;              //!< the bigger the value, the smaller the specular reflection point
130  float                     shineStrength;
131  float                     reflStrength;
132  float                     refraction;
133
134  // uniforms
135  Shader::Uniform*          cam_uni;                //!< uniform that is used for the camera position
136  Shader::Uniform*          light_uni;              //!< uniform that is used for the light position
137  Shader::Uniform*          color_uni;              //!< uniform that is used for the watercolor
138  Shader::Uniform*          shineSize_uni;          //!< uniform that is used for the specular shininessd of the water
139  Shader::Uniform*          shineStrength_uni;      //!< uniform that is used for the strenght of the specular reflection
140  Shader::Uniform*          reflStrength_uni;       //!< uniform that is used for the strength of the reflection
141  Shader::Uniform*          refr_uni;               //!< uniform that is used for the strength of the refraction
142
143  // fading TODO fix this so it isnt so hacky anymore
144  tAnimation<MappedWater>*  waterUVFader;
145  float                     newWaterUV;
146  float                     waterUVFadeTime;
147  bool                      bFadeWaterUV ;
148  tAnimation<MappedWater>*  waterFlowFader;
149  float                     newWaterFlow;
150  float                     waterFlowFadeTime;
151  bool                      bFadeWaterFlow;
152  tAnimation<MappedWater>*  shineSizeFader;
153  float                     newShineSize;
154  float                     shineSizeFadeTime;
155  bool                      bFadeShineSize;
156  tAnimation<MappedWater>*  shineStrengthFader;
157  float                     newShineStrength;
158  float                     shineStrengthFadeTime;
159  bool                      bFadeShineStrength;
160  tAnimation<MappedWater>*  reflStrengthFader;
161  float                     newReflStrength;
162  float                     reflStrengthFadeTime;
163  bool                      bFadeReflStrength;
164  tAnimation<MappedWater>*  refractionFader;
165  float                     newRefraction;
166  float                     refractionFadeTime;
167  bool                      bFadeRefraction;
168  tAnimation<MappedWater>*  waterHeightFader;
169  float                     newWaterHeight;
170  float                     waterHeightFadeTime;
171  bool                      bFadeWaterHeight;
172  tAnimation<MappedWater>*  waterColorRFader;
173  tAnimation<MappedWater>*  waterColorGFader;
174  tAnimation<MappedWater>*  waterColorBFader;
175  Vector                    newWaterColor;
176  float                     waterColorFadeTime;
177  bool                      bFadeWaterColor;
178};
179
180#endif
Note: See TracBrowser for help on using the repository browser.