Esempio n. 1
0
//..............................................................................
float interpolatedNoise(float x, float y, int i) {
    float integer_X = int(x);
    float fractional_X = x - integer_X;
    float integer_Y = int(y);
    float fractional_Y = y - integer_Y;
    
    float v1 = smoothNoise(integer_X, integer_Y, i);
    float v2 = smoothNoise(integer_X + 1, integer_Y, i);
    float v3 = smoothNoise(integer_X, integer_Y + 1, i);
    float v4 = smoothNoise(integer_X + 1, integer_Y + 1, i);
    
    float i1 = cosineInterpolate(v1, v2, fractional_X);
    float i2 = cosineInterpolate(v3, v4, fractional_X);
    
    return cosineInterpolate(i1, i2, fractional_Y);  
    
}
Esempio n. 2
0
std::vector<sf::Vector2f> Utils::getInterpolationCosine(std::vector<sf::Vector2f> const& path, unsigned int subdivision)
{
    std::vector<sf::Vector2f> res((path.size()-1)*subdivision+1);
    for(unsigned int i=0;i<path.size()-1;i++){
        for(unsigned int j=0;j<subdivision;j++){
            //res[i+j].y = path[i].y+cosineInterpolate(path[i].y,path[i+1].y,1.f/j);
            unsigned int id = i*subdivision+j;
            float part = (float)j/(subdivision);
            res[id].y = path[i].y+part*(path[i+1].y-path[i].y);
            res[id].x = cosineInterpolate(path[i].x,path[i+1].x,part);
        }
    }
    res[(path.size()-1)*subdivision] = path[path.size()-1];
    return res;
}
Esempio n. 3
0
void PerlinNoise::interpolateMap(int delta)
{
	int lowX = 0, highX = delta;
	int lowZ = 0, highZ = delta;

	for(int z = 0; z < MAX_WORLD_SIZE; z++)
	{
		for(int x = 0; x < MAX_WORLD_SIZE; x++)
		{
			//Adjust locations of known heights if necessary
			if(x > highX)
			{
				highX += delta;
				lowX += delta;
			}

			//Make sure the current location does not already have a height
			if(x == lowX && z == lowZ)
				continue;
			if(x == lowX && z == highZ)
				continue;
			if(x == highX && z == highZ)
				continue;
			if(x == highX && z == lowZ)
				continue;

			//Interpolate the four intermediate values
			double h1 = cosineInterpolate(*getMap(lowX, lowZ), *getMap(highX, lowZ), (x-lowX)/(double)delta);
			double h2 = cosineInterpolate(*getMap(lowX, highZ), *getMap(highX, highZ), (x-lowX)/(double)delta);
			double h3 = cosineInterpolate(*getMap(lowX, lowZ), *getMap(lowX, highZ), (z-lowZ)/(double)delta);
			double h4 = cosineInterpolate(*getMap(highX, lowZ), *getMap(highX, highZ), (z-lowZ)/(double)delta);

			//Interpolate the two values on the current location
			double h5 = cosineInterpolate(h1, h2, (z-lowZ)/(double)delta);
			double h6 = cosineInterpolate(h3, h4, (x-lowX)/(double)delta);

			//Set the height as the average
			*getMap(x, z) = (h5+h6)/2;
		}

		//Adjust locations of known heights if necessary
		if(z >= highZ)
		{
			highZ += delta;
			lowZ += delta;
		}
		lowX = 0;
		highX = delta;
	}

}
Esempio n. 4
0
double AnimationGraph::valueAt( double time )
{
	int i;
	for ( i = keys.count() - 1; i > -1; --i ) {
		if ( keys[i].x <= time ) {
			AnimationKey k1 = keys[i];
			if ( i == keys.count() - 1 )
				return k1.y;
				
			AnimationKey k2 = keys[i+1];
			switch ( k1.keyType ) {
				case AnimationKey::LINEAR:
					return linearInterpolate( k1.y, k2.y, ( time - k1.x ) / ( k2.x - k1.x ) );
				case AnimationKey::CURVE:
					return cosineInterpolate( k1.y, k2.y, ( time - k1.x ) / ( k2.x - k1.x ) );
				default:
					return k1.y;
			}
		}
	}
	return keys[0].y;
}