예제 #1
0
bool CFXBoxBlur::LoadData(CResourceList* pResourceList)
{
	// Force width and height to be powers of two. log2(x) = log10(x) / log10(2)

	CVarInt::CValueInt valueInt;

	EvaluateVar("BlurTexture Width",  0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nWidthPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	EvaluateVar("BlurTexture Height", 0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nHeightPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	int nWidth  = pow(2, nWidthPwr);
	int nHeight = pow(2, nHeightPwr);

	// Create texture

	UtilGL::Texturing::STexLoadOptions texOptions;
	texOptions.SetDefaults();
	texOptions.eFilter = UtilGL::Texturing::FILTER_LINEAR;

	m_texture.LoadFlat(nWidth, nHeight, CVector4(0.0f, 0.0f, 0.0f, 1.0f), false, false, &texOptions);

	return true;
}
예제 #2
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundModule
//  - prototype : bool SetVolume(float fPercentage)
//
//  - Purpose   : Sets the volume (percentage) of the sound module.
//
// -----------------------------------------------------------------------------
bool CSoundModule::SetVolume(float fPercentage)
{
    if(!IsValid())
    {
        return false;
    }

    return BASS_ChannelSetAttributes(m_handle, -1, MYROUND(fPercentage), -101) == TRUE;
}
예제 #3
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundSystem
//  - prototype : bool SetMasterVolume(float fPercentage)
//
//  - Purpose   : Sets the master volume (percentage).
//
// -----------------------------------------------------------------------------
bool CSoundSystem::SetMasterVolume(float fPercentage)
{
    if(m_bActive == false)
    {
        return false;
    }

    return BASS_SetVolume(MYROUND(fPercentage * 2.55f)) == TRUE;
}
예제 #4
0
파일: farmesh.cpp 프로젝트: Neear/minetest
void FarMesh::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	/*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
		return;*/
	if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
		return;
	/*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SKY_BOX)
		return;*/

	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	
	//const s16 grid_radius_i = 12;
	//const float grid_size = BS*50;
	const s16 grid_radius_i = m_render_range/MAP_BLOCKSIZE;
	const float grid_size = BS*MAP_BLOCKSIZE;
	const v2f grid_speed(-BS*0, 0);
	
	// Position of grid noise origin in world coordinates
	v2f world_grid_origin_pos_f(0,0);
	// Position of grid noise origin from the camera
	v2f grid_origin_from_camera_f = world_grid_origin_pos_f - m_camera_pos;
	// The center point of drawing in the noise
	v2f center_of_drawing_in_noise_f = -grid_origin_from_camera_f;
	// The integer center point of drawing in the noise
	v2s16 center_of_drawing_in_noise_i(
		MYROUND(center_of_drawing_in_noise_f.X / grid_size),
		MYROUND(center_of_drawing_in_noise_f.Y / grid_size)
	);
	// The world position of the integer center point of drawing in the noise
	v2f world_center_of_drawing_in_noise_f = v2f(
		center_of_drawing_in_noise_i.X * grid_size,
		center_of_drawing_in_noise_i.Y * grid_size
	) + world_grid_origin_pos_f;

	for(s16 zi=-grid_radius_i; zi<grid_radius_i; zi++)
	for(s16 xi=-grid_radius_i; xi<grid_radius_i; xi++)
	{
		/*// Don't draw very close to player
		s16 dd = 3;
		if(zi > -dd && zi < dd && xi > -dd && xi < dd)
			continue;*/

		v2s16 p_in_noise_i(
			xi+center_of_drawing_in_noise_i.X,
			zi+center_of_drawing_in_noise_i.Y
		);
		
		// If sector was drawn, don't draw it this way
		if(m_client->m_env.getClientMap().sectorWasDrawn(p_in_noise_i))
			continue;

		/*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0)
			continue;*/
		/*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0)
			continue;*/

		v2f p0 = v2f(xi,zi)*grid_size + world_center_of_drawing_in_noise_f;
		
		/*double noise[4];
		double d = 100*BS;
		noise[0] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+0)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+0)*grid_size/BS/100,
				m_seed, 3, 0.5);
		
		noise[1] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+0)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+1)*grid_size/BS/100,
				m_seed, 3, 0.5);
		
		noise[2] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+1)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+1)*grid_size/BS/100,
				m_seed, 3, 0.5);
		
		noise[3] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+1)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+0)*grid_size/BS/100,
				m_seed, 3, 0.5);*/
		
		HeightPoint hps[5];
		hps[0] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+0)*grid_size/BS,
				(p_in_noise_i.Y+0)*grid_size/BS));
		hps[1] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+0)*grid_size/BS,
				(p_in_noise_i.Y+1)*grid_size/BS));
		hps[2] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+1)*grid_size/BS,
				(p_in_noise_i.Y+1)*grid_size/BS));
		hps[3] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+1)*grid_size/BS,
				(p_in_noise_i.Y+0)*grid_size/BS));
		v2s16 centerpoint(
				(p_in_noise_i.X+0)*grid_size/BS+MAP_BLOCKSIZE/2,
				(p_in_noise_i.Y+0)*grid_size/BS+MAP_BLOCKSIZE/2);
		hps[4] = ground_height(m_seed, centerpoint);
		
		float noise[5];
		float h_min = BS*65535;
		float h_max = -BS*65536;
		float ma_avg = 0;
		float h_avg = 0;
		u32 have_sand_count = 0;
		float tree_amount_avg = 0;
		for(u32 i=0; i<5; i++)
		{
			noise[i] = hps[i].gh + hps[i].ma;
			if(noise[i] < h_min)
				h_min = noise[i];
			if(noise[i] > h_max)
				h_max = noise[i];
			ma_avg += hps[i].ma;
			h_avg += noise[i];
			if(hps[i].have_sand)
				have_sand_count++;
			tree_amount_avg += hps[i].tree_amount;
		}
		ma_avg /= 5.0;
		h_avg /= 5.0;
		tree_amount_avg /= 5.0;

		float steepness = (h_max - h_min)/grid_size;
		
		float light_f = noise[0]+noise[1]-noise[2]-noise[3];
		light_f /= 100;
		if(light_f < -1.0) light_f = -1.0;
		if(light_f > 1.0) light_f = 1.0;
		//light_f += 1.0;
		//light_f /= 2.0;
		
		v2f p1 = p0 + v2f(1,1)*grid_size;
		
		bool ground_is_sand = false;
		bool ground_is_rock = false;
		bool ground_is_mud = false;
		video::SColor c;
		// Detect water
		if(h_avg < WATER_LEVEL*BS && h_max < (WATER_LEVEL+5)*BS)
		{
			//c = video::SColor(255,59,86,146);
			//c = video::SColor(255,82,120,204);
			c = video::SColor(255,74,105,170);

			/*// Set to water level
			for(u32 i=0; i<4; i++)
			{
				if(noise[i] < BS*WATER_LEVEL)
					noise[i] = BS*WATER_LEVEL;
			}*/
			light_f = 0;
		}
		// Steep cliffs
		else if(steepness > 2.0)
		{
			c = video::SColor(255,128,128,128);
			ground_is_rock = true;
		}
		// Basic ground
		else
		{
			if(ma_avg < 2.0*BS)
			{
				c = video::SColor(255,128,128,128);
				ground_is_rock = true;
			}
			else
			{
				if(h_avg <= 2.5*BS && have_sand_count >= 2)
				{
					c = video::SColor(255,210,194,156);
					ground_is_sand = true;
				}
				else
				{
					/*// Trees if there are over 0.01 trees per MapNode
					if(tree_amount_avg > 0.01)
						c = video::SColor(255,50,128,50);
					else
						c = video::SColor(255,107,134,51);*/
					c = video::SColor(255,107,134,51);
					ground_is_mud = true;
				}
			}
		}
		
		// Set to water level
		for(u32 i=0; i<4; i++)
		{
			if(noise[i] < BS*WATER_LEVEL)
				noise[i] = BS*WATER_LEVEL;
		}

		float b = m_brightness + light_f*0.1*m_brightness;
		if(b < 0) b = 0;
		if(b > 2) b = 2;
		
		c = video::SColor(255, b*c.getRed(), b*c.getGreen(), b*c.getBlue());
		
		driver->setMaterial(m_materials[0]);

		video::S3DVertex vertices[4] =
		{
			video::S3DVertex(p0.X,noise[0],p0.Y, 0,0,0, c, 0,1),
			video::S3DVertex(p0.X,noise[1],p1.Y, 0,0,0, c, 1,1),
			video::S3DVertex(p1.X,noise[2],p1.Y, 0,0,0, c, 1,0),
			video::S3DVertex(p1.X,noise[3],p0.Y, 0,0,0, c, 0,0),
		};
		u16 indices[] = {0,1,2,2,3,0};
		driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
				video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);

		// Add some trees if appropriate
		if(tree_amount_avg >= 0.0065 && steepness < 1.4
				&& ground_is_mud == true)
		{
			driver->setMaterial(m_materials[1]);
			
			float b = m_brightness;
			c = video::SColor(255, b*255, b*255, b*255);
			
			{
				video::S3DVertex vertices[4] =
				{
					video::S3DVertex(p0.X,noise[0],p0.Y,
							0,0,0, c, 0,1),
					video::S3DVertex(p0.X,noise[0]+BS*MAP_BLOCKSIZE,p0.Y,
							0,0,0, c, 0,0),
					video::S3DVertex(p1.X,noise[2]+BS*MAP_BLOCKSIZE,p1.Y,
							0,0,0, c, 1,0),
					video::S3DVertex(p1.X,noise[2],p1.Y,
							0,0,0, c, 1,1),
				};
				u16 indices[] = {0,1,2,2,3,0};
				driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
						video::EVT_STANDARD, scene::EPT_TRIANGLES,
						video::EIT_16BIT);
			}
			{
				video::S3DVertex vertices[4] =
				{
					video::S3DVertex(p1.X,noise[3],p0.Y,
							0,0,0, c, 0,1),
					video::S3DVertex(p1.X,noise[3]+BS*MAP_BLOCKSIZE,p0.Y,
							0,0,0, c, 0,0),
					video::S3DVertex(p0.X,noise[1]+BS*MAP_BLOCKSIZE,p1.Y,
							0,0,0, c, 1,0),
					video::S3DVertex(p0.X,noise[1],p1.Y,
							0,0,0, c, 1,1),
				};
				u16 indices[] = {0,1,2,2,3,0};
				driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
						video::EVT_STANDARD, scene::EPT_TRIANGLES,
						video::EIT_16BIT);
			}
		}
	}

	//driver->clearZBuffer();
}
예제 #5
0
void Clouds::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
	//if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
		return;

	ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);
	
	bool enable_3d = g_settings->getBool("enable_3d_clouds");
	int num_faces_to_draw = enable_3d ? 6 : 1;
	
	m_material.setFlag(video::EMF_BACK_FACE_CULLING, enable_3d);

	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	driver->setMaterial(m_material);
	
	/*
		Clouds move from X+ towards X-
	*/

	const s16 cloud_radius_i = 12;
	const float cloud_size = BS*64;
	const v2f cloud_speed(0, -BS*2);
	
	const float cloud_full_radius = cloud_size * cloud_radius_i;
	
	// Position of cloud noise origin in world coordinates
	v2f world_cloud_origin_pos_f = m_time*cloud_speed;
	// Position of cloud noise origin from the camera
	v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos;
	// The center point of drawing in the noise
	v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f;
	// The integer center point of drawing in the noise
	v2s16 center_of_drawing_in_noise_i(
		MYROUND(center_of_drawing_in_noise_f.X / cloud_size),
		MYROUND(center_of_drawing_in_noise_f.Y / cloud_size)
	);
	// The world position of the integer center point of drawing in the noise
	v2f world_center_of_drawing_in_noise_f = v2f(
		center_of_drawing_in_noise_i.X * cloud_size,
		center_of_drawing_in_noise_i.Y * cloud_size
	) + world_cloud_origin_pos_f;

	/*video::SColor c_top(128,b*240,b*240,b*255);
	video::SColor c_side_1(128,b*230,b*230,b*255);
	video::SColor c_side_2(128,b*220,b*220,b*245);
	video::SColor c_bottom(128,b*205,b*205,b*230);*/
	video::SColorf c_top_f(m_color);
	video::SColorf c_side_1_f(m_color);
	video::SColorf c_side_2_f(m_color);
	video::SColorf c_bottom_f(m_color);
	c_side_1_f.r *= 0.95;
	c_side_1_f.g *= 0.95;
	c_side_1_f.b *= 0.95;
	c_side_2_f.r *= 0.90;
	c_side_2_f.g *= 0.90;
	c_side_2_f.b *= 0.90;
	c_bottom_f.r *= 0.80;
	c_bottom_f.g *= 0.80;
	c_bottom_f.b *= 0.80;
	c_top_f.a = 0.9;
	c_side_1_f.a = 0.9;
	c_side_2_f.a = 0.9;
	c_bottom_f.a = 0.9;
	video::SColor c_top = c_top_f.toSColor();
	video::SColor c_side_1 = c_side_1_f.toSColor();
	video::SColor c_side_2 = c_side_2_f.toSColor();
	video::SColor c_bottom = c_bottom_f.toSColor();

	// Get fog parameters for setting them back later
	video::SColor fog_color(0,0,0,0);
	video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR;
	f32 fog_start = 0;
	f32 fog_end = 0;
	f32 fog_density = 0;
	bool fog_pixelfog = false;
	bool fog_rangefog = false;
	driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density,
			fog_pixelfog, fog_rangefog);
	
	// Set our own fog
	driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
			cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog);

	// Read noise

	bool *grid = new bool[cloud_radius_i*2*cloud_radius_i*2];

	for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
	for(s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++)
	{
		u32 i = (zi+cloud_radius_i)*cloud_radius_i*2 + xi+cloud_radius_i;

		v2s16 p_in_noise_i(
			xi+center_of_drawing_in_noise_i.X,
			zi+center_of_drawing_in_noise_i.Y
		);

#if 0
		double noise = noise2d_perlin_abs(
				(float)p_in_noise_i.X*cloud_size/BS/200,
				(float)p_in_noise_i.Y*cloud_size/BS/200,
				m_seed, 3, 0.4);
		grid[i] = (noise >= 0.80);
#endif
#if 1
		double noise = noise2d_perlin(
				(float)p_in_noise_i.X*cloud_size/BS/200,
				(float)p_in_noise_i.Y*cloud_size/BS/200,
				m_seed, 3, 0.5);
		grid[i] = (noise >= 0.4);
#endif
	}

