[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" |
---|
[8255] | 21 | #include "util/loading/resource_manager.h" |
---|
[7679] | 22 | |
---|
[8255] | 23 | #include "material.h" |
---|
| 24 | #include "state.h" |
---|
| 25 | #include "p_node.h" |
---|
| 26 | #include "shader.h" |
---|
| 27 | #include "shell_command.h" |
---|
[9006] | 28 | #include "t_animation.h" |
---|
| 29 | #include "script_class.h" |
---|
[7679] | 30 | |
---|
| 31 | #include "parser/tinyxml/tinyxml.h" |
---|
| 32 | |
---|
[9006] | 33 | Vector CloudEffect::cloudColor; |
---|
| 34 | Vector CloudEffect::skyColor; |
---|
| 35 | Vector CloudEffect::newCloudColor; |
---|
| 36 | Vector CloudEffect::newSkyColor; |
---|
[8255] | 37 | |
---|
[9006] | 38 | bool CloudEffect::fadeSky; |
---|
| 39 | bool CloudEffect::fadeCloud; |
---|
| 40 | float CloudEffect::fadeTime; |
---|
| 41 | |
---|
[7679] | 42 | using namespace std; |
---|
| 43 | |
---|
[8255] | 44 | SHELL_COMMAND(activate, CloudEffect, activateCloud); |
---|
| 45 | SHELL_COMMAND(deactivate, CloudEffect, deactivateCloud); |
---|
[9006] | 46 | SHELL_COMMAND(skyColor, CloudEffect, shellSkyColor); |
---|
| 47 | SHELL_COMMAND(cloudColor, CloudEffect, shellCloudColor); |
---|
[8255] | 48 | |
---|
[9006] | 49 | |
---|
| 50 | CREATE_SCRIPTABLE_CLASS(CloudEffect, CL_CLOUD_EFFECT, |
---|
| 51 | addMethod("skyColor", ExecutorLua4<CloudEffect,float,float,float,float>(&CloudEffect::shellSkyColor)) |
---|
[9112] | 52 | ->addMethod("cloudColor", ExecutorLua4<CloudEffect,float,float,float,float>(&CloudEffect::shellCloudColor)) |
---|
| 53 | ->addMethod("activate", ExecutorLua0<CloudEffect>(&CloudEffect::activate)) |
---|
| 54 | ->addMethod("deactivate", ExecutorLua0<CloudEffect>(&CloudEffect::deactivate)) |
---|
[9006] | 55 | ); |
---|
| 56 | |
---|
| 57 | |
---|
[7679] | 58 | CREATE_FACTORY(CloudEffect, CL_CLOUD_EFFECT); |
---|
| 59 | |
---|
[9006] | 60 | CloudEffect::CloudEffect(const TiXmlElement* root) { |
---|
| 61 | this->setClassID(CL_CLOUD_EFFECT, "CloudEffect"); |
---|
[7679] | 62 | |
---|
[9006] | 63 | this->init(); |
---|
[7679] | 64 | |
---|
[9006] | 65 | if (root != NULL) |
---|
| 66 | this->loadParams(root); |
---|
[7679] | 67 | |
---|
[9006] | 68 | if(cloudActivate) |
---|
| 69 | this->activate(); |
---|
[7679] | 70 | } |
---|
| 71 | |
---|
[9006] | 72 | CloudEffect::~CloudEffect() { |
---|
| 73 | this->deactivate(); |
---|
[8793] | 74 | |
---|
[9006] | 75 | if (glIsTexture(noise3DTexName)) |
---|
| 76 | glDeleteTextures(1, &noise3DTexName); |
---|
[8793] | 77 | |
---|
[9006] | 78 | delete shader; |
---|
[7679] | 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
[9006] | 82 | void CloudEffect::init() { |
---|
| 83 | PRINTF(0)("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 | |
---|
[9006] | 123 | this->shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert", |
---|
| 124 | ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag"); |
---|
[7768] | 125 | |
---|
[9006] | 126 | this->shader->activateShader(); |
---|
[8793] | 127 | |
---|
[9006] | 128 | Shader::Uniform(shader, "Noise").set(0); |
---|
[8793] | 129 | |
---|
[9006] | 130 | this->offset = new Shader::Uniform(shader, "Offset"); |
---|
| 131 | this->skycolor = new Shader::Uniform(shader, "SkyColor"); |
---|
| 132 | this->cloudcolor = new Shader::Uniform(shader, "CloudColor"); |
---|
[8793] | 133 | |
---|
[9006] | 134 | this->shader->deactivateShader(); |
---|
| 135 | |
---|
| 136 | this->skydome->setShader(shader); |
---|
[7679] | 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[9006] | 140 | void CloudEffect::loadParams(const TiXmlElement* root) { |
---|
| 141 | WeatherEffect::loadParams(root); |
---|
[7768] | 142 | |
---|
[9006] | 143 | LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed); |
---|
| 144 | LoadParam(root, "scale", this, CloudEffect, setCloudScale); |
---|
| 145 | LoadParam(root, "cloudcolor", this, CloudEffect, setCloudColor); |
---|
| 146 | LoadParam(root, "skycolor", this, CloudEffect, setSkyColor); |
---|
[8793] | 147 | |
---|
[9006] | 148 | LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius); |
---|
| 149 | LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius); |
---|
| 150 | LoadParam(root, "divisions", this, CloudEffect, setDivisions); |
---|
[8793] | 151 | |
---|
[9006] | 152 | LOAD_PARAM_START_CYCLE(root, element); |
---|
| 153 | { |
---|
| 154 | LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); |
---|
| 155 | } |
---|
| 156 | LOAD_PARAM_END_CYCLE(element); |
---|
[8255] | 157 | } |
---|
[7768] | 158 | |
---|
| 159 | |
---|
[9006] | 160 | void CloudEffect::activate() { |
---|
| 161 | PRINTF(0)( "Activating\n"); |
---|
[7784] | 162 | |
---|
[9006] | 163 | // Can only be set after the loadParams call |
---|
| 164 | this->shader->activateShader(); |
---|
| 165 | Shader::Uniform(shader, "Scale").set(this->scale); |
---|
| 166 | this->skycolor->set |
---|
| 167 | (skyColor.x, skyColor.y, skyColor.z); |
---|
| 168 | this->cloudcolor->set |
---|
| 169 | (cloudColor.x, cloudColor.y, cloudColor.z); |
---|
| 170 | this->shader->deactivateShader(); |
---|
[8793] | 171 | |
---|
[9006] | 172 | this->skydome->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1); |
---|
| 173 | this->skydome->activate(); |
---|
[8793] | 174 | |
---|
[9006] | 175 | this->cloudActivate = true; |
---|
[7768] | 176 | } |
---|
[7679] | 177 | |
---|
[9006] | 178 | void CloudEffect::deactivate() { |
---|
| 179 | PRINTF(0)("Deactivating CloudEffect\n"); |
---|
[8255] | 180 | |
---|
[9006] | 181 | this->skydome->deactivate(); |
---|
| 182 | this->cloudActivate = false; |
---|
[7679] | 183 | } |
---|
[7768] | 184 | |
---|
[9006] | 185 | void CloudEffect::draw() const {} |
---|
[8793] | 186 | |
---|
[9006] | 187 | void CloudEffect::tick (float dt) { |
---|
[7768] | 188 | |
---|
[9006] | 189 | if (this->cloudActivate) { |
---|
| 190 | |
---|
| 191 | this->offsetZ += 0.05 * dt * this->animationSpeed; |
---|
| 192 | |
---|
| 193 | this->shader->activateShader(); |
---|
[9112] | 194 | this->offset->set |
---|
| 195 | (0.0f, 0.0f, offsetZ); |
---|
[9006] | 196 | |
---|
[9112] | 197 | if(cloudColor != newCloudColor) { |
---|
[9006] | 198 | |
---|
[9112] | 199 | if(fadeCloud) { |
---|
[9006] | 200 | |
---|
[9112] | 201 | this->cloudColorFadeX = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudX); |
---|
| 202 | this->cloudColorFadeX->setInfinity(ANIM_INF_CONSTANT); |
---|
| 203 | this->cloudColorFadeY = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudY); |
---|
| 204 | this->cloudColorFadeY->setInfinity(ANIM_INF_CONSTANT); |
---|
| 205 | this->cloudColorFadeZ = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudZ); |
---|
| 206 | this->cloudColorFadeZ->setInfinity(ANIM_INF_CONSTANT); |
---|
[9006] | 207 | |
---|
[9112] | 208 | this->cloudColorFadeX->addKeyFrame(cloudColor.x, fadeTime, ANIM_LINEAR); |
---|
| 209 | this->cloudColorFadeX->addKeyFrame(newCloudColor.x, 0, ANIM_LINEAR); |
---|
[9006] | 210 | |
---|
[9112] | 211 | this->cloudColorFadeY->addKeyFrame(cloudColor.y, fadeTime, ANIM_LINEAR); |
---|
| 212 | this->cloudColorFadeY->addKeyFrame(newCloudColor.y, 0, ANIM_LINEAR); |
---|
[9006] | 213 | |
---|
[9112] | 214 | this->cloudColorFadeZ->addKeyFrame(cloudColor.z, fadeTime, ANIM_LINEAR); |
---|
| 215 | this->cloudColorFadeZ->addKeyFrame(newCloudColor.z, 0, ANIM_LINEAR); |
---|
[9006] | 216 | |
---|
[9112] | 217 | fadeCloud = false; |
---|
[9006] | 218 | |
---|
[9112] | 219 | this->cloudColorFadeX->replay(); |
---|
| 220 | this->cloudColorFadeY->replay(); |
---|
| 221 | this->cloudColorFadeZ->replay(); |
---|
[9006] | 222 | } |
---|
| 223 | |
---|
[9112] | 224 | this->cloudcolor->set |
---|
| 225 | (this->cloudColor.x, this->cloudColor.y, this->cloudColor.z); |
---|
| 226 | } |
---|
[9006] | 227 | |
---|
[9112] | 228 | if(skyColor != newSkyColor) { |
---|
[9006] | 229 | |
---|
[9112] | 230 | if(fadeSky) { |
---|
[9006] | 231 | |
---|
[9112] | 232 | this->skyColorFadeX = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyX); |
---|
| 233 | this->skyColorFadeX->setInfinity(ANIM_INF_CONSTANT); |
---|
| 234 | this->skyColorFadeY = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyY); |
---|
| 235 | this->skyColorFadeY->setInfinity(ANIM_INF_CONSTANT); |
---|
| 236 | this->skyColorFadeZ = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyZ); |
---|
| 237 | this->skyColorFadeZ->setInfinity(ANIM_INF_CONSTANT); |
---|
[9006] | 238 | |
---|
[9112] | 239 | this->skyColorFadeX->addKeyFrame(skyColor.x, fadeTime, ANIM_LINEAR); |
---|
| 240 | this->skyColorFadeX->addKeyFrame(newSkyColor.x, 0, ANIM_LINEAR); |
---|
[9006] | 241 | |
---|
[9112] | 242 | this->skyColorFadeY->addKeyFrame(skyColor.y, fadeTime, ANIM_LINEAR); |
---|
| 243 | this->skyColorFadeY->addKeyFrame(newSkyColor.y, 0, ANIM_LINEAR); |
---|
[9006] | 244 | |
---|
[9112] | 245 | this->skyColorFadeZ->addKeyFrame(skyColor.z, fadeTime, ANIM_LINEAR); |
---|
| 246 | this->skyColorFadeZ->addKeyFrame(newSkyColor.z, 0, ANIM_LINEAR); |
---|
[9006] | 247 | |
---|
[9112] | 248 | fadeSky = false; |
---|
[9006] | 249 | |
---|
[9112] | 250 | this->skyColorFadeX->replay(); |
---|
| 251 | this->skyColorFadeY->replay(); |
---|
| 252 | this->skyColorFadeZ->replay(); |
---|
[9006] | 253 | } |
---|
[9112] | 254 | |
---|
| 255 | this->skycolor->set |
---|
| 256 | (this->skyColor.x, this->skyColor.y, this->skyColor.z); |
---|
[9006] | 257 | } |
---|
| 258 | |
---|
| 259 | this->shader->deactivateShader(); |
---|
| 260 | } |
---|
[8793] | 261 | } |
---|
[7768] | 262 | |
---|
| 263 | |
---|
[9006] | 264 | void CloudEffect::setColorSkyX(float color) { |
---|
| 265 | skyColor.x = color; |
---|
[8793] | 266 | } |
---|
[9006] | 267 | void CloudEffect::setColorSkyY(float color) { |
---|
| 268 | skyColor.y = color; |
---|
| 269 | } |
---|
| 270 | void CloudEffect::setColorSkyZ(float color) { |
---|
| 271 | skyColor.z = color; |
---|
| 272 | } |
---|
| 273 | void CloudEffect::setColorCloudX(float color) { |
---|
| 274 | cloudColor.x = color; |
---|
| 275 | } |
---|
| 276 | void CloudEffect::setColorCloudY(float color) { |
---|
| 277 | cloudColor.y = color; |
---|
| 278 | } |
---|
| 279 | void CloudEffect::setColorCloudZ(float color) { |
---|
| 280 | cloudColor.z = color; |
---|
| 281 | } |
---|
[7768] | 282 | |
---|
[9006] | 283 | void CloudEffect::changeSkyColor(Vector color, float time) { |
---|
| 284 | newSkyColor = color; |
---|
| 285 | fadeSky = true; |
---|
| 286 | fadeTime = time; |
---|
| 287 | } |
---|
[7768] | 288 | |
---|
[9006] | 289 | |
---|
| 290 | void CloudEffect::changeCloudColor(Vector color, float time) { |
---|
| 291 | newCloudColor = color; |
---|
| 292 | fadeCloud = true; |
---|
| 293 | fadeTime = time; |
---|
[8793] | 294 | } |
---|
[7768] | 295 | |
---|
[9006] | 296 | void CloudEffect::shellSkyColor(float colorX, float colorY, float colorZ, float time) { |
---|
| 297 | changeSkyColor( Vector(colorX, colorY, colorZ), time); |
---|
| 298 | } |
---|
[7768] | 299 | |
---|
[9006] | 300 | void CloudEffect::shellCloudColor(float colorX, float colorY, float colorZ, float time) { |
---|
| 301 | changeCloudColor( Vector(colorX, colorY, colorZ), time); |
---|
| 302 | } |
---|
[7768] | 303 | |
---|
| 304 | |
---|
[8793] | 305 | |
---|
[9006] | 306 | void CloudEffect::make3DNoiseTexture() { |
---|
| 307 | int f, i, j, k, inc; |
---|
| 308 | int startFrequency = 4; |
---|
| 309 | int numOctaves = 4; |
---|
| 310 | double ni[3]; |
---|
| 311 | double inci, incj, inck; |
---|
| 312 | int frequency = startFrequency; |
---|
| 313 | GLubyte *ptr; |
---|
| 314 | double amp = 0.5; |
---|
| 315 | |
---|
| 316 | if ((noise3DTexPtr = (GLubyte *) malloc(noise3DTexSize * |
---|
| 317 | noise3DTexSize * |
---|
| 318 | noise3DTexSize * 4)) == NULL) |
---|
| 319 | PRINTF(0)("ERROR: Could not allocate 3D noise texture\n"); |
---|
| 320 | |
---|
| 321 | for (f=0, inc=0; f < numOctaves; |
---|
| 322 | ++f, frequency *= 2, ++inc, amp *= 0.5) { |
---|
| 323 | SetNoiseFrequency(frequency); |
---|
| 324 | ptr = noise3DTexPtr; |
---|
| 325 | ni[0] = ni[1] = ni[2] = 0; |
---|
| 326 | |
---|
| 327 | inci = 1.0 / (noise3DTexSize / frequency); |
---|
| 328 | for (i=0; i<noise3DTexSize; ++i, ni[0] += inci) { |
---|
| 329 | incj = 1.0 / (noise3DTexSize / frequency); |
---|
| 330 | for (j=0; j<noise3DTexSize; ++j, ni[1] += incj) { |
---|
| 331 | inck = 1.0 / (noise3DTexSize / frequency); |
---|
| 332 | for (k=0; k<noise3DTexSize; ++k, ni[2] += inck, ptr+= 4) { |
---|
| 333 | *(ptr+inc) = (GLubyte) (((noise3(ni)+1.0) * amp)*128.0); |
---|
| 334 | } |
---|
| 335 | } |
---|
[8793] | 336 | } |
---|
| 337 | } |
---|
[7768] | 338 | } |
---|
| 339 | |
---|
[9006] | 340 | void CloudEffect::initNoise() { |
---|
| 341 | int i, j, k; |
---|
[8793] | 342 | |
---|
[9006] | 343 | srand(30757); |
---|
| 344 | for (i = 0 ; i < B ; i++) { |
---|
| 345 | p[i] = i; |
---|
| 346 | g1[i] = (double)((rand() % (B + B)) - B) / B; |
---|
[8793] | 347 | |
---|
[9006] | 348 | for (j = 0 ; j < 2 ; j++) |
---|
| 349 | g2[i][j] = (double)((rand() % (B + B)) - B) / B; |
---|
| 350 | normalize2(g2[i]); |
---|
[8793] | 351 | |
---|
[9006] | 352 | for (j = 0 ; j < 3 ; j++) |
---|
| 353 | g3[i][j] = (double)((rand() % (B + B)) - B) / B; |
---|
| 354 | normalize3(g3[i]); |
---|
| 355 | } |
---|
[8793] | 356 | |
---|
[9006] | 357 | while (--i) { |
---|
| 358 | k = p[i]; |
---|
| 359 | p[i] = p[j = rand() % B]; |
---|
| 360 | p[j] = k; |
---|
| 361 | } |
---|
[8793] | 362 | |
---|
[9006] | 363 | for (i = 0 ; i < B + 2 ; i++) { |
---|
| 364 | p[B + i] = p[i]; |
---|
| 365 | g1[B + i] = g1[i]; |
---|
| 366 | for (j = 0 ; j < 2 ; j++) |
---|
| 367 | g2[B + i][j] = g2[i][j]; |
---|
| 368 | for (j = 0 ; j < 3 ; j++) |
---|
| 369 | g3[B + i][j] = g3[i][j]; |
---|
| 370 | } |
---|
[7768] | 371 | } |
---|
[7784] | 372 | |
---|
[9006] | 373 | void CloudEffect::SetNoiseFrequency( int frequency) { |
---|
| 374 | start = 1; |
---|
| 375 | B = frequency; |
---|
| 376 | BM = B-1; |
---|
[8793] | 377 | } |
---|
| 378 | |
---|
[9006] | 379 | double CloudEffect::noise3( double vec[3]) { |
---|
| 380 | int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; |
---|
| 381 | double rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v; |
---|
| 382 | int i, j; |
---|
[8793] | 383 | |
---|
[9006] | 384 | if (start) { |
---|
| 385 | start = 0; |
---|
| 386 | initNoise(); |
---|
| 387 | } |
---|
[8793] | 388 | |
---|
[9006] | 389 | setup(0, bx0,bx1, rx0,rx1); |
---|
| 390 | setup(1, by0,by1, ry0,ry1); |
---|
| 391 | setup(2, bz0,bz1, rz0,rz1); |
---|
[8793] | 392 | |
---|
[9006] | 393 | i = p[ bx0 ]; |
---|
| 394 | j = p[ bx1 ]; |
---|
[8793] | 395 | |
---|
[9006] | 396 | b00 = p[ i + by0 ]; |
---|
| 397 | b10 = p[ j + by0 ]; |
---|
| 398 | b01 = p[ i + by1 ]; |
---|
| 399 | b11 = p[ j + by1 ]; |
---|
[8793] | 400 | |
---|
[9006] | 401 | t = s_curve(rx0); |
---|
| 402 | sy = s_curve(ry0); |
---|
| 403 | sz = s_curve(rz0); |
---|
[8793] | 404 | |
---|
[9006] | 405 | q = g3[ b00 + bz0 ] ; |
---|
| 406 | u = at3(rx0,ry0,rz0); |
---|
| 407 | q = g3[ b10 + bz0 ] ; |
---|
| 408 | v = at3(rx1,ry0,rz0); |
---|
| 409 | a = lerp(t, u, v); |
---|
[8793] | 410 | |
---|
[9006] | 411 | q = g3[ b01 + bz0 ] ; |
---|
| 412 | u = at3(rx0,ry1,rz0); |
---|
| 413 | q = g3[ b11 + bz0 ] ; |
---|
| 414 | v = at3(rx1,ry1,rz0); |
---|
| 415 | b = lerp(t, u, v); |
---|
[8793] | 416 | |
---|
[9006] | 417 | c = lerp(sy, a, b); |
---|
[8793] | 418 | |
---|
[9006] | 419 | q = g3[ b00 + bz1 ] ; |
---|
| 420 | u = at3(rx0,ry0,rz1); |
---|
| 421 | q = g3[ b10 + bz1 ] ; |
---|
| 422 | v = at3(rx1,ry0,rz1); |
---|
| 423 | a = lerp(t, u, v); |
---|
[8793] | 424 | |
---|
[9006] | 425 | q = g3[ b01 + bz1 ] ; |
---|
| 426 | u = at3(rx0,ry1,rz1); |
---|
| 427 | q = g3[ b11 + bz1 ] ; |
---|
| 428 | v = at3(rx1,ry1,rz1); |
---|
| 429 | b = lerp(t, u, v); |
---|
[8793] | 430 | |
---|
[9006] | 431 | d = lerp(sy, a, b); |
---|
[8793] | 432 | |
---|
[9006] | 433 | return lerp(sz, c, d); |
---|
[8793] | 434 | } |
---|
| 435 | |
---|
[9006] | 436 | void CloudEffect::normalize2( double v[2]) { |
---|
| 437 | double s; |
---|
[8793] | 438 | |
---|
[9006] | 439 | s = sqrt(v[0] * v[0] + v[1] * v[1]); |
---|
| 440 | v[0] = v[0] / s; |
---|
| 441 | v[1] = v[1] / s; |
---|
[8793] | 442 | } |
---|
| 443 | |
---|
[9006] | 444 | void CloudEffect::normalize3( double v[3]) { |
---|
| 445 | double s; |
---|
[8793] | 446 | |
---|
[9006] | 447 | s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); |
---|
| 448 | v[0] = v[0] / s; |
---|
| 449 | v[1] = v[1] / s; |
---|
| 450 | v[2] = v[2] / s; |
---|
[8793] | 451 | } |
---|
| 452 | |
---|