Пример #1
0
void Texture::setHgtMap(IMesh *mesh, std::string filename, float height)
{
	int mapWidth, mapHeight;
	long *data = FileBmp::loadBmp(filename, mapWidth, mapHeight);
	float r = (float) 1 / 255;
	Vector *v = mesh->getVertices();
	for (int i = 0; i < mesh->mVertCnt; i++)
	{
		int x = map_linear(v[i].x, mesh->mMin.x, mesh->mMax.x, mapWidth - 1, 0);
		int y = map_linear(v[i].z, mesh->mMin.z, mesh->mMax.z, 0, mapHeight - 1);
		long c = data[y * mapWidth + x];
		v[i].y = getR(c) * r * height;
		mesh->setVertex(i, v[i].x, v[i].y, v[i].z);
	}
	delete []data;
}
Пример #2
0
/**
 * IMPORTANT: This function sets the value for g_tw_nlp which is a rather
 * important global variable.  It is also set in (very few) other places,
 * but mainly just here.
 */
void
tw_define_lps(tw_lpid nlp, size_t msg_sz, tw_seed * seed)
{
	int	 i;

	g_tw_nlp = nlp;
	
#ifdef ROSS_MEMORY
	g_tw_memory_sz = sizeof(tw_memory);
#endif

	g_tw_msg_sz = msg_sz;
	g_tw_rng_seed = seed;

	early_sanity_check();

	/*
	 * Construct the KP array.
	 */
	if( g_tw_nkp == 1 ) // if it is the default, then check with the overide param
	  g_tw_nkp = nkp_per_pe * g_tw_npe;
	// else assume the application overloaded and has BRAINS to set its own g_tw_nkp

	g_tw_kp = (tw_kp **)tw_calloc(TW_LOC, "KPs", sizeof(*g_tw_kp), g_tw_nkp);

	/*
	 * Construct the LP array.
	 */
	g_tw_lp = (tw_lp **)tw_calloc(TW_LOC, "LPs", sizeof(*g_tw_lp), g_tw_nlp);

	switch(g_tw_mapping)
	  {
	  case LINEAR:
	    map_linear();
	    break;
	    
	  case ROUND_ROBIN:
	    map_round_robin();
	    break;
	    
	  case CUSTOM:
	    if( g_tw_custom_initial_mapping )
	      {
		g_tw_custom_initial_mapping();
	      }
	    else
	      {
		tw_error(TW_LOC, "CUSTOM mapping flag set but not custom mapping function! \n");
	      }
	    break;
	    
	  default:
	    tw_error(TW_LOC, "Bad value for g_tw_mapping %d \n", g_tw_mapping);
	  }

	// init LP RNG stream(s)
	for(i = 0; i < g_tw_nlp; i++)
		if(g_tw_rng_default == TW_TRUE)
			tw_rand_init_streams(g_tw_lp[i], g_tw_nRNG_per_lp);
}