[9006] | 1 | /*! |
---|
[7796] | 2 | * @file mapped_water.h |
---|
[8719] | 3 | * worldentity for flat, cool looking, mapped water |
---|
[7796] | 4 | */ |
---|
[8719] | 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 --> |
---|
[9006] | 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> |
---|
[8792] | 18 | <watercolor>0.1, 0.2, 0.4</watercolor> |
---|
[8719] | 19 | </MappedWater> |
---|
| 20 | */ |
---|
[7796] | 21 | |
---|
[8719] | 22 | |
---|
[7796] | 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 | |
---|
[9006] | 30 | namespace OrxGui { class GLGuiBox; }; |
---|
[8719] | 31 | |
---|
[9006] | 32 | // forward declaration |
---|
| 33 | template <class T> class tAnimation; |
---|
| 34 | |
---|
[7796] | 35 | class MappedWater : public WorldEntity |
---|
| 36 | { |
---|
[9869] | 37 | ObjectListDeclaration(MappedWater); |
---|
[8719] | 38 | public: |
---|
| 39 | MappedWater(const TiXmlElement* root = NULL); |
---|
| 40 | virtual ~MappedWater(); |
---|
[7796] | 41 | |
---|
[9006] | 42 | // worldentity functions |
---|
[8719] | 43 | void loadParams(const TiXmlElement* root); |
---|
[9006] | 44 | void saveParams(); |
---|
[8719] | 45 | void draw() const; |
---|
| 46 | void tick(float dt); |
---|
[8037] | 47 | |
---|
[8719] | 48 | // function to prepare renderpaths for creation of refleaction and reflaction textures |
---|
| 49 | void activateReflection(); |
---|
| 50 | void deactivateReflection(); |
---|
| 51 | void activateRefraction(); |
---|
| 52 | void deactivateRefraction(); |
---|
[7796] | 53 | |
---|
[9006] | 54 | // slider gui to edit water params during gameplay |
---|
[9021] | 55 | void toggleGui(); |
---|
[9006] | 56 | |
---|
[8719] | 57 | // functions to set parameters for the water, usually they're called through loadparam |
---|
[9006] | 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; } |
---|
[7796] | 71 | |
---|
[8792] | 72 | // functions to change water parameters during runtime |
---|
| 73 | // to reset waterUV and waterFlow just use the normal set functions |
---|
[9006] | 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(); } |
---|
[8792] | 82 | void resetWaterColor(float r, float g, float b); |
---|
[9006] | 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); |
---|
[8792] | 90 | |
---|
[9006] | 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; } |
---|
[8792] | 100 | |
---|
[8719] | 101 | private: |
---|
| 102 | void initParams(); |
---|
| 103 | void initTextures(); |
---|
| 104 | void initShaders(); |
---|
[9006] | 105 | void calcVerts(); |
---|
[7796] | 106 | |
---|
[8719] | 107 | private: |
---|
[9006] | 108 | Material mat; |
---|
[9869] | 109 | Shader shader; |
---|
[9006] | 110 | OrxGui::GLGuiBox* box; |
---|
[7796] | 111 | |
---|
[9006] | 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; |
---|
[7796] | 179 | }; |
---|
| 180 | |
---|
[8719] | 181 | #endif |
---|