Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/environments/mapped_water.h

Last change on this file was 10034, checked in by rennerc, 17 years ago

fix for segfault with ati r300 driver

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