#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
#define INAREA(x, z, radius) \
	((x) >= -(radius) && (x) < (radius) && (z) >= -(radius) && (z) < (radius))

	for(s16 zi0=-cloud_radius_i; zi0<cloud_radius_i; zi0++)
	for(s16 xi0=-cloud_radius_i; xi0<cloud_radius_i; xi0++)
	{
		s16 zi = zi0;
		s16 xi = xi0;
		// Draw from front to back (needed for transparency)
		/*if(zi <= 0)
			zi = -cloud_radius_i - zi;
		if(xi <= 0)
			xi = -cloud_radius_i - xi;*/
		// Draw from back to front
		if(zi >= 0)
			zi = cloud_radius_i - zi - 1;
		if(xi >= 0)
			xi = cloud_radius_i - xi - 1;

		u32 i = GETINDEX(xi, zi, cloud_radius_i);

		if(grid[i] == false)
			continue;

		v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;

		video::S3DVertex v[4] = {
			video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
		};

		/*if(zi <= 0 && xi <= 0){
			v[0].Color.setBlue(255);
			v[1].Color.setBlue(255);
			v[2].Color.setBlue(255);
			v[3].Color.setBlue(255);
		}*/

		f32 rx = cloud_size/2;
		f32 ry = 8*BS;
		f32 rz = cloud_size/2;

		for(int i=0; i<num_faces_to_draw; i++)
		{
			switch(i)
			{
			case 0:	// top
				for(int j=0;j<4;j++){
					v[j].Normal.set(0,1,0);
				}
				v[0].Pos.set(-rx, ry,-rz);
				v[1].Pos.set(-rx, ry, rz);
				v[2].Pos.set( rx, ry, rz);
				v[3].Pos.set( rx, ry,-rz);
				break;
			case 1: // back
				if(INAREA(xi, zi-1, cloud_radius_i)){
					u32 j = GETINDEX(xi, zi-1, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_1;
					v[j].Normal.set(0,0,-1);
				}
				v[0].Pos.set(-rx, ry,-rz);
				v[1].Pos.set( rx, ry,-rz);
				v[2].Pos.set( rx,-ry,-rz);
				v[3].Pos.set(-rx,-ry,-rz);
				break;
			case 2: //right
				if(INAREA(xi+1, zi, cloud_radius_i)){
					u32 j = GETINDEX(xi+1, zi, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_2;
					v[j].Normal.set(1,0,0);
				}
				v[0].Pos.set( rx, ry,-rz);
				v[1].Pos.set( rx, ry, rz);
				v[2].Pos.set( rx,-ry, rz);
				v[3].Pos.set( rx,-ry,-rz);
				break;
			case 3: // front
				if(INAREA(xi, zi+1, cloud_radius_i)){
					u32 j = GETINDEX(xi, zi+1, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_1;
					v[j].Normal.set(0,0,-1);
				}
				v[0].Pos.set( rx, ry, rz);
				v[1].Pos.set(-rx, ry, rz);
				v[2].Pos.set(-rx,-ry, rz);
				v[3].Pos.set( rx,-ry, rz);
				break;
			case 4: // left
				if(INAREA(xi-1, zi, cloud_radius_i)){
					u32 j = GETINDEX(xi-1, zi, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_2;
					v[j].Normal.set(-1,0,0);
				}
				v[0].Pos.set(-rx, ry, rz);
				v[1].Pos.set(-rx, ry,-rz);
				v[2].Pos.set(-rx,-ry,-rz);
				v[3].Pos.set(-rx,-ry, rz);
				break;
			case 5: // bottom
				for(int j=0;j<4;j++){
					v[j].Color = c_bottom;
					v[j].Normal.set(0,-1,0);
				}
				v[0].Pos.set( rx,-ry, rz);
				v[1].Pos.set(-rx,-ry, rz);
				v[2].Pos.set(-rx,-ry,-rz);
				v[3].Pos.set( rx,-ry,-rz);
				break;
			}

			v3f pos(p0.X, m_cloud_y, p0.Y);
			pos -= intToFloat(m_camera_offset, BS);

			for(u16 i=0; i<4; i++)
				v[i].Pos += pos;
			u16 indices[] = {0,1,2,2,3,0};
			driver->drawVertexPrimitiveList(v, 4, indices, 2,
					video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
		}
	}

	delete[] grid;
	
	// Restore fog settings
	driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,
			fog_pixelfog, fog_rangefog);
}
bool CFXTransExplodingCubes::LoadData(CResourceList* pResourceList)
{
	// Create RTT Texture

	CVarInt::CValueInt valueInt;

	EvaluateVar("RenderTex Width",  0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nWidthPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	EvaluateVar("RenderTex Height", 0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nHeightPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	int nWidth  = pow(2, nWidthPwr);
	int nHeight = pow(2, nHeightPwr);

	UtilGL::Texturing::STexLoadOptions texOptions;
	texOptions.SetDefaults();
	texOptions.eFilter = UtilGL::Texturing::FILTER_LINEAR;

	m_textureRTT.LoadFlat(nWidth, nHeight, CVector4(0.0f, 0.0f, 0.0f, 1.0f), false, false, &texOptions);

	// Create cubes

	CVarInt::CValueInt     valueXCubes;
	CVarInt::CValueInt     valueYCubes;
	CVarInt::CValueInt     valueSeed;
	CVarFloat::CValueFloat valueAngleMultiple;
	CVarFloat::CValueFloat valueDepth;
	CVarFloat::CValueFloat valueAngleStep;

	CVarFloat::CValueFloat valueAccelX;
	CVarFloat::CValueFloat valueAccelY;
	CVarFloat::CValueFloat valueAccelZ;
	CVarFloat::CValueFloat valueSpeedX;
	CVarFloat::CValueFloat valueSpeedY;
	CVarFloat::CValueFloat valueSpeedZ;
	CVarFloat::CValueFloat valueAssimetry;
	CVarFloat::CValueFloat valueMaxRotation;
	CVarFloat::CValueFloat valueVariation;

	EvaluateVar("X Cubes",        0.0f, &valueXCubes);
	EvaluateVar("Y Cubes",        0.0f, &valueYCubes);
	EvaluateVar("Seed",		      0.0f, &valueSeed);
	EvaluateVar("Z Depth",        0.0f, &valueDepth);
	EvaluateVar("Angle Step",     0.0f, &valueAngleStep);
	EvaluateVar("Accel X",        0.0f, &valueAccelX);
	EvaluateVar("Accel Y",        0.0f, &valueAccelY);
	EvaluateVar("Accel Z",        0.0f, &valueAccelZ);
	EvaluateVar("Start Speed X",  0.0f, &valueSpeedX);
	EvaluateVar("Start Speed Y",  0.0f, &valueSpeedY);
	EvaluateVar("Start Speed Z",  0.0f, &valueSpeedZ);
	EvaluateVar("Assimetry",      0.0f, &valueAssimetry);
	EvaluateVar("Max Rotation",   0.0f, &valueMaxRotation);
	EvaluateVar("Variation",      0.0f, &valueVariation);

	CVector3 v3Accel(valueAccelX.GetValue(), valueAccelY.GetValue(), valueAccelZ.GetValue());
	CVector3 v3Speed(valueSpeedX.GetValue(), valueSpeedY.GetValue(), valueSpeedZ.GetValue());

	int xRes = valueXCubes.GetValue() > 1 ? valueXCubes.GetValue() : 1;
	int yRes = valueYCubes.GetValue() > 1 ? valueYCubes.GetValue() : 1;

	float fSizeX = 1.0f / xRes;
	float fSizeY = 1.0f / yRes;

	srand(valueSeed.GetValue());

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0f, 1.33f, 1.0f, 100.0f);

	UtilGL::Transforming::ClearMatrix(UtilGL::Transforming::MATRIX_WORLD);
	UtilGL::Transforming::ClearMatrix(UtilGL::Transforming::MATRIX_VIEW);

	for(int y = 0; y < yRes; y++)
	{
		for(int x = 0; x < xRes; x++)
		{
			SCube cube;

			cube.fU  = x * fSizeX;
			cube.fV  = 1.0f - (y * fSizeY);
			cube.fU2 = x * fSizeX + fSizeX;
			cube.fV2 = 1.0f - (y * fSizeY + fSizeY);

			CVector3 upLeft  (x * fSizeX,          y * fSizeY,          0.5f);
			CVector3 botRight(x * fSizeX + fSizeX, y * fSizeY + fSizeY, 0.5f);

			UtilGL::Transforming::NormViewportToLocal(&upLeft);
			UtilGL::Transforming::NormViewportToLocal(&botRight);

			float fHalfX = (botRight.X() - upLeft.X()) * 0.5f;
			float fHalfY = (botRight.Y() - upLeft.Y()) * 0.5f;
			float fHalfZ = valueDepth.GetValue() * 0.5f;

			cube.v1.Set(-fHalfX, -fHalfY, +fHalfZ);
			cube.v2.Set(-fHalfX, +fHalfY, +fHalfZ);
			cube.v3.Set(+fHalfX, +fHalfY, +fHalfZ);
			cube.v4.Set(+fHalfX, -fHalfY, +fHalfZ);
			cube.v5.Set(-fHalfX, -fHalfY, -fHalfZ);
			cube.v6.Set(-fHalfX, +fHalfY, -fHalfZ);
			cube.v7.Set(+fHalfX, +fHalfY, -fHalfZ);
			cube.v8.Set(+fHalfX, -fHalfY, -fHalfZ);

			cube.v3Center.Set(	(x * fSizeX) + (fSizeX * 0.5f),
								(y * fSizeY) + (fSizeY * 0.5f),
								0.5f);

			cube.v3Accel    = v3Accel * ComputeRandWithVariation(1.0f, valueVariation.GetValue()) * ((botRight.Y() - upLeft.Y()) * xRes);
			cube.v3Speed    = v3Speed * ComputeRandWithVariation(1.0f, valueVariation.GetValue()) * ((botRight.Y() - upLeft.Y()) * xRes);

			cube.fStartTime = (MYFABSF(x - (xRes / 2.0f)) / (float)(xRes / 2.0f)) * valueAssimetry.GetValue();
			cube.fRotation  = ComputeRand(0.0f, valueMaxRotation.GetValue());

			UtilGL::Transforming::NormViewportToLocal(&cube.v3Center);

			cube.fTStart = 0.0f;
			cube.fTEnd   = 1.0f;

			m_vecCubes.push_back(cube);
		}
	}

	return true;
}
예제 #7
0
/** main program */
int main(int argc, char**argv) {
  int arg;                        /* current command-line argument */
  unsigned int bin;               /* current bin */
  struct headertag2 hd;           /* header of input SFT */
  FILE *fp;                       /* currently open filepointer */
  char *oldcomment;               /* comment of input SFT */
  char *cmdline = NULL;           /* records command-line to add it to comment */
  char *comment = NULL;           /* comment to be written into output SFT file */
  int swap;                       /* do we need to swap bytes? */
  float *data;                    /* SFT data */
  char *outname;                  /* name of output SFT file */
  char empty = '\0';
  char *prefix = &empty;          /* output filename prefix */
  char *detector = NULL;          /* detector name */
  double factor = 1.0;            /* "mystery" factor */
  double conversion_factor = 1.0; /* extra factor needed when converting from v1 SFTs */
  int firstfile = TRUE;           /* are we processing the first input SFT file? */
  int allcomments = FALSE;        /* write comment into _every_ SFT in the file */
  int add_comment = CMT_FULL;     /* add VCS ID and full command-line to every SFT file */
  unsigned int start = 0, end = 0;     /* start and end in bins */
  unsigned int width = 0, overlap = 0; /* width and overlap in bins */
  double fMin = -1.0, fMax = -1.0;     /* start and end in Hz */
  double fWidth = -1.0, fOverlap = -1; /* width and overlap in Hz */
  unsigned int nactivesamples;         /* number of bins to actually read in */
  int validate = TRUE;                 /* validate the checksum of each input SFT before using it? */

  /* initialize throtteling */
  time(&read_bandwidth.last_checked);
  time(&read_open_rate.last_checked);
  time(&write_bandwidth.last_checked);
  time(&write_open_rate.last_checked);

  /* help / usage message */
  if((argv[1] == NULL) ||
     (strcmp(argv[1], "-h") == 0) || 
     (strcmp(argv[1], "--help") == 0)) {
    fprintf(stderr,
	    "%s -h\n"
	    "\n"
	    "  Write this help message\n"
	    "\n"
	    "%s\n"
	    "  [-a|--all-comments]\n"
	    "  [-c|--add-comment 0|1|2]\n"
	    "  [-v|--no-validation]\n"
	    "  [-s|--start-bin <startbin>]\n"
	    "  [-e|--end-bin <endbin (exclusively)>]\n"
	    "  [-b|--width <sftbins>]\n"
	    "  [-x|--overlap <overlap>]\n"
	    "  [-fs|--start-frequency <startfrequency>]\n"
	    "  [-fe|--end-frequency <endfrequency (exclusively)>]\n"
	    "  [-fb|--frequency-bandwidth <frequencywidth>]\n"
	    "  [-fx|--frequency-overlap <frequencyoverlap>]\n"
	    "  [-m|--factor <factor>]\n"
	    "  [-d|--detector <detector>]\n"
	    "  [-o|--output-prefix <outputprefix>]\n"
	    "  -i|--input-files <inputfile> ...\n"
	    "\n"
	    "  This program reads in binary SFTs (v1 and v2) and writes out narrow-banded\n"
	    "  merged SFTs (v2).\n"
	    "\n"
	    "  The frequency bands of the ouput SFTs (first frequency bin of first output SFT,\n"
	    "  last frequency bin of last output SFT, number of bins in each output SFT)\n"
	    "  and a possible overlap of the output files can be specified\n"
	    "  either in bins ('-s', '-e', '-b', -'x') or Hz ('-fs', '-fe', '-fb', '-fx')\n"
	    "  (or mixed - if both are given, frequency values take precedence).\n"
	    "\n"
	    "  A 'mystery factor' can be specified with '-m' option.\n"
	    "\n"
	    "  '-v' skips validation of the CRC checksum of the input files\n"
	    "\n"
	    "  In case of reading v1 SFTs (which don't support detector information in the header)\n"
	    "  the detector needs to be specified on the command-line using '-d' option.\n"
	    "\n"
	    "  The name of the output SFTs is created by appending the start bin of the narrow-band\n"
	    "  SFT to the 'output prefix' that can be given to the program with '-o'. If an output\n"
	    "  file already exists, the program will append the new SFTs to them, making it possible\n"
	    "  to construct the final narrow-band SFTs by running the program multiple times with\n"
	    "  different input SFTs. The GPS timestamps of the input SFTs need to be in ascending\n"
	    "  order to get valid merged SFT files.\n"
	    "\n"
	    "  The '-c' options specifies how to deal with comments - 0 means no comment is written\n"
	    "  at all, 1 means that the comment is taken unmodified from the input SFTs, 2 (default)\n"
	    "  means that the program appends its RCS id and command-line to the comment.\n"
	    "  By default a comment is written only to the first SFT of a merged SFT output 'block'\n"
	    "  (i.e. call to this program). Adding the option '-a' to the command line specifies that\n"
	    "  instead the comment is written into every SFT in the resulting file.\n"
	    "\n"
	    "  The last option on the command-line needs to be '-i', followed by as many input files\n"
	    "  as you wish (or the OS supports - using xargs should be simple with this command-line\n"
	    "  syntax).\n"
	    "\n"
	    "  The program adds its own VCS ID and command-line to the comment of the written SFTs,\n"
	    "  a mystery factor should show up as 'xxx' there.\n",
	    argv[0], argv[0]);
    exit(0);
  }

  /* record VCS ID and command-line for the comment */
  TRY((cmdline = (char*)malloc(strlen(lalAppsVCSIdentId)+strlen(lalAppsVCSIdentStatus)+2)) == NULL,
      "out of memory allocating cmdline",1);
  strcpy(cmdline,lalAppsVCSIdentId);
  strcat(cmdline,lalAppsVCSIdentStatus);
  strcat(cmdline, "\n");
  for(arg = 0; arg < argc; arg++) {
    if (strcmp(argv[arg], "-m") == 0) {
      /* obscure the mystery factor */
      TRY((cmdline = (char*)realloc((void*)cmdline, strlen(cmdline) + 8)) == NULL,
	  "out of memory allocating cmdline",2);
      strcat(cmdline, "-m xxx ");
      arg++;
    } else {
      TRY((cmdline = (char*)realloc((void*)cmdline, strlen(cmdline) + strlen(argv[arg]) + 2)) == NULL,
	  "out of memory allocating cmdline",3);
      strcat(cmdline, argv[arg]);
      if(arg == argc - 1)
	strcat(cmdline, "\n");
      else
	strcat(cmdline, " ");
    }
  }

  /* get parameters from command-line */
  for(arg = 1; arg < argc; arg++) {
    if((strcmp(argv[arg], "-d") == 0) ||
	      (strcmp(argv[arg], "--detector") == 0)) {
      detector = argv[++arg];
    } else if((strcmp(argv[arg], "-c") == 0) ||
	      (strcmp(argv[arg], "--add-comment") == 0)) {
      add_comment = atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-a") == 0) ||
	      (strcmp(argv[arg], "--all-comments") == 0)) {
      allcomments = TRUE;
    } else if((strcmp(argv[arg], "-s") == 0) ||
	      (strcmp(argv[arg], "--start-bin") == 0)) {
      start = atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-e") == 0) ||
	      (strcmp(argv[arg], "--end-bin") == 0)) {
      end = atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-b") == 0) ||
	      (strcmp(argv[arg], "--width") == 0)) {
      width = atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-x") == 0) ||
	      (strcmp(argv[arg], "--overlap") == 0)) {
      overlap = atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-fs") == 0) ||
	      (strcmp(argv[arg], "--start-frequency") == 0)) {
      fMin = atof(argv[++arg]);
    } else if((strcmp(argv[arg], "-fe") == 0) ||
	      (strcmp(argv[arg], "--end-frequency") == 0)) {
      fMax = atof(argv[++arg]);
    } else if((strcmp(argv[arg], "-fb") == 0) ||
	      (strcmp(argv[arg], "--frequency-bandwidth") == 0)) {
      fWidth = atof(argv[++arg]);
    } else if((strcmp(argv[arg], "-fx") == 0) ||
	      (strcmp(argv[arg], "--frequency-overlap") == 0)) {
      fOverlap = atof(argv[++arg]);
    } else if((strcmp(argv[arg], "-m") == 0) ||
	      (strcmp(argv[arg], "--factor") == 0)) {
      factor = atof(argv[++arg]);
    } else if((strcmp(argv[arg], "-v") == 0) ||
	      (strcmp(argv[arg], "--no-validation") == 0)) {
      validate = FALSE;
    } else if((strcmp(argv[arg], "-o") == 0) ||
	      (strcmp(argv[arg], "--output-prefix") == 0)) {
      prefix = argv[++arg];
    } else if((strcmp(argv[arg], "-rb") == 0) ||
	      (strcmp(argv[arg], "--read-bandwidth") == 0)) {
      read_bandwidth.resource_rate=atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-ror") == 0) ||
	      (strcmp(argv[arg], "--read-open-rate") == 0)) {
      read_open_rate.resource_rate=atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-wb") == 0) ||
	      (strcmp(argv[arg], "--write-bandwidth") == 0)) {
      write_bandwidth.resource_rate=atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-wor") == 0) ||
	      (strcmp(argv[arg], "--write-open-rate") == 0)) {
      write_open_rate.resource_rate=atoi(argv[++arg]);
    } else if((strcmp(argv[arg], "-i") == 0) ||
	      (strcmp(argv[arg], "--input-files") == 0)) {
      break;
    } else {
      fprintf(stderr, "unknown option '%s', try '-h' for help\n", argv[arg]);
      exit (-1);
    }
  }

  /* check if there was an input-file option given at all */
  TRY(argv[arg] == NULL, "no input files specified",4);
  TRY((strcmp(argv[arg], "-i") != 0) &&
      (strcmp(argv[arg], "--input-files") != 0),
      "no input files specified",5);

  /* allocate space for output filename */
  TRY((outname = (char*)malloc(strlen(prefix) + 20)) == NULL,
      "out of memory allocating outname",6);

  /* loop over all input SFT files */
  /* first skip the "-i" option */
  for(arg++; arg < argc; arg++) {

    /* open input SFT */
    request_resource(&read_open_rate, 1);
    TRY((fp = fopen(argv[arg], "r")) == NULL,
	"could not open SFT file for reading",7);
    
    /* read header */
    request_resource(&read_bandwidth, 40);
    TRYSFT(ReadSFTHeader(fp, &hd, &oldcomment, &swap, validate),
	   "could not read SFT header");

    /* calculate bins from frequency parameters if they were given */
    /* deltaF = 1.0 / tbase; bins = freq / deltaF => bins = freq * tbase */
    if(fMin >= 0.0)
      start = MYROUND(fMin * hd.tbase);
    if(fMax >= 0.0)
      end   = MYROUND(fMax * hd.tbase);
    if(fWidth >= 0.0)
      width = MYROUND(fWidth * hd.tbase);
    if(fOverlap >= 0.0)
      overlap = MYROUND(fOverlap * hd.tbase);
 
    /* allocate space for SFT data */
    TRY((data = (float*)calloc(hd.nsamples, 2*sizeof(float))) == NULL,
	"out of memory allocating data",8);

    /* error if desired start bin < hd.firstfreqindex */
    if((int)start < hd.firstfreqindex) {
      fprintf(stderr,
	      "ERROR: start bin (%d) is smaller than first bin in input SFT (%d)\n",
	      start, hd.firstfreqindex);
      exit(9);
    }

    /* error if desired end bin > hd.firstfreqindex + hd.nsamples - 1 */
    if(start + width > end + 1) {
      fprintf(stderr,
	      "ERROR: end bin (%d) is larger than last bin in input SFT (%d)\n",
	      end, hd.firstfreqindex+hd.nsamples - 1);
      exit(10);
    }

    /* error if overlap is larger than the width */
    if(overlap >= width) {
      fprintf(stderr,
              "ERROR: overlap (%d) is not smaller than the width (%d)\n",
              overlap, width);
      exit(11);
    }

    /* construct comment for output SFTs */
    if (add_comment > CMT_OLD) {

      /* allocate space for new comment */
      TRY((comment = (char*)malloc(hd.comment_length + strlen(cmdline) + 1)) == NULL,
	  "out of memory allocating comment",11);
      
      /* append the commandline of this program to the old comment */
      if (oldcomment)
	strcpy(comment,oldcomment);
      else
	*comment = '\0';
      strcat(comment,cmdline);

    } else if (add_comment == CMT_OLD) {

      /* only copied existing comment, no additional space needed */
      comment = oldcomment;

    } /* else (add_comment == CMT_NONE) and (comment == NULL) i.e. no comment at all */

    /* get the detector name from SFT header if present there (in v2 SFTs),
       or else it needs to have been set on the command-line */
    if(*hd.detector)
      detector = hd.detector;

    /* if no detector has been specified, issue an error */
    TRY(!detector || !*detector, "When reading v1 SFTs a detector needs to be specified with -d",12);

    /* calculate number of bins to actually read (from width + overlap) */
    /* add width-overlap samples as lon as they are < the total number og bins to write */
    for(nactivesamples = 0; nactivesamples < end - start; nactivesamples += width - overlap);
    /* add the last overlap */
    nactivesamples += overlap + 1;
    /* if this number is larger than the bins in the input sft, just use the latter */
    if(nactivesamples > hd.nsamples + hd.firstfreqindex - start)
       nactivesamples = hd.nsamples + hd.firstfreqindex - start;

    /* read in SFT bins */
    request_resource(&read_bandwidth, nactivesamples*8);
    TRYSFT(ReadSFTData(fp, data, start, nactivesamples, NULL, NULL),
	   "could not read SFT data");

    /* if reading v1 SFTs set up a factor to be applied for normalization conversion */
    if(hd.version == 1.0) {
      conversion_factor = 0.5 * hd.tbase / hd.nsamples;
    } else {
      conversion_factor = 1.0;
    }

    /* apply mystery factor and possibly normalization factor */
    for(bin = 0; bin < 2 * nactivesamples; bin++)
      data[bin] *= factor * conversion_factor;

    /* close the input sfts */
    fclose(fp);

    /* loop over start bins for output SFTs */
    for(bin = start; bin < end; bin += width - overlap) {
      /* determine the number of bins actually to write from the desired 'width',
	 given that the remaining number of bin may be odd (especially from overlapping)
	 and the bins to write need to be present in the input sft
       */
      int last_input_bin   = hd.firstfreqindex + hd.nsamples - 1;
      int last_output_bin  = bin + width - 1;
      int max_input_width  = last_output_bin <= last_input_bin ? width : width - (last_output_bin - last_input_bin);
      int max_output_width = end - bin + 1;
      int this_width       = max_input_width < max_output_width ? max_input_width : max_output_width;

      /* construct filename for this output SFT */
      sprintf(outname, "%s%d", prefix, bin);

      /* append this SFT to a possible "merged" SFT with the same name */
      request_resource(&write_open_rate, 1);
      TRY((fp = fopen(outname,"a")) == NULL,
	  "could not open SFT for writing",13);

      /* write the data */
      /* write the comment only to the first SFT of a "block", i.e. of a call of this program */
      request_resource(&write_bandwidth, 40 + this_width * 8);
      TRYSFT(WriteSFT(fp, hd.gps_sec, hd.gps_nsec, hd.tbase, 
		      bin, this_width, detector,
		      (firstfile || allcomments) ? comment : NULL,
		      data + 2 * (bin - start)),
	     "could not write SFT data");

      /* close output SFT file */
      fclose(fp);

    } /* loop over output SFTs */

    /* cleanup */
    if (add_comment > CMT_OLD)
      free(comment);
    free(data);

    /* next file is not the first file anymore */
    firstfile = FALSE;

  } /* loop over input SFTs */

  /* cleanup */
  free(outname);
  if (add_comment > CMT_OLD)
    free(cmdline);

  return(0);
}
예제 #8
0
void Clouds::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	/*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
		return;*/
	if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
		return;

	ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);

	int num_faces_to_draw = 6;
	if(g_settings->getBool("enable_2d_clouds"))
		num_faces_to_draw = 1;

	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	driver->setMaterial(m_material);
	
	/*
		Clouds move from X+ towards X-
	*/

	const s16 cloud_radius_i = 12;
	const float cloud_size = BS*48;
	const v2f cloud_speed(-BS*2, 0);
	
	// Position of cloud noise origin in world coordinates
	v2f world_cloud_origin_pos_f = m_time*cloud_speed;
	// Position of cloud noise origin from the camera
	v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos;
	// The center point of drawing in the noise
	v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f;
	// The integer center point of drawing in the noise
	v2s16 center_of_drawing_in_noise_i(
		MYROUND(center_of_drawing_in_noise_f.X / cloud_size),
		MYROUND(center_of_drawing_in_noise_f.Y / cloud_size)
	);
	// The world position of the integer center point of drawing in the noise
	v2f world_center_of_drawing_in_noise_f = v2f(
		center_of_drawing_in_noise_i.X * cloud_size,
		center_of_drawing_in_noise_i.Y * cloud_size
	) + world_cloud_origin_pos_f;

	for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
	for(s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++)
	{
		v2s16 p_in_noise_i(
			xi+center_of_drawing_in_noise_i.X,
			zi+center_of_drawing_in_noise_i.Y
		);

		/*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0)
			continue;*/
		/*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0)
			continue;*/

		v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;
		
		double noise = noise2d_perlin_abs(
				(float)p_in_noise_i.X*cloud_size/BS/200,
				(float)p_in_noise_i.Y*cloud_size/BS/200,
				m_seed, 3, 0.4);
		if(noise < 0.95)
			continue;

		float b = m_brightness;
		video::SColor c_top(128,b*240,b*240,b*255);
		video::SColor c_side_1(128,b*230,b*230,b*255);
		video::SColor c_side_2(128,b*220,b*220,b*245);
		video::SColor c_bottom(128,b*205,b*205,b*230);

		video::S3DVertex v[4] =
		{
			video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
		};

		f32 rx = cloud_size;
		f32 ry = 8*BS;
		f32 rz = cloud_size;

		for(int i=0; i<num_faces_to_draw; i++)
		{
			switch(i)
			{
				case 0:	// top
					v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
					v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
					v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
					v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
					break;
				case 1: // back
					for(int j=0;j<4;j++)
						v[j].Color=c_side_1;
					v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
					v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
					v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
					v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
					break;
				case 2: //right
					for(int j=0;j<4;j++)
						v[j].Color=c_side_2;
					v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
					v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
					v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
					v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
					break;
				case 3: // front
					for(int j=0;j<4;j++)
						v[j].Color=c_side_1;
					v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
					v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
					v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
					v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
					break;
				case 4: // left
					for(int j=0;j<4;j++)
						v[j].Color=c_side_2;
					v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
					v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
					v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
					v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
					break;
				case 5: // bottom
					for(int j=0;j<4;j++)
						v[j].Color=c_bottom;
					v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
					v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
					v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
					v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
					break;
			}

			v3f pos = v3f(p0.X,m_cloud_y,p0.Y);

			for(u16 i=0; i<4; i++)
				v[i].Pos += pos;
			u16 indices[] = {0,1,2,2,3,0};
			driver->drawVertexPrimitiveList(v, 4, indices, 2,
					video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
		}

	}
}