当前位置: 首页>>代码示例>>C++>>正文


C++ Noise函数代码示例

本文整理汇总了C++中Noise函数的典型用法代码示例。如果您正苦于以下问题:C++ Noise函数的具体用法?C++ Noise怎么用?C++ Noise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Noise函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PerlinNoise

/*
 Ruido Perlin para la posicion x,y
 */
float PerlinNoise(float x,float y,int width,int octaves,float seed, float persistence){
	double a,b,valor=0,freq,cachox,cachoy;
	int casilla,num_pasos,pasox,pasoy;
	float amplitud=256*persistence;            //La amplitud es 128,64,32,16... para cada pasada
	float periodo=256;                         //El periodo es similar a la amplitud
	if (octaves>12) 
		octaves=12;
	
	
	for (int s=0;s<octaves;s++){
		amplitud/=2;                      
		periodo/=2;
		freq=1/float(periodo);             //Optimizacion para dividir 1 vez y multiplicar luego
		num_pasos=int(width*freq);         //Para el const que vimos en IntNoise
		pasox=int(x*freq);                 //Indices del vértice superior izquerda del cuadrado
		pasoy=int(y*freq);                 //en el que nos encontramos
		cachox=x*freq-pasox;               //frac_x y frac_y en el ejemplo
		cachoy=y*freq-pasoy;
		casilla=pasox+pasoy*num_pasos;     // índice final del IntNoise
		a=InterPol(Noise(casilla+seed),Noise(casilla+1+seed),cachox);
		b=InterPol(Noise(casilla+num_pasos+seed),Noise(casilla+1+num_pasos+seed),cachox);
		valor+=InterPol(a,b,cachoy)*amplitud;   //superposicion del valor final con anteriores
	}
	
	return valor;      
	
}
开发者ID:LuisGP,项目名称:Practicas-TAG3D,代码行数:30,代码来源:perlin.cpp

示例2: PerlinNoise

float PerlinNoise(float x, float y, int width, int octaves, int seed, double period) {

	double a, b, value, freq, zone_x, zone_y;
	int s, box, num, step_x, step_y;
	float amplitude = period;
	int noisedata;

	freq = 1 / period;
	value = 0;

	for (s = 0; s<octaves; s++) {
		num = static_cast<int>(width*freq);
		step_x = static_cast<int>(x*freq);
		step_y = static_cast<int>(y*freq);
		zone_x = x*freq - step_x;
		zone_y = y*freq - step_y;
		box = step_x + step_y*num;
		noisedata = (box + seed);
		a = InterLinear(Noise(noisedata), Noise(noisedata + 1), zone_x);
		b = InterLinear(Noise(noisedata + num), Noise(noisedata + 1 + num), zone_x);
		value += InterLinear(a, b, zone_y)*amplitude;
		freq *= 4;
		amplitude /= 4;
	}
	return value;
}
开发者ID:zackszhu,项目名称:SimpleQuidditch,代码行数:26,代码来源:WhiteBall.cpp

示例3: Turbulence

Float Turbulence(const Point3f &p, const Vector3f &dpdx, const Vector3f &dpdy,
                 Float omega, int maxOctaves) {
    // Compute number of octaves for antialiased FBm
    Float len2 = std::max(dpdx.LengthSquared(), dpdy.LengthSquared());
    Float foctaves = Clamp(-1.f - .5f * Log2(len2), 0, maxOctaves);
    int octaves = std::floor(foctaves);

    // Compute sum of octaves of noise for turbulence
    Float sum = 0.f, lambda = 1.f, o = 1.f;
    for (int i = 0; i < octaves; ++i) {
        sum += o * std::abs(Noise(lambda * p));
        lambda *= 1.99f;
        o *= omega;
    }

    // Account for contributions of clamped octaves in turbulence
    Float partialOctave = foctaves - octaves;
    sum += o * Lerp(SmoothStep(.3f, .7f, partialOctave), 0.2,
                    std::abs(Noise(lambda * p)));
    for (int i = octaves; i < maxOctaves; ++i) {
        sum += o * 0.2f;
        o *= omega;
    }
    return sum;
}
开发者ID:KojiNakamaru,项目名称:pbrt-v3,代码行数:25,代码来源:texture.cpp

