[7679] | 1 | /* |
---|
[8793] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[9006] | 3 | |
---|
[8793] | 4 | Copyright (C) 2004 orx |
---|
[9006] | 5 | |
---|
[8793] | 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[9006] | 10 | |
---|
[7679] | 11 | ### File Specific: |
---|
[8793] | 12 | main-programmer: hdavid, amaechler |
---|
[9006] | 13 | |
---|
[8793] | 14 | INSPIRED BY http://www.codesampler.com/usersrc/usersrc_6.htm#oglu_sky_dome_shader |
---|
[7679] | 15 | */ |
---|
| 16 | |
---|
| 17 | #include "cloud_effect.h" |
---|
| 18 | |
---|
| 19 | #include "util/loading/load_param.h" |
---|
| 20 | #include "util/loading/factory.h" |
---|
| 21 | |
---|
[8255] | 22 | #include "material.h" |
---|
| 23 | #include "state.h" |
---|
| 24 | #include "p_node.h" |
---|
| 25 | #include "shader.h" |
---|
| 26 | #include "shell_command.h" |
---|
[9006] | 27 | #include "t_animation.h" |
---|
| 28 | #include "script_class.h" |
---|
[7679] | 29 | |
---|
[9821] | 30 | #include "resource_shader.h" |
---|
| 31 | |
---|
[7679] | 32 | |
---|
[10114] | 33 | |
---|
[9006] | 34 | Vector CloudEffect::cloudColor; |
---|
| 35 | Vector CloudEffect::skyColor; |
---|
| 36 | Vector CloudEffect::newCloudColor; |
---|
| 37 | Vector CloudEffect::newSkyColor; |
---|
[8255] | 38 | |
---|
[9006] | 39 | bool CloudEffect::fadeSky; |
---|
| 40 | bool CloudEffect::fadeCloud; |
---|
| 41 | float CloudEffect::fadeTime; |
---|
| 42 | |
---|
[10114] | 43 | ObjectListDefinition(CloudEffect); |
---|
[7679] | 44 | |
---|
[9406] | 45 | |
---|
[8255] | 46 | SHELL_COMMAND(activate, CloudEffect, activateCloud); |
---|
| 47 | SHELL_COMMAND(deactivate, CloudEffect, deactivateCloud); |
---|
[9006] | 48 | SHELL_COMMAND(skyColor, CloudEffect, shellSkyColor); |
---|
| 49 | SHELL_COMMAND(cloudColor, CloudEffect, shellCloudColor); |
---|
[8255] | 50 | |
---|
[9006] | 51 | |
---|
[9757] | 52 | CREATE_SCRIPTABLE_CLASS(CloudEffect, |
---|
[9746] | 53 | addMethod("skyColor", Executor4<CloudEffect, lua_State*,float,float,float,float>(&CloudEffect::shellSkyColor)) |
---|
| 54 | ->addMethod("cloudColor", Executor4<CloudEffect, lua_State*,float,float,float,float>(&CloudEffect::shellCloudColor)) |
---|
| 55 | ->addMethod("activate", Executor0<CloudEffect, lua_State*>(&CloudEffect::activate)) |
---|
| 56 | ->addMethod("deactivate", Executor0<CloudEffect, lua_State*>(&CloudEffect::deactivate)) |
---|
[9006] | 57 | ); |
---|
| 58 | |
---|
| 59 | |
---|
[9709] | 60 | CREATE_FACTORY(CloudEffect); |
---|
[7679] | 61 | |
---|
[9006] | 62 | CloudEffect::CloudEffect(const TiXmlElement* root) { |
---|
[9686] | 63 | this->registerObject(this, CloudEffect::_objectList); |
---|
[7679] | 64 | |
---|
[9006] | 65 | this->init(); |
---|
[7679] | 66 | |
---|
[9006] | 67 | if (root != NULL) |
---|
| 68 | this->loadParams(root); |
---|
[7679] | 69 | |
---|
[9006] | 70 | if(cloudActivate) |
---|
| 71 | this->activate(); |
---|
[7679] | 72 | } |
---|
| 73 | |
---|
[9006] | 74 | CloudEffect::~CloudEffect() { |
---|
| 75 | this->deactivate(); |
---|
[8793] | 76 | |
---|
[9006] | 77 | if (glIsTexture(noise3DTexName)) |
---|
| 78 | glDeleteTextures(1, &noise3DTexName); |
---|
[7679] | 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
[9006] | 82 | void CloudEffect::init() { |
---|
[9863] | 83 | PRINTF(4)("Initializing CloudEffect\n"); |
---|
[7768] | 84 | |
---|
[9006] | 85 | // default values |
---|
| 86 | this->offsetZ = 0; |
---|
| 87 | this->animationSpeed = 2; |
---|
| 88 | this->scale = 0.0004f; |
---|
| 89 | this->atmosphericRadius = 4000; |
---|
| 90 | this->planetRadius = 1500; |
---|
| 91 | this->divs = 15; |
---|
[9235] | 92 | this->cloudActivate = false; |
---|
[9006] | 93 | fadeSky = false; |
---|
| 94 | fadeCloud = false; |
---|
[8793] | 95 | |
---|
| 96 | |
---|
[9006] | 97 | skyColor = Vector(0.0f, 0.0f, 0.8f); |
---|
| 98 | cloudColor = Vector(0.8f, 0.8f, 0.8f); |
---|
| 99 | newSkyColor = skyColor; |
---|
| 100 | newCloudColor = cloudColor; |
---|
[8793] | 101 | |
---|
[9006] | 102 | this->noise3DTexSize = 128; |
---|
| 103 | this->noise3DTexName = 0; |
---|
[8793] | 104 | |
---|
[9006] | 105 | this->make3DNoiseTexture(); |
---|
[8793] | 106 | |
---|
[9006] | 107 | glGenTextures(1, &noise3DTexName); |
---|
| 108 | glBindTexture(GL_TEXTURE_3D, noise3DTexName); |
---|
[8793] | 109 | |
---|
[9006] | 110 | glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
---|
| 111 | glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
---|
| 112 | glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
---|
| 113 | glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
---|
| 114 | glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
---|
[8793] | 115 | |
---|
[9006] | 116 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, |
---|
| 117 | noise3DTexSize, noise3DTexSize, noise3DTexSize, |
---|
| 118 | 0, GL_RGBA, GL_UNSIGNED_BYTE, noise3DTexPtr); |
---|
[8793] | 119 | |
---|
[9006] | 120 | this->skydome = new Skydome(); |
---|
| 121 | this->skydome->setTexture(noise3DTexName); |
---|
[8793] | 122 | |
---|
[10034] | 123 | if ( Shader::isSupported() ) |
---|
| 124 | { |
---|
| 125 | this->shader = ResourceShader("/shaders/cloud.vert", "/shaders/cloud.frag"); |
---|
| 126 | |
---|
| 127 | this->shader.activateShader(); |
---|
| 128 | |
---|
| 129 | Shader::Uniform(shader, "Noise").set(0); |
---|
| 130 | |
---|
| 131 | this->offset = new Shader::Uniform(shader, "Offset"); |
---|
| 132 | this->skycolor = new Shader::Uniform(shader, "SkyColor"); |
---|
| 133 | this->cloudcolor = new Shader::Uniform(shader, "CloudColor"); |
---|
| 134 | |
---|
| 135 | this->shader.deactivateShader(); |
---|
| 136 | |
---|
| 137 | this->skydome->setShader(&shader); |
---|
| 138 | } |
---|
[7679] | 139 | } |
---|
| 140 | |
---|
| 141 | |
---|
[9006] | 142 | void CloudEffect::loadParams(const TiXmlElement* root) { |
---|
| 143 | WeatherEffect::loadParams(root); |
---|
[7768] | 144 | |
---|
[9006] | 145 | LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed); |
---|
| 146 | LoadParam(root, "scale", this, CloudEffect, setCloudScale); |
---|
| 147 | LoadParam(root, "cloudcolor", this, CloudEffect, setCloudColor); |
---|
| 148 | LoadParam(root, "skycolor", this, CloudEffect, setSkyColor); |
---|
[8793] | 149 | |
---|
[9006] | 150 | LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius); |
---|
| 151 | LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius); |
---|
| 152 | LoadParam(root, "divisions", this, CloudEffect, setDivisions); |
---|
[8793] | 153 | |
---|
[9006] | 154 | LOAD_PARAM_START_CYCLE(root, element); |
---|
| 155 | { |
---|
| 156 | LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); |
---|
| 157 | } |
---|
| 158 | LOAD_PARAM_END_CYCLE(element); |
---|
[8255] | 159 | } |
---|
[7768] | 160 | |
---|
| 161 | |
---|
[9006] | 162 | void CloudEffect::activate() { |
---|
| 163 | PRINTF(0)( "Activating\n"); |
---|
[7784] | 164 | |
---|
[9006] | 165 | // Can only be set after the loadParams call |
---|
[9818] | 166 | this->shader.activateShader(); |
---|
[9006] | 167 | Shader::Uniform(shader, "Scale").set(this->scale); |
---|
| 168 | this->skycolor->set |
---|
| 169 | (skyColor.x, skyColor.y, skyColor.z); |
---|
| 170 | this->cloudcolor->set |
---|
| 171 | (cloudColor.x, cloudColor.y, cloudColor.z); |
---|
[9818] | 172 | this->shader.deactivateShader(); |
---|
[8793] | 173 | |
---|
[9006] | 174 | this->skydome->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1); |
---|
| 175 | this->skydome->activate(); |
---|
[8793] | 176 | |
---|
[9006] | 177 | this->cloudActivate = true; |
---|
[7768] | 178 | } |
---|
[7679] | 179 | |
---|
[9006] | 180 | void CloudEffect::deactivate() { |
---|
[9863] | 181 | PRINTF(4)("Deactivating CloudEffect\n"); |
---|
[8255] | 182 | |
---|
[9006] | 183 | this->skydome->deactivate(); |
---|
| 184 | this->cloudActivate = false; |
---|
[7679] | 185 | } |
---|
[7768] | 186 | |
---|
[9006] | 187 | void CloudEffect::draw() const {} |
---|
[8793] | 188 | |
---|
[9006] | 189 | void CloudEffect::tick (float dt) { |
---|
[7768] | 190 | |
---|
[10034] | 191 | if ( this->cloudActivate && Shader::isSupported() ) { |
---|
[9006] | 192 | |
---|
| 193 | this->offsetZ += 0.05 * dt * this->animationSpeed; |
---|
| 194 | |
---|
[9818] | 195 | this->shader.activateShader(); |
---|
[9112] | 196 | this->offset->set |
---|
| 197 | (0.0f, 0.0f, offsetZ); |
---|
[9006] | 198 | |
---|
[9112] | 199 | if(cloudColor != newCloudColor) { |
---|
[9006] | 200 | |
---|
[9112] | 201 | if(fadeCloud) { |
---|
[9006] | 202 | |
---|
[9112] | 203 | this->cloudColorFadeX = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudX); |
---|
| 204 | this->cloudColorFadeX->setInfinity(ANIM_INF_CONSTANT); |
---|
| 205 | this->cloudColorFadeY = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudY); |
---|
| 206 | this->cloudColorFadeY->setInfinity(ANIM_INF_CONSTANT); |
---|
| 207 | this->cloudColorFadeZ = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudZ); |
---|
| 208 | this->cloudColorFadeZ->setInfinity(ANIM_INF_CONSTANT); |
---|
[9006] | 209 | |
---|
[9112] | 210 | this->cloudColorFadeX->addKeyFrame(cloudColor.x, fadeTime, ANIM_LINEAR); |
---|
| 211 | this->cloudColorFadeX->addKeyFrame(newCloudColor.x, 0, ANIM_LINEAR); |
---|
[9006] | 212 | |
---|
[9112] | 213 | this->cloudColorFadeY->addKeyFrame(cloudColor.y, fadeTime, ANIM_LINEAR); |
---|
| 214 | this->cloudColorFadeY->addKeyFrame(newCloudColor.y, 0, ANIM_LINEAR); |
---|
[9006] | 215 | |
---|
[9112] | 216 | this->cloudColorFadeZ->addKeyFrame(cloudColor.z, fadeTime, ANIM_LINEAR); |
---|
| 217 | this->cloudColorFadeZ->addKeyFrame(newCloudColor.z, 0, ANIM_LINEAR); |
---|
[9006] | 218 | |
---|
[9112] | 219 | fadeCloud = false; |
---|
[9006] | 220 | |
---|
[9112] | 221 | this->cloudColorFadeX->replay(); |
---|
| 222 | this->cloudColorFadeY->replay(); |
---|
| 223 | this->cloudColorFadeZ->replay(); |
---|
[9006] | 224 | } |
---|
| 225 | |
---|
[9112] | 226 | this->cloudcolor->set |
---|
| 227 | (this->cloudColor.x, this->cloudColor.y, this->cloudColor.z); |
---|
| 228 | } |
---|
[9006] | 229 | |
---|
[9112] | 230 | if(skyColor != newSkyColor) { |
---|
[9006] | 231 | |
---|
[9112] | 232 | if(fadeSky) { |
---|
[9006] | 233 | |
---|
[9112] | 234 | this->skyColorFadeX = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyX); |
---|
| 235 | this->skyColorFadeX->setInfinity(ANIM_INF_CONSTANT); |
---|
| 236 | this->skyColorFadeY = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyY); |
---|
| 237 | this->skyColorFadeY->setInfinity(ANIM_INF_CONSTANT); |
---|
| 238 | this->skyColorFadeZ = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyZ); |
---|
| 239 | this->skyColorFadeZ->setInfinity(ANIM_INF_CONSTANT); |
---|
[9006] | 240 | |
---|
[9112] | 241 | this->skyColorFadeX->addKeyFrame(skyColor.x, fadeTime, ANIM_LINEAR); |
---|
| 242 | this->skyColorFadeX->addKeyFrame(newSkyColor.x, 0, ANIM_LINEAR); |
---|
[9006] | 243 | |
---|
[9112] | 244 | this->skyColorFadeY->addKeyFrame(skyColor.y, fadeTime, ANIM_LINEAR); |
---|
| 245 | this->skyColorFadeY->addKeyFrame(newSkyColor.y, 0, ANIM_LINEAR); |
---|
[9006] | 246 | |
---|
[9112] | 247 | this->skyColorFadeZ->addKeyFrame(skyColor.z, fadeTime, ANIM_LINEAR); |
---|
| 248 | this->skyColorFadeZ->addKeyFrame(newSkyColor.z, 0, ANIM_LINEAR); |
---|
[9006] | 249 | |
---|
[9112] | 250 | fadeSky = false; |
---|
[9006] | 251 | |
---|
[9112] | 252 | this->skyColorFadeX->replay(); |
---|
| 253 | this->skyColorFadeY->replay(); |
---|
| 254 | this->skyColorFadeZ->replay(); |
---|
[9006] | 255 | } |
---|
[9112] | 256 | |
---|
| 257 | this->skycolor->set |
---|
| 258 | (this->skyColor.x, this->skyColor.y, this->skyColor.z); |
---|
[9006] | 259 | } |
---|
| 260 | |
---|
[9818] | 261 | this->shader.deactivateShader(); |
---|
[9006] | 262 | } |
---|
[8793] | 263 | } |
---|
[7768] | 264 | |
---|
| 265 | |
---|
[9006] | 266 | void CloudEffect::setColorSkyX(float color) { |
---|
| 267 | skyColor.x = color; |
---|
[8793] | 268 | } |
---|
[9006] | 269 | void CloudEffect::setColorSkyY(float color) { |
---|
| 270 | skyColor.y = color; |
---|
| 271 | } |
---|
| 272 | void CloudEffect::setColorSkyZ(float color) { |
---|
| 273 | skyColor.z = color; |
---|
| 274 | } |
---|
| 275 | void CloudEffect::setColorCloudX(float color) { |
---|
| 276 | cloudColor.x = color; |
---|
| 277 | } |
---|
| 278 | void CloudEffect::setColorCloudY(float color) { |
---|
| 279 | cloudColor.y = color; |
---|
| 280 | } |
---|
| 281 | void CloudEffect::setColorCloudZ(float color) { |
---|
| 282 | cloudColor.z = color; |
---|
| 283 | } |
---|
[7768] | 284 | |
---|
[9006] | 285 | void CloudEffect::changeSkyColor(Vector color, float time) { |
---|
| 286 | newSkyColor = color; |
---|
| 287 | fadeSky = true; |
---|
| 288 | fadeTime = time; |
---|
| 289 | } |
---|
[7768] | 290 | |
---|
[9006] | 291 | |
---|
| 292 | void CloudEffect::changeCloudColor(Vector color, float time) { |
---|
| 293 | newCloudColor = color; |
---|
| 294 | fadeCloud = true; |
---|
| 295 | fadeTime = time; |
---|
[8793] | 296 | } |
---|
[7768] | 297 | |
---|
[9006] | 298 | void CloudEffect::shellSkyColor(float colorX, float colorY, float colorZ, float time) { |
---|
| 299 | changeSkyColor( Vector(colorX, colorY, colorZ), time); |
---|
| 300 | } |
---|
[7768] | 301 | |
---|
[9006] | 302 | void CloudEffect::shellCloudColor(float colorX, float colorY, float colorZ, float time) { |
---|
| 303 | changeCloudColor( Vector(colorX, colorY, colorZ), time); |
---|
| 304 | } |
---|
[7768] | 305 | |
---|
| 306 | |
---|
[8793] | 307 | |
---|
[9006] | 308 | void CloudEffect::make3DNoiseTexture() { |
---|
| 309 | int f, i, j, k, inc; |
---|
| 310 | int startFrequency = 4; |
---|
| 311 | int numOctaves = 4; |
---|
| 312 | double ni[3]; |
---|
| 313 | double inci, incj, inck; |
---|
| 314 | int frequency = startFrequency; |
---|
| 315 | GLubyte *ptr; |
---|
| 316 | double amp = 0.5; |
---|
| 317 | |
---|
| 318 | if ((noise3DTexPtr = (GLubyte *) malloc(noise3DTexSize * |
---|
| 319 | noise3DTexSize * |
---|
| 320 | noise3DTexSize * 4)) == NULL) |
---|
| 321 | PRINTF(0)("ERROR: Could not allocate 3D noise texture\n"); |
---|
| 322 | |
---|
| 323 | for (f=0, inc=0; f < numOctaves; |
---|
| 324 | ++f, frequency *= 2, ++inc, amp *= 0.5) { |
---|
| 325 | SetNoiseFrequency(frequency); |
---|
| 326 | ptr = noise3DTexPtr; |
---|
| 327 | ni[0] = ni[1] = ni[2] = 0; |
---|
| 328 | |
---|
| 329 | inci = 1.0 / (noise3DTexSize / frequency); |
---|
| 330 | for (i=0; i<noise3DTexSize; ++i, ni[0] += inci) { |
---|
| 331 | incj = 1.0 / (noise3DTexSize / frequency); |
---|
| 332 | for (j=0; j<noise3DTexSize; ++j, ni[1] += incj) { |
---|
| 333 | inck = 1.0 / (noise3DTexSize / frequency); |
---|
| 334 | for (k=0; k<noise3DTexSize; ++k, ni[2] += inck, ptr+= 4) { |
---|
| 335 | *(ptr+inc) = (GLubyte) (((noise3(ni)+1.0) * amp)*128.0); |
---|
| 336 | } |
---|
| 337 | } |
---|
[8793] | 338 | } |
---|
| 339 | } |
---|
[7768] | 340 | } |
---|
| 341 | |
---|
[9006] | 342 | void CloudEffect::initNoise() { |
---|
| 343 | int i, j, k; |
---|
[8793] | 344 | |
---|
[9006] | 345 | srand(30757); |
---|
| 346 | for (i = 0 ; i < B ; i++) { |
---|
| 347 | p[i] = i; |
---|
| 348 | g1[i] = (double)((rand() % (B + B)) - B) / B; |
---|
[8793] | 349 | |
---|
[9006] | 350 | for (j = 0 ; j < 2 ; j++) |
---|
| 351 | g2[i][j] = (double)((rand() % (B + B)) - B) / B; |
---|
| 352 | normalize2(g2[i]); |
---|
[8793] | 353 | |
---|
[9006] | 354 | for (j = 0 ; j < 3 ; j++) |
---|
| 355 | g3[i][j] = (double)((rand() % (B + B)) - B) / B; |
---|
| 356 | normalize3(g3[i]); |
---|
| 357 | } |
---|
[8793] | 358 | |
---|
[9006] | 359 | while (--i) { |
---|
| 360 | k = p[i]; |
---|
| 361 | p[i] = p[j = rand() % B]; |
---|
| 362 | p[j] = k; |
---|
| 363 | } |
---|
[8793] | 364 | |
---|
[9006] | 365 | for (i = 0 ; i < B + 2 ; i++) { |
---|
| 366 | p[B + i] = p[i]; |
---|
| 367 | g1[B + i] = g1[i]; |
---|
| 368 | for (j = 0 ; j < 2 ; j++) |
---|
| 369 | g2[B + i][j] = g2[i][j]; |
---|
| 370 | for (j = 0 ; j < 3 ; j++) |
---|
| 371 | g3[B + i][j] = g3[i][j]; |
---|
| 372 | } |
---|
[7768] | 373 | } |
---|
[7784] | 374 | |
---|
[9006] | 375 | void CloudEffect::SetNoiseFrequency( int frequency) { |
---|
| 376 | start = 1; |
---|
| 377 | B = frequency; |
---|
| 378 | BM = B-1; |
---|
[8793] | 379 | } |
---|
| 380 | |
---|
[9006] | 381 | double CloudEffect::noise3( double vec[3]) { |
---|
| 382 | int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; |
---|
| 383 | double rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v; |
---|
| 384 | int i, j; |
---|
[8793] | 385 | |
---|
[9006] | 386 | if (start) { |
---|
| 387 | start = 0; |
---|
| 388 | initNoise(); |
---|
| 389 | } |
---|
[8793] | 390 | |
---|
[9006] | 391 | setup(0, bx0,bx1, rx0,rx1); |
---|
| 392 | setup(1, by0,by1, ry0,ry1); |
---|
| 393 | setup(2, bz0,bz1, rz0,rz1); |
---|
[8793] | 394 | |
---|
[9006] | 395 | i = p[ bx0 ]; |
---|
| 396 | j = p[ bx1 ]; |
---|
[8793] | 397 | |
---|
[9006] | 398 | b00 = p[ i + by0 ]; |
---|
| 399 | b10 = p[ j + by0 ]; |
---|
| 400 | b01 = p[ i + by1 ]; |
---|
| 401 | b11 = p[ j + by1 ]; |
---|
[8793] | 402 | |
---|
[9006] | 403 | t = s_curve(rx0); |
---|
| 404 | sy = s_curve(ry0); |
---|
| 405 | sz = s_curve(rz0); |
---|
[8793] | 406 | |
---|
[9006] | 407 | q = g3[ b00 + bz0 ] ; |
---|
| 408 | u = at3(rx0,ry0,rz0); |
---|
| 409 | q = g3[ b10 + bz0 ] ; |
---|
| 410 | v = at3(rx1,ry0,rz0); |
---|
| 411 | a = lerp(t, u, v); |
---|
[8793] | 412 | |
---|
[9006] | 413 | q = g3[ b01 + bz0 ] ; |
---|
| 414 | u = at3(rx0,ry1,rz0); |
---|
| 415 | q = g3[ b11 + bz0 ] ; |
---|
| 416 | v = at3(rx1,ry1,rz0); |
---|
| 417 | b = lerp(t, u, v); |
---|
[8793] | 418 | |
---|
[9006] | 419 | c = lerp(sy, a, b); |
---|
[8793] | 420 | |
---|
[9006] | 421 | q = g3[ b00 + bz1 ] ; |
---|
| 422 | u = at3(rx0,ry0,rz1); |
---|
| 423 | q = g3[ b10 + bz1 ] ; |
---|
| 424 | v = at3(rx1,ry0,rz1); |
---|
| 425 | a = lerp(t, u, v); |
---|
[8793] | 426 | |
---|
[9006] | 427 | q = g3[ b01 + bz1 ] ; |
---|
| 428 | u = at3(rx0,ry1,rz1); |
---|
| 429 | q = g3[ b11 + bz1 ] ; |
---|
| 430 | v = at3(rx1,ry1,rz1); |
---|
| 431 | b = lerp(t, u, v); |
---|
[8793] | 432 | |
---|
[9006] | 433 | d = lerp(sy, a, b); |
---|
[8793] | 434 | |
---|
[9006] | 435 | return lerp(sz, c, d); |
---|
[8793] | 436 | } |
---|
| 437 | |
---|
[9006] | 438 | void CloudEffect::normalize2( double v[2]) { |
---|
| 439 | double s; |
---|
[8793] | 440 | |
---|
[9006] | 441 | s = sqrt(v[0] * v[0] + v[1] * v[1]); |
---|
| 442 | v[0] = v[0] / s; |
---|
| 443 | v[1] = v[1] / s; |
---|
[8793] | 444 | } |
---|
| 445 | |
---|
[9006] | 446 | void CloudEffect::normalize3( double v[3]) { |
---|
| 447 | double s; |
---|
[8793] | 448 | |
---|
[9006] | 449 | s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); |
---|
| 450 | v[0] = v[0] / s; |
---|
| 451 | v[1] = v[1] / s; |
---|
| 452 | v[2] = v[2] / s; |
---|
[8793] | 453 | } |
---|
| 454 | |
---|