/* Returns the derivative at the specified grid location. By default this function returns central differences. Due to the interpolation this function uses it implicitly returs forward/backward differences at the respective grid boundaries. */ CVector2D CScalarField2D::_getDerivative(float x, float y) const { static float step = .5f; static float div = 2.0f*step; /*float f1(_getValue(x-step, y)); float f2(_getValue(x+step, y)); float f3(_getValue(x, y-step)); float f4(_getValue(x, y+step)); return CVector2D( (f2-f1)/div, (f4-f3)/div );*/ return CVector2D( (_getValue(x+step, y)-_getValue(x-step, y))/div, (_getValue(x, y+step)-_getValue(x, y-step))/div ); }
float CScalarField2D::GetValue(const CPointf &posD) const { static float x, y; _getGridCoordinates(posD.x, posD.y, x, y); return _getValue(x,y); }
/* Returns the bi-linearly interpolated value at the specified coordinate in domain space. Parameters: dx: X-component of the domain coordinate dy: Y-component of the domain coordinate posD: Two dimensional point specifying the domain coordinate */ float CScalarField2D::GetValue(float dx, float dy) const { static float x, y; _getGridCoordinates(dx, dy, x, y); return _getValue(x,y); }
void RainbowLegMode::_doubleRainbow() { for (int i = 0; i < _half; i++) _pixels[i].setHSV(map(i, 0, _half, 0, 255), 255, _getValue(i)); // <gerstle> setting _pixels[_pixelCount - 1 - i] to _pixels[i] would work if half // was actually half... so, run through both sides... :( for (int i = _half; i < _pixelCount; i++) _pixels[i].setHSV(map((_pixelCount - i - 1), 0, (_pixelCount - _half - 1), 0, 255), 255, _getValue(i)); }
void RainbowLegMode::_rotate() { if (_currentTime > (_lastChangeTimer + _config->rainbow.delay)) { _lastChangeTimer = _currentTime; _perlinZ += 0.001; // <gerstle> this increment shows the entire hue spectrum on a leg // if you go less than that, not all the colors show all the time, kinda nice. for (int i = 0; i < _pixelCount; i++) _pixels[i].setHSV(_lastStartHue + (((float)i) * (_increment * .6)), 255, _getValue(i)); // <gerstle> let it roll under _lastStartHue--; } }
void RainbowLegMode::_rise() { if (_currentTime > (_lastChangeTimer + _config->rainbow.delay)) { _lastChangeTimer = _currentTime; _perlinZ += 0.001; for (int i = 0; i < _half; i++) _pixels[i].setHSV(_lastStartHue + (((float)i) * _increment), 255, _getValue(i)); // <gerstle> setting _pixels[_pixelCount - 1 - i] to _pixels[i] would work if half // was actually half... so, run through both sides... :( for (int i = _half; i < _pixelCount; i++) _pixels[i].setHSV(_lastStartHue + (((float)(_pixelCount - i - 1)) * _increment), 255, _getValue(i)); // <gerstle> let it roll over _lastStartHue++; } }
void blTerrainProxy::light(LightInfo * light) { // If we don't have terrain or its not a directional // light then skip processing. TerrainBlock * terrain = getObject(); if ( !terrain || light->getType() != LightInfo::Vector ) return; S32 time = Platform::getRealMilliseconds(); // reset mShadowVolume = new ShadowVolumeBSP; // build interior shadow volume for(ObjectProxy ** itr = gLighting->mLitObjects.begin(); itr != gLighting->mLitObjects.end(); itr++) { ObjectProxy* objproxy = *itr; if (markObjectShadow(objproxy)) objproxy->addToShadowVolume(mShadowVolume, light, SceneLighting::SHADOW_DETAIL); } lightVector(light); // set the lightmap... terrain->clearLightMap(); // Blur... F32 kernel[3][3] = { {1, 2, 1}, {2, 3, 2}, {1, 2, 1} }; F32 modifier = 1; F32 divisor = 0; for( U32 i=0; i<3; i++ ) { for( U32 j=0; j<3; j++ ) { if( i==1 && j==1 ) { kernel[i][j] = 1 + kernel[i][j] * modifier; } else { kernel[i][j] = kernel[i][j] * modifier; } divisor += kernel[i][j]; } } for( U32 i=0; i < mLightMapSize; i++ ) { for( U32 j=0; j < mLightMapSize; j++ ) { ColorF val; val = _getValue( i-1, j-1 ) * kernel[0][0]; val += _getValue( i-1, j ) * kernel[0][1]; val += _getValue( i-1, j+1 ) * kernel[0][2]; val += _getValue( i, j-1 ) * kernel[1][0]; val += _getValue( i, j ) * kernel[1][1]; val += _getValue( i, j+1 ) * kernel[1][2]; val += _getValue( i+1, j-1 ) * kernel[2][0]; val += _getValue( i+1, j ) * kernel[2][1]; val += _getValue( i+1, j+1 ) * kernel[2][2]; U32 edge = 0; if( j == 0 || j == mLightMapSize - 1 ) edge++; if( i == 0 || i == mLightMapSize - 1 ) edge++; if( !edge ) val = val / divisor; else val = mLightmap[ i * mLightMapSize + j ]; // clamp values mLightmap[ i * mLightMapSize + j ]= val; } } // And stuff it into the texture... GBitmap *terrLightMap = terrain->getLightMap(); for(U32 y = 0; y < mLightMapSize; y++) { for(U32 x = 0; x < mLightMapSize; x++) { ColorI color(255, 255, 255, 255); color.red = mLightmap[x + y * mLightMapSize].red * 255; color.green = mLightmap[x + y * mLightMapSize].green * 255; color.blue = mLightmap[x + y * mLightMapSize].blue * 255; terrLightMap->setColor(x, y, color); } } /* // This handles matching up the outer edges of the terrain // lightmap when it has neighbors if (!terrain->isTiling()) { for (S32 y = 0; y < terrLightMap->getHeight(); y++) { ColorI c; if (terrain->getFile()->mEdgeTerrainFiles[0]) { terrLightMap->getColor(terrLightMap->getWidth()-1,y,c); terrLightMap->setColor(0,y,c); terrLightMap->setColor(1,y,c); } else { terrLightMap->getColor(0,y,c); terrLightMap->setColor(terrLightMap->getWidth()-1,y,c); terrLightMap->setColor(terrLightMap->getWidth()-2,y,c); } } for (S32 x = 0; x < terrLightMap->getHeight(); x++) { ColorI c; if (terrain->getFile()->mEdgeTerrainFiles[1]) { terrLightMap->getColor(x,terrLightMap->getHeight()-1,c); terrLightMap->setColor(x,0,c); terrLightMap->setColor(x,1,c); } else { terrLightMap->getColor(x,0,c); terrLightMap->setColor(x,terrLightMap->getHeight()-1,c); terrLightMap->setColor(x,terrLightMap->getHeight()-2,c); } } } */ delete mShadowVolume; Con::printf(" = terrain lit in %3.3f seconds", (Platform::getRealMilliseconds()-time)/1000.f); }
void RainbowLegMode::_singleRainbow() { for (int i = 0; i < _pixelCount; i++) _pixels[i].setHSV(map(i, 0, _pixelCount, 0, 255), 255, _getValue(i)); }