• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ Noise函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DrawNoise8bit

void DrawNoise8bit (CG16bitImage &Dest, int x, int y, int cxWidth, int cyHeight, int iScale, BYTE byMin, BYTE byMax)

//	DrawNoise8bit
//
//	Draws 8-bit Perlin noise

	{
	ASSERT(iScale > 0);

	NoiseInit();

	//	Make sure we're in bounds

	if (!Dest.HasAlpha() || !Dest.AdjustCoords(NULL, NULL, 0, 0, 
			&x, &y, 
			&cxWidth, &cyHeight))
		return;

	//	Noise returns numbers from -1.0 to 1.0, so we need to scale to appropriate values
	//	Note: We add 0.99999 because we will later truncate to integers and we want
	//	255.0 - 255.99999 to equal 255. We can't add more 9s because floating-point precision
	//	will turn it into 256.0.

	float rRange = (float)(byMax - byMin) + 0.99999f;
	float rFactor = rRange / 2.0f;

	//	Prepare

	CNoiseGenerator Noise(iScale);
	SNoisePos xP, yP;

	//	Fill

	Noise.Reset(yP, y);

	BYTE *pRow = Dest.GetAlphaRow(y);
	BYTE *pRowEnd = Dest.GetAlphaRow(y + cyHeight);
	while (pRow < pRowEnd)
		{
		Noise.Reset(xP, x);

		BYTE *pPos = pRow;
		BYTE *pPosEnd = pRow + cxWidth;
		while (pPos < pPosEnd)
			{
			float rNoise = Noise.GetAt(xP, yP);
			*pPos = byMin + (BYTE)(DWORD)(rFactor * (1.0f + rNoise));

			//	Next pixel

			pPos++;
			Noise.Next(xP);
			}

		//	Next row

		pRow = Dest.NextAlphaRow(pRow);
		Noise.Next(yP);
		}
	}
开发者ID:alanhorizon,项目名称:Transcendence,代码行数:60,代码来源:8bitNoise.cpp


示例17: Run

bool FGSensor::Run(void )
{
  Input = InputNodes[0]->getDoubleValue() * InputSigns[0];

  Output = Input; // perfect sensor

  // Degrade signal as specified

  if (fail_stuck) {
    Output = PreviousOutput;
    return true;
  }

  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 (bias != 0.0)           Bias();      // models a finite bias

  if (delay != 0.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(); // Is it right to clip a sensor?
  return true;
}
开发者ID:Aero348,项目名称:Matlab-Cularis,代码行数:28,代码来源:FGSensor.cpp


示例18: Noise

void cStructGenMarbleCaves::GenFinish(cChunkDesc & a_ChunkDesc)
{
	cNoise Noise(m_Seed);
	for (int z = 0; z < cChunkDef::Width; z++)
	{
		const float zz = static_cast<float>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z);
		for (int x = 0; x < cChunkDef::Width; x++)
		{
			const float xx = static_cast<float>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x);

			int Top = a_ChunkDesc.GetHeight(x, z);
			for (int y = 1; y < Top; ++y)
			{
				if (a_ChunkDesc.GetBlockType(x, y, z) != E_BLOCK_STONE)
				{
					continue;
				}

				const float yy = static_cast<float>(y);
				const float WaveNoise = 1;
				if (cosf(GetMarbleNoise(xx, yy * 0.5f, zz, Noise)) * fabs(cosf(yy * 0.2f + WaveNoise * 2) * 0.75f + WaveNoise) > 0.0005f)
				{
					a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR);
				}
			}  // for y
		}  // for x
	}  // for z
}
开发者ID:ThuGie,项目名称:MCServer,代码行数:28,代码来源:Caves.cpp


示例19: Noise

void cChunkDesc::RandomFillRelCuboid(
	int a_MinX, int a_MaxX,
	int a_MinY, int a_MaxY,
	int a_MinZ, int a_MaxZ,
	BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
	int a_RandomSeed, int a_ChanceOutOf10k
)
{
	cNoise Noise(a_RandomSeed);
	int MinX = std::max(a_MinX, 0);
	int MinY = std::max(a_MinY, 0);
	int MinZ = std::max(a_MinZ, 0);
	int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
	int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
	int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);

	for (int y = MinY; y <= MaxY; y++)
	{
		for (int z = MinZ; z <= MaxZ; z++)
		{
			for (int x = MinX; x <= MaxX; x++)
			{
				int rnd = (Noise.IntNoise3DInt(x, y, z) / 7) % 10000;
				if (rnd <= a_ChanceOutOf10k)
				{
					SetBlockTypeMeta(x, y, z, a_BlockType, a_BlockMeta);
				}
			}
		}  // for z
	}  // for y
}
开发者ID:ThuGie,项目名称:MCServer,代码行数:31,代码来源:ChunkDesc.cpp


示例20: marble_texture

color marble_texture(vector * hit, texture * tex, ray * ry) {
    flt i,d;
    flt x,y,z;
    color col;

    x=hit->x;
    y=hit->y;
    z=hit->z;

    x=x * 1.0;

    d=x + 0.0006 * Noise(x, (y * 1.0), (z * 1.0));
    d=d*(((int) d) % 25);
    i=0.0 + 0.10 * fabs(d - 10.0 - 20.0 * ((int) d * 0.05));
    if (i > 1.0) i=1.0;
    if (i < 0.0) i=0.0;

    /*
      col.r=i * tex->col.r;
      col.g=i * tex->col.g;
      col.b=i * tex->col.b;
    */

    col.r = (1.0 + sin(i * 6.28)) / 2.0;
    col.g = (1.0 + sin(i * 16.28)) / 2.0;
    col.b = (1.0 + cos(i * 30.28)) / 2.0;

    return col;
}
开发者ID:Klaim,项目名称:aos-cpp-dependencies,代码行数:29,代码来源:texture.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NoisePerlin2D函数代码示例发布时间:2022-05-30
下一篇:
C++ NodePath函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap