Improve Clouds::render mathematics

This commit is contained in:
Loic Blot 2015-03-07 13:23:38 +01:00
parent 5698e2baf8
commit a603a76787

View file

@ -95,13 +95,13 @@ void Clouds::render()
*/ */
const s16 cloud_radius_i = 12; const s16 cloud_radius_i = 12;
const float cloud_size = BS*64; const float cloud_size = BS * 64;
const v2f cloud_speed(0, -BS*2); const v2f cloud_speed(0, -BS * 2);
const float cloud_full_radius = cloud_size * cloud_radius_i; const float cloud_full_radius = cloud_size * cloud_radius_i;
// Position of cloud noise origin in world coordinates // Position of cloud noise origin in world coordinates
v2f world_cloud_origin_pos_f = m_time*cloud_speed; v2f world_cloud_origin_pos_f = m_time * cloud_speed;
// Position of cloud noise origin from the camera // Position of cloud noise origin from the camera
v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos; v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos;
// The center point of drawing in the noise // The center point of drawing in the noise
@ -160,32 +160,27 @@ void Clouds::render()
// Read noise // Read noise
bool *grid = new bool[cloud_radius_i*2*cloud_radius_i*2]; bool *grid = new bool[cloud_radius_i * 2 * cloud_radius_i * 2];
for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++) float cloud_size_noise = cloud_size / BS / 200;
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( for(s16 zi = -cloud_radius_i; zi < cloud_radius_i; zi++) {
xi+center_of_drawing_in_noise_i.X, u32 si = (zi + cloud_radius_i) * cloud_radius_i * 2 + cloud_radius_i;
zi+center_of_drawing_in_noise_i.Y
);
#if 0 for(s16 xi = -cloud_radius_i; xi < cloud_radius_i; xi++) {
double noise = noise2d_perlin_abs( u32 i = si + xi;
(float)p_in_noise_i.X*cloud_size/BS/200,
(float)p_in_noise_i.Y*cloud_size/BS/200, v2s16 p_in_noise_i(
m_seed, 3, 0.4); xi + center_of_drawing_in_noise_i.X,
grid[i] = (noise >= 0.80); zi + center_of_drawing_in_noise_i.Y
#endif );
#if 1
double noise = noise2d_perlin( double noise = noise2d_perlin(
(float)p_in_noise_i.X*cloud_size/BS/200, (float)p_in_noise_i.X * cloud_size_noise,
(float)p_in_noise_i.Y*cloud_size/BS/200, (float)p_in_noise_i.Y * cloud_size_noise,
m_seed, 3, 0.5); m_seed, 3, 0.5);
grid[i] = (noise >= 0.4); grid[i] = (noise >= 0.4);
#endif }
} }
#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius)) #define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
@ -230,8 +225,8 @@ void Clouds::render()
}*/ }*/
f32 rx = cloud_size/2; f32 rx = cloud_size/2;
f32 ry = 8*BS; f32 ry = 8 * BS;
f32 rz = cloud_size/2; f32 rz = cloud_size / 2;
for(int i=0; i<num_faces_to_draw; i++) for(int i=0; i<num_faces_to_draw; i++)
{ {