예제 #1
0
파일: world.c 프로젝트: NotGyro/GameOfLife
void Update(World *const w)
{
	for(int y = 0; y < w->height; ++y)
	{
		for(int x = 0; x < w->width; ++x)
		{
			UpdateCell(w, x, y);
		}
	}
	FlipBuffers(w);	
}
예제 #2
0
void cVoronoiMap::FindNearestSeeds(
	int a_X, int a_Y,
	int & a_NearestSeedX, int & a_NearestSeedY,
	int & a_SecondNearestSeedX, int & a_SecondNearestSeedY
)
{
	int CellX = a_X / m_CellSize;
	int CellY = a_Y / m_CellSize;

	UpdateCell(CellX, CellY);

	// Get 5x5 neighboring cell seeds, compare distance to each. Return the value in the minumim-distance cell
	int NearestSeedX = 0, NearestSeedY = 0;
	int SecondNearestSeedX = 0, SecondNearestSeedY = 0;
	int MinDist = m_CellSize * m_CellSize * 16;  // There has to be a cell closer than this
	int MinDist2 = MinDist;
	for (int x = 0; x < 5; x++)
	{
		for (int y = 0; y < 5; y++)
		{
			int SeedX = m_SeedX[x][y];
			int SeedY = m_SeedZ[x][y];

			int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedY - a_Y) * (SeedY - a_Y);
			if (Dist < MinDist)
			{
				SecondNearestSeedX = NearestSeedX;
				SecondNearestSeedY = NearestSeedY;
				MinDist2 = MinDist;
				NearestSeedX = SeedX;
				NearestSeedY = SeedY;
				MinDist = Dist;
			}
			else if (Dist < MinDist2)
			{
				SecondNearestSeedX = SeedX;
				SecondNearestSeedY = SeedY;
				MinDist2 = Dist;
			}
		}  // for z
	}  // for x

	a_NearestSeedX = NearestSeedX;
	a_NearestSeedY = NearestSeedY;
	a_SecondNearestSeedX = SecondNearestSeedX;
	a_SecondNearestSeedY = SecondNearestSeedY;
}
예제 #3
0
파일: box.C 프로젝트: avoronts/hard_spheres
//==============================================================
// Transfer, takes care of boundary events too
//=============================================================
void box::Transfer(event e)
{
  gtime = e.time;
  int i = e.i;
  int j = e.j;
  int k=0;           // dimension perpendicular to wall it crosses
 
  // update position and lutime (velocity doesn't change)
  s[i].x += s[i].v*(gtime-s[i].lutime);
  s[i].xns += s[i].v*(gtime-s[i].lutime); // !!!!!!!!!!!!  added  by A. Vorontsov
  s[i].lutime = gtime;

  vector<DIM,int> celli;  // new cell for i
  celli = s[i].cell;  // this is not redundant
  
  // update cell
  if (j>N+DIM+1)  // right wall
    {
      k = j-N-DIM-2;
      celli[k] = s[i].cell[k] + 1;

      // if in right-most cell, translate x and cell
      if (s[i].cell[k] == ngrids - 1)
	{
	  s[i].x[k] -= SIZE;
	  celli[k] -= ngrids;
	}
    }
  else if (j<N+DIM+1)  // left wall
    {
      k = -j+N+DIM;
      celli[k] = s[i].cell[k] - 1;

      // if in left-most cell, translate x and cell
      if (s[i].cell[k] == 0)
	{
	  s[i].x[k] += SIZE;
	  celli[k] += ngrids;
	}
    }
  else
    std::cout << "error in Transfer" << std::endl;
      
  UpdateCell(i, celli); 
}
예제 #4
0
int cVoronoiMap::GetValueAt(
	int a_X, int a_Y,  // Coords to query
	int & a_NearestSeedX, int & a_NearestSeedY,  // Coords of the closest cell
	int & a_MinDist2  // Distance to the second closest cell
)
{
	int CellX = a_X / m_CellSize;
	int CellY = a_Y / m_CellSize;

	UpdateCell(CellX, CellY);

	// Get 5x5 neighboring cell seeds, compare distance to each. Return the value in the minumim-distance cell
	int NearestSeedX = 0, NearestSeedY = 0;
	int MinDist = m_CellSize * m_CellSize * 16;  // There has to be a cell closer than this
	int MinDist2 = MinDist;
	int res = 0;  // Will be overriden
	for (int x = 0; x < 5; x++)
	{
		for (int y = 0; y < 5; y++)
		{
			int SeedX = m_SeedX[x][y];
			int SeedY = m_SeedZ[x][y];

			int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedY - a_Y) * (SeedY - a_Y);
			if (Dist < MinDist)
			{
				NearestSeedX = SeedX;
				NearestSeedY = SeedY;
				MinDist2 = MinDist;
				MinDist = Dist;
				res = m_Noise3.IntNoise2DInt(x + CellX - 2, y + CellY - 2);
			}
			else if (Dist < MinDist2)
			{
				MinDist2 = Dist;
			}
		}  // for z
	}  // for x

	a_NearestSeedX = NearestSeedX;
	a_NearestSeedY = NearestSeedY;
	a_MinDist2 = MinDist2;
	return res;
}
예제 #5
0
int cVoronoiMap::GetValueAt(int a_X, int a_Y, int & a_MinDist1, int & a_MinDist2)
{
	// Note that due to historical reasons, the algorithm uses XZ coords, while the input uses XY coords.
	// This is because the algorithm was first implemented directly in the biome generators which use MC coords.
	
	int CellX = a_X / m_CellSize;
	int CellZ = a_Y / m_CellSize;
	
	UpdateCell(CellX, CellZ);
	
	// Get 5x5 neighboring cell seeds, compare distance to each. Return the value in the minumim-distance cell
	int MinDist = m_CellSize * m_CellSize * 16;  // There has to be a cell closer than this
	int MinDist2 = MinDist;
	int res = 0;  // Will be overriden
	for (int x = 0; x < 5; x++)
	{
		for (int z = 0; z < 5; z++)
		{
			int SeedX = m_SeedX[x][z];
			int SeedZ = m_SeedZ[x][z];
			
			int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedZ - a_Y) * (SeedZ - a_Y);
			if (Dist < MinDist)
			{
				MinDist2 = MinDist;
				MinDist = Dist;
				res = m_Noise3.IntNoise2DInt(x + CellX - 2, z + CellZ - 2);
			}
			else if (Dist < MinDist2)
			{
				MinDist2 = Dist;
			}
		}  // for z
	}  // for x

	a_MinDist1 = MinDist;
	a_MinDist2 = MinDist2;
	return res;
}