示例4: InterpolatedNoise

float InterpolatedNoise(float x) {

	int integer_X = int(x);
	float fractional_X = x - integer_X;

	float v1 = Noise(integer_X);
	float v2 = Noise(integer_X + 1);

	return Interpolate(v1, v2, fractional_X);
}
开发者ID:jazztickets,项目名称:cmaketest,代码行数:10,代码来源:main.cpp

示例5: SmoothNoise

float SmoothNoise(int x, int y)
{
    float corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16;
    float sides   = ( Noise(x-1, y)  +Noise(x+1, y)  +Noise(x, y-1)  +Noise(x, y+1) ) /  8;
    float center  =  Noise(x, y) / 4;
    return corners + sides + center;
}
开发者ID:max79137913,项目名称:3D_Render_Library,代码行数:7,代码来源:tex_fun.cpp

示例6: SmoothedNoise

	double SmoothedNoise(int x, int y){
		double corners, sides, center;
		corners = (Noise(x - 1, y - 1) + Noise(x + 1, y - 1) + Noise(x - 1, y + 1) + Noise(x + 1, y + 1)) / 32.0;
		sides = (Noise(x - 1, y) + Noise(x + 1, y) + Noise(x, y - 1) + Noise(x, y + 1)) / 16.0;
		center = Noise(x, y) / 8.0;
		return corners + sides + center;
	}
开发者ID:haozi23333,项目名称:NEWorld,代码行数:7,代码来源:WorldGen.cpp

示例7: SmoothNoise

double SmoothNoise(int x, int y)
{
	double corners = (Noise(x - 1, y - 1) + Noise(x + 1, y - 1) + Noise(x - 1, y + 1) + Noise(x + 1, y + 1)) / 16;
	double sides = (Noise(x - 1, y) + Noise(x + 1, y) + Noise(x, y - 1) + Noise(x, y + 1)) / 8;
	double center = Noise(x, y) / 4;
	return corners + sides + center;
}
开发者ID:KarteekKumarM,项目名称:MountainTerrain,代码行数:7,代码来源:Utility.cpp

示例8: Noise

float PerlinNoise::SmoothNoise1(int x, int y) const 
{
	float corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16;
	float sides   = ( Noise(x-1, y)  +Noise(x+1, y)  +Noise(x, y-1)  +Noise(x, y+1) ) /  8;
	float center  =  Noise(x, y) / 4;
	return corners + sides + center;
}
开发者ID:dreamsxin,项目名称:ultimatepp,代码行数:7,代码来源:PerlinNoise.cpp

示例9: Turbulence

void WoodMaterial::color_texture (Vector3D& v)
{
  float X = v.x, Y = v.y, Z = v.z;  
  float x=scale*X, y=scale*Y, z=scale*Z;         // scale the texture coordinates
   
  x *= 0.08f;                    // Get some noise values. Drag out the texture in
  float chaos = Turbulence(x,y,z,0.01f) * 0.5; // the direction of the stem of the 
  float val2 = Noise(x,y,z);             // fictive tree. The pattern should vary
                                                    //  less along that direction

  float tx,ty,tz;           // Make the pattern "semi"-periodic so it looks as if
  if (z > 0.0) {                      // a new board is used at regular intervals
    tz = floor((z + boardsize*0.5) / boardsize);
    z -= tz * boardsize;
  } else {
    tz = floor((boardsize*0.5 - z) / boardsize);
    z += tz * boardsize;
  }
  if (y > 0.0) {
    ty = floor((y + boardsize*0.5) / boardsize);
    y -= ty * boardsize;
  } else {
    ty = floor((boardsize*0.5 - y) / boardsize);
    y += ty * boardsize;
  }

  tx = 0;                            // Skew the "stem" so the "cylinders" aren't 
  float skewoff = Noise(tx,ty,tz);               // perfectly symmetric about the  
  z -= (0.05 + 0.03*skewoff) * (X*scale - 2.0);     // x-axis. Skew the different
  y -= (0.05 + 0.03*skewoff) * (X*scale - 2.0);   // "logs" slightly differently.
    
  float rad = ::hypot(y,z) + chaos; // Calculate distance from middle of "stem" and
  float val = rad - floor(rad);   //  distort this distance with turbulence value

  if (val < 0.1) {	    // Choose a color dependent on the distorted distance
    v.x = base.red;
    v.y = base.green;
    v.z = base.blue;
  } else if (val < 0.9) {
    float t = 1.0 - pow(val / 0.8 - 0.1, 6.0);
    v.x = ring.red   + t * (base.red   - ring.red);
    v.y = ring.green + t * (base.green - ring.green);
    v.z = ring.blue  + t * (base.blue  - ring.blue);
  } else {
    v.x = ring.red;
    v.y = ring.green;
    v.z = ring.blue;
  }
  
  if (val2 < 0.01 && val2 > 0.0) {   // Add a little extra "noise" so the pattern 
   v.x = ring.red;                      // doesn't get too regular. this could be 
   v.y = ring.green;               // small cracks,or other anomalies in the wood
   v.z = ring.blue;
  }
}
开发者ID:lucafuji,项目名称:Gene-Correlation,代码行数:55,代码来源:materials.cpp

