コード例 #1
0
ファイル: Looper.cpp プロジェクト: MartinBspheroid/Looper
void Looper::smoothCos()
{
	for (size_t i = 0; i < data.size() - 1; i++)
	{
		data.at(i) = CosineInterpolate(data.at(i), data.at(i + 1), 0.5);
	}

	data.back() = CosineInterpolate(data.back(), data.front(), 0.5);
}
コード例 #2
0
ファイル: perlin.cpp プロジェクト: paud/d2x-xl
double InterpolatedNoise2D (double x, double y)
{
double xInt, yInt,
		 xFrac = modf (x, &xInt),
		 yFrac = modf (x, &yInt);
double v1 = SmoothedNoise2D ((long) xInt, (long) yInt);
double v2 = SmoothedNoise2D ((long) xInt+1, (long) yInt);
double v3 = SmoothedNoise2D ((long) xInt, (long) yInt+1);
double v4 = SmoothedNoise2D ((long) xInt+1, (long) yInt+1);
double i1 = CosineInterpolate (v1, v2, xFrac);
double i2 = CosineInterpolate (v3, v4, xFrac);
return CosineInterpolate (i1, i2, yFrac);
}
コード例 #3
0
ファイル: perlin.cpp プロジェクト: paud/d2x-xl
double InterpolatedNoise1D (double x)
{
double xInt, xFrac = modf (x, &xInt);
double v1 = SmoothedNoise1D ((long) xInt);
double v2 = SmoothedNoise1D ((long) xInt + 1);
return CosineInterpolate (v1, v2, xFrac);
}
コード例 #4
0
ファイル: PerlinNoise.cpp プロジェクト: dreamsxin/ultimatepp
float PerlinNoiseCache::Get(float x, float y, int z) const
{
	int integer_X   	 	= int(x);
	float fractional_X 		= x - integer_X;

	int integer_Y    		= int(y);
	float fractional_Y 		= y - integer_Y;	
	
	float v1 = Get(integer_X,     integer_Y, z);
	float v2 = Get(integer_X + 1, integer_Y, z);
	float v3 = Get(integer_X,     integer_Y + 1, z);
	float v4 = Get(integer_X + 1, integer_Y + 1, z);
	
	float i1 = CosineInterpolate(v1, v2, fractional_X);
	float i2 = CosineInterpolate(v3, v4, fractional_X);

	return CosineInterpolate(i1, i2, fractional_Y);
}
コード例 #5
0
ファイル: PerlinNoise.cpp プロジェクト: dreamsxin/ultimatepp
float PerlinNoise::InterpolatedNoise1(float x, float y) const
{
	int integer_X   	 	= int(x);
	float fractional_X 		= x - integer_X;

	int integer_Y    		= int(y);
	float fractional_Y 		= y - integer_Y;

	float v1 = SmoothNoise1(integer_X,     integer_Y);
	float v2 = SmoothNoise1(integer_X + 1, integer_Y);
	float v3 = SmoothNoise1(integer_X,     integer_Y + 1);
	float v4 = SmoothNoise1(integer_X + 1, integer_Y + 1);

	float i1 = CosineInterpolate(v1, v2, fractional_X);
	float i2 = CosineInterpolate(v3, v4, fractional_X);

	return CosineInterpolate(i1, i2, fractional_Y);
}
コード例 #6
0
ファイル: Noise.cpp プロジェクト: Didey/MCServer
NOISE_DATATYPE cNoise::CosineNoise1D(NOISE_DATATYPE a_X) const
{
	int BaseX = FAST_FLOOR(a_X);
	NOISE_DATATYPE FracX = a_X - BaseX;
	return CosineInterpolate(IntNoise1D(BaseX), IntNoise1D(BaseX + 1), FracX);
}
コード例 #7
0
ファイル: basezone.cpp プロジェクト: smcbeth/Example
void
BaseZone::BaseLevelTerrain_ (float32 maxSmoothingFactor, uint32 aboveGroundHeightLimit)
{
	// SNOW: store sector locations that have had level terrain called on them. if this method is called many times over the same area, various problems in the terrain will result
	uint32 averageTerraHeight;
	uint32 minHeight = revisedHeightMap_[0];
	uint32 maxHeight = minHeight;
	{
		uint32 sum = 0;
		for (uint32 y = 0; y < GetLengthY (); ++y)
		{
			for (uint32 x = 0; x < GetLengthX (); ++x)
			{
				uint32 height = revisedHeightMap_[x + y * GetLengthX ()];
				if (height < minHeight)
					minHeight = height;
				if (height > maxHeight)
					maxHeight = height;
				sum += height;
			}
		}
		averageTerraHeight = sum / (GetLengthX () * GetLengthY ());
	}

	UPoint3D centerPoint;
	centerPoint.x = min_.x + GetLengthX () / 2;
	centerPoint.y = min_.y + GetLengthY () / 2;
	GetWorld()->BeginModify ();
	for (uint32 y = min_.y; y <= max_.y; ++y)
	{
		for (uint32 x = min_.x; x <= max_.x; ++x)
		{
			uint32 distFromCenter = Max (Abs (int32(x) - int32(min_.x + GetLengthX () / 2)), Abs (int32(y) - int32(min_.y + GetLengthY () / 2)));
			uint32 height = (uint16)revisedHeightMap_[(x - min_.x) + (y - min_.y) * GetLengthX ()];

			uint32 smoothHeight = uint32(LinearInterpolate(
											CosineInterpolate (float(averageTerraHeight), float(height), float(distFromCenter) / float(Max (GetLengthX () / 2, GetLengthY () / 2))), 
											float(height), maxSmoothingFactor) + 0.5f);
			
			// slide blocks up or down. some compression or expansion of terrain layers will occur.
			if (height < smoothHeight)
			{
				uint32 difference = smoothHeight - height;
				Vector<uint32> blockStack;
				Vector<uint32> aboveGroundBStack;
				for (uint32 z = height - difference; z <= height; ++z)
					blockStack.InsertBack (GetWorld()->GetSCube (x, y, z));
				for (uint32 z = height + 1; z <= height + aboveGroundHeightLimit; ++z)
					aboveGroundBStack.InsertBack (GetWorld()->GetSCube (x, y, z));

				// expand terrain stack
				bool incrementI = false;
				uint32 i = 0;
				for (uint32 z = height - difference; z <= smoothHeight; ++z)
				{
					GetWorld()->SetSCube (x, y, z, blockStack[i]);
					if (incrementI)
						++i;
					incrementI = !incrementI;
				}
				i = 0;
				for (uint32 z = smoothHeight + 1; z <= smoothHeight + aboveGroundHeightLimit; ++z)
				{
					GetWorld()->SetSCube (x, y, z, aboveGroundBStack[i]);
					++i;
				}
			}
			else if (height > smoothHeight)
			{
				uint32 difference = height - smoothHeight;
				Vector<uint32> blockStack;
				Vector<uint32> aboveGroundBStack;
				for (uint32 z = smoothHeight - difference; z <= height; ++z)
					blockStack.InsertBack (GetWorld()->GetSCube (x, y, z));
				for (uint32 z = height + 1; z <= height + aboveGroundHeightLimit; ++z)
					aboveGroundBStack.InsertBack (GetWorld()->GetSCube (x, y, z));

				// compress terrain stack
				uint32 i = 0;
				for (uint32 z = smoothHeight - difference; z <= height; ++z)
				{
					if (z <= smoothHeight)
					{
						if (z == height || i >= blockStack.GetCount ())
							GetWorld()->SetSCube (x, y, z, blockStack[blockStack.GetCount () - 1]);
						else
							GetWorld()->SetSCube (x, y, z, blockStack[i]);
						i += 2;
					}
					else
					{
						GetWorld()->SetSCube (x, y, z, 0);
					}
				}
				i = 0;
				for (uint32 z = smoothHeight + 1; z <= smoothHeight + aboveGroundHeightLimit; ++z)
				{
					GetWorld()->SetSCube (x, y, z, aboveGroundBStack[i]);
					++i;
				}
			}

			// correct revised height map values
			revisedHeightMap_[(x - min_.x) + (y - min_.y) * GetLengthX ()] = (uint16)smoothHeight;
		}
	}
	GetWorld()->EndModify ();
}
コード例 #8
0
ファイル: UIAnim.cpp プロジェクト: 3rdexp/xsandbox
bool CAnimationSpooler::RenderJob_Flat(const CAnimJobUI* pJob, LPDIRECT3DSURFACE9 /*pSurface*/, DWORD dwTick)
{
   RECT rc = pJob->data.plot.rcFrom;
   FLOAT mu = (FLOAT)(pJob->dwStartTick + pJob->dwDuration - dwTick) / (FLOAT) pJob->dwDuration;
   FLOAT scale1 = 0.0;
   if( pJob->data.plot.iInterpolate == CAnimJobUI::INTERPOLATE_LINEAR ) scale1 = (FLOAT) LinearInterpolate(0.0, 1.0, mu);
   if( pJob->data.plot.iInterpolate == CAnimJobUI::INTERPOLATE_COS ) scale1 = (FLOAT) CosineInterpolate(0.0, 1.0, mu);
   FLOAT scale2 = 1.0f - scale1;
   D3DVECTOR ptCenter = { rc.left + ((rc.right - rc.left) / 2.0f), rc.top + ((rc.bottom - rc.top) / 2.0f) };
   FLOAT xtrans = (FLOAT) pJob->data.plot.mFrom.xtrans * scale1;
   FLOAT ytrans = (FLOAT) pJob->data.plot.mFrom.ytrans * scale1;
   FLOAT ztrans = 1.0f + ((FLOAT) abs(pJob->data.plot.mFrom.ztrans) * (pJob->data.plot.mFrom.ztrans >= 0.0 ? scale1 : scale2));
   FLOAT fSin = (FLOAT) sin(pJob->data.plot.mFrom.zrot * scale1);
   FLOAT fCos = (FLOAT) cos(pJob->data.plot.mFrom.zrot * scale1);
   DWORD clrAlpha = ((DWORD)(0xFF - (FLOAT) abs(pJob->data.plot.mFrom.alpha) * (pJob->data.plot.mFrom.alpha >= 0 ? scale1 : scale2)) << 24) | 0xffffff;
   HRESULT Hr = 0;
   for( int iBuffer = pJob->iBufferStart; iBuffer < pJob->iBufferEnd; iBuffer++ ) {
      // Lock the vertex buffer and apply transformation
      LPDIRECT3DVERTEXBUFFER9 pVBuffer = m_p3DVertices[iBuffer];
      LPVOID pVertices = NULL;
      Hr = pVBuffer->Lock(0, sizeof(CUSTOMFAN), &pVertices, 0);
      if( FAILED(Hr) ) return false;
      CUSTOMFAN verts;
      memcpy(verts, m_fans[iBuffer], sizeof(CUSTOMFAN));
      for( int i = 0; i < sizeof(CUSTOMFAN) / sizeof(CUSTOMVERTEX); i++ ) {
         verts[i].x -= ptCenter.x;
         verts[i].y -= ptCenter.y;
         verts[i].x += xtrans;                         // Translate
         verts[i].y += ytrans;
         verts[i].x = verts[i].x * ztrans;             // Scale
         verts[i].y = verts[i].y * ztrans;
         FLOAT x = verts[i].x; FLOAT y = verts[i].y;   // Rotate around Z
         verts[i].x = x * fCos - y * fSin;
         verts[i].y = x * fSin + y * fCos;
         verts[i].x += ptCenter.x;
         verts[i].y += ptCenter.y;
         verts[i].color = clrAlpha;
      }
      memcpy(pVertices, verts, sizeof(CUSTOMFAN));
      pVBuffer->Unlock();
      // Paint it
      Hr = m_p3DDevice->SetStreamSource(0, pVBuffer, 0, sizeof(CUSTOMVERTEX));
      Hr = m_p3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
      Hr = m_p3DDevice->SetTexture(0, m_p3DTextures[iBuffer]);
      Hr = m_p3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
   }
   return true;
}