Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/test/src/world_entities/environments/mapped_water.h @ 10594

Last change on this file since 10594 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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