示例10: Noise

float PerlinNoise::SmoothNoise(int x, int y, int i)
{
    float corners = ( Noise(x-1, y-1,i)+Noise(x+1, y-1,i)+Noise(x-1, y+1,i)+Noise(x+1, y+1,i) ) / 16;
    float sides   = ( Noise(x-1, y,i)  +Noise(x+1, y,i)  +Noise(x, y-1,i)  +Noise(x, y+1,i) ) /  8;
    float center  =  Noise(x, y,i) / 4;
    return corners + sides + center;
}
开发者ID:vHanda,项目名称:Survival,代码行数:7,代码来源:PerlinNoise.cpp

示例11: pow

HRESULT HEIGHTMAP::CreateRandomHeightMap(int seed, float noiseSize, float persistence, int octaves)
{
	//For each map node
	for(int y=0;y<m_size.y;y++)
		for(int x=0;x<m_size.x;x++)
		{
			//Scale x & y to the range of 0.0 - m_size
			float xf = ((float)x / (float)m_size.x) * noiseSize;
			float yf = ((float)y / (float)m_size.y) * noiseSize;

			float total = 0;			

			// For each octave
			for(int i=0;i<octaves;i++)
			{
				//Calculate frequency and amplitude (different for each octave)
				float freq = pow(2.0f, i);
				float amp = pow(persistence, i);

				//Calculate the x,y noise coordinates
				float tx = xf * freq;
				float ty = yf * freq;
				int tx_int = (int)tx;
				int ty_int = (int)ty;

				//Calculate the fractions of x & y
			    float fracX = tx - tx_int;
			    float fracY = ty - ty_int;

				//Get the noise of this octave for each of these 4 points
				float v1 = Noise(tx_int + ty_int * 57 + seed);
				float v2 = Noise(tx_int+ 1 + ty_int * 57 + seed);
				float v3 = Noise(tx_int + (ty_int+1) * 57 + seed);
				float v4 = Noise(tx_int + 1 + (ty_int+1) * 57 + seed);

				//Smooth in the X-axis
				float i1 = CosInterpolate(v1 , v2 , fracX);
				float i2 = CosInterpolate(v3 , v4 , fracX);

				//Smooth in the Y-axis
				total += CosInterpolate(i1 , i2 , fracY) * amp;
			}

			int b = (int)(128 + total * 128.0f);
			if(b < 0)b = 0;
			if(b > 255)b = 255;

			//Save to heightMap
			m_pHeightMap[x + y * m_size.x] = (b / 255.0f) * m_maxHeight;
		}

	return S_OK;
}
开发者ID:Alriightyman,项目名称:RTS,代码行数:53,代码来源:heightMap.cpp

示例12: Noise

