コード例 #1
0
ファイル: boltzmann_test.cpp プロジェクト: davnils/kex-sudoku
int main()
{
  grid_t g;

  for(int i = 0; i < 9; i++) {
    for(int j = 0; j < 9; j++) {
      g.grid[i][j] = 0;
    }
  }

  g.grid[2][0] = 8;
  g.grid[3][0] = 2;
  g.grid[8][0] = 5;
  g.grid[4][1] = 6;
  g.grid[6][1] = 1;
  g.grid[8][1] = 4;
  g.grid[0][2] = 9;
  g.grid[2][2] = 4;
  g.grid[4][2] = 1;
  g.grid[6][2] = 7;
  g.grid[8][2] = 8;
  g.grid[0][3] = 4;
  g.grid[6][3] = 5;
  g.grid[2][4] = 2;
  g.grid[3][4] = 5;
  g.grid[5][4] = 3;
  g.grid[7][4] = 8;
  g.grid[8][4] = 1;
  g.grid[0][5] = 5;
  g.grid[4][5] = 8;
  g.grid[7][5] = 7;
  g.grid[2][6] = 1;
  g.grid[3][6] = 9;
  g.grid[7][6] = 5;
  g.grid[3][7] = 1;
  g.grid[1][8] = 5;
  g.grid[2][8] = 9;
  g.grid[3][8] = 8;
  g.grid[5][8] = 2;
  g.grid[7][8] = 1;
  g.grid[8][8] = 3;

  Boltzmann solver(g);

  while(1) {
    solver.simulate(false);
    dumpGrid(solver.getGrid());
  }
}
コード例 #2
0
static byte_t * getRawHeightfieldData(eTerrainModel model, PHY_ScalarType type, btScalar& minHeight, btScalar& maxHeight){
//	std::cerr << "\nRegenerating terrain\n";
//	std::cerr << "  model = " << model << "\n";
//	std::cerr << "  type = " << type << "\n";

	long nElements = ((long) s_gridSize) * s_gridSize;
//	std::cerr << "  nElements = " << nElements << "\n";

	int bytesPerElement = sizeof(float);
//	std::cerr << "  bytesPerElement = " << bytesPerElement << "\n";
	btAssert(bytesPerElement > 0 && "bad bytes per element");

	long nBytes = nElements * bytesPerElement;
//	std::cerr << "  nBytes = " << nBytes << "\n";
	byte_t * raw = new byte_t[nBytes];
	btAssert(raw && "out of memory");

	// reseed randomization every 30 seconds
//	srand(time(NULL) / 30);

	// populate based on model
	setRadial(raw, bytesPerElement, type);

	if (0) {
		// inside if(0) so it keeps compiling but isn't
		// 	exercised and doesn't cause warnings
//		std::cerr << "final grid:\n";
		dumpGrid(raw, bytesPerElement, type, s_gridSize - 1);
	}

	// find min/max
	for (int i = 0; i < s_gridSize; ++i) {
		for (int j = 0; j < s_gridSize; ++j) {
			float z = getGridHeight(raw, i, j, type);
//			std::cerr << "i=" << i << ", j=" << j << ": z=" << z << "\n";

			// update min/max
			if (!i && !j) {
				minHeight = z;
				maxHeight = z;
			} else {
				if (z < minHeight) {
					minHeight = z;
				}
				if (z > maxHeight) {
					maxHeight = z;
				}
			}
		}
	}

	if (maxHeight < -minHeight) {
		maxHeight = -minHeight;
	}
	if (minHeight > -maxHeight) {
		minHeight = -maxHeight;
	}

//	std::cerr << "  minHeight = " << minHeight << "\n";
//	std::cerr << "  maxHeight = " << maxHeight << "\n";

	return raw;
}