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