void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed)
{
	// Calculate the total weight:
	int TotalProbab = 1;
	for (size_t i = 0; i < a_CountLootProbabs; i++)
	{
		TotalProbab += a_LootProbabs[i].m_Weight;
	}
	
	// Pick the loot items:
	cNoise Noise(a_Seed);
	for (int i = 0; i < a_NumSlots; i++)
	{
		int Rnd = (Noise.IntNoise1DInt(i) / 7);
		int LootRnd = Rnd % TotalProbab;
		Rnd >>= 8;
		cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0);  // TODO: enchantment
		for (size_t j = 0; j < a_CountLootProbabs; j++)
		{
			LootRnd -= a_LootProbabs[i].m_Weight;
			if (LootRnd < 0)
			{
				CurrentLoot = a_LootProbabs[i].m_Item;
				CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount + (Rnd % (a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount));
				Rnd >>= 8;
				break;
			}
		}  // for j - a_LootProbabs[]
		SetSlot(Rnd % m_NumSlots, CurrentLoot);
	}  // for i - NumSlots
开发者ID:JoeClacks,项目名称:MCServer,代码行数:30,代码来源:ItemGrid.cpp

示例13: ProcessSensorSignal

void FGSensor::ProcessSensorSignal(void)
{
    Output = Input; // perfect sensor

    // Degrade signal as specified

    if (fail_stuck) {
        Output = PreviousOutput;
    } else {
        if (lag != 0.0)            Lag();       // models sensor lag and filter
        if (noise_variance != 0.0) Noise();     // models noise
        if (drift_rate != 0.0)     Drift();     // models drift over time
        if (gain != 0.0)           Gain();      // models a finite gain
        if (bias != 0.0)           Bias();      // models a finite bias

        if (delay != 0)            Delay();     // models system signal transport latencies

        if (fail_low)  Output = -HUGE_VAL;
        if (fail_high) Output =  HUGE_VAL;

        if (bits != 0)             Quantize();  // models quantization degradation

        Clip();
    }
}
开发者ID:AEgisTG,项目名称:jsbsim,代码行数:25,代码来源:FGSensor.cpp

示例14: if

void FGSensor::ProcessSensorSignal(void)
{
  Output = Input; // perfect sensor

  // Degrade signal as specified

  if (fail_stuck) {
    Output = PreviousOutput;
  } else if (fcs->GetTrimStatus()) {
    if (lag != 0.0)            {PreviousOutput = Output;    PreviousInput  = Input;}
    if (drift_rate != 0.0)     drift = 0;
    if (gain != 0.0)           Gain();      // models a finite gain
    if (bias != 0.0)           Bias();      // models a finite bias

    if (delay != 0)            for (int i=0; i<delay; i++) output_array[i] = Output;

    Clip();
  } else {
    if (lag != 0.0)            Lag();       // models sensor lag and filter
    if (noise_variance != 0.0) Noise();     // models noise
    if (drift_rate != 0.0)     Drift();     // models drift over time
    if (gain != 0.0)           Gain();      // models a finite gain
    if (bias != 0.0)           Bias();      // models a finite bias

    if (delay != 0)            Delay();     // models system signal transport latencies

    if (fail_low)  Output = -HUGE_VAL;
    if (fail_high) Output =  HUGE_VAL;

    if (bits != 0)             Quantize();  // models quantization degradation

    Clip();
  }
  if (IsOutput) SetOutput();
}
开发者ID:matthewzhenggong,项目名称:jsbsim,代码行数:35,代码来源:FGSensor.cpp

示例15: cEnchantments

cEnchantments cEnchantments::SelectEnchantmentFromVector(const cWeightedEnchantments & a_Enchantments, int a_Seed)
{
	// Sum up all the enchantments' weights:
	int AllWeights = 0;
	for (const auto Enchantment : a_Enchantments)
	{
		AllWeights += Enchantment.m_Weight;
	}

	// If there's no weight for any of the enchantments, return an empty enchantment
	if (AllWeights <= 0)
	{
		return cEnchantments();
	}

	// Pick a random enchantment:
	cNoise Noise(a_Seed);
	int RandomNumber = Noise.IntNoise1DInt(AllWeights) / 7 % AllWeights;
	for (const auto Enchantment : a_Enchantments)
	{
		RandomNumber -= Enchantment.m_Weight;
		if (RandomNumber <= 0)
		{
			return Enchantment.m_Enchantments;
		}
	}

	// No enchantment picked, return an empty one (we probably shouldn't ever get here):
	return cEnchantments();
}
开发者ID:36451,项目名称:MCServer,代码行数:30,代码来源:Enchantments.cpp


注:本文中的Noise函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。