summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-03-07 13:23:38 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2015-03-07 13:27:43 +0100
commita603a767877b94b4d3bc4d3de8d762fbc56a583d (patch)
tree345f65cf60fc12de31783c8fc1f24fb386954ee0
parent5698e2baf8008b11706a4bbc4d62c8b584703834 (diff)
downloadminetest-a603a767877b94b4d3bc4d3de8d762fbc56a583d.tar.gz
minetest-a603a767877b94b4d3bc4d3de8d762fbc56a583d.tar.bz2
minetest-a603a767877b94b4d3bc4d3de8d762fbc56a583d.zip
Improve Clouds::render mathematics
-rw-r--r--src/clouds.cpp55
1 files changed, 25 insertions, 30 deletions
diff --git a/src/clouds.cpp b/src/clouds.cpp
index 10ac8f5b3..8fea7a6aa 100644
--- a/src/clouds.cpp
+++ b/src/clouds.cpp
@@ -95,13 +95,13 @@ void Clouds::render()
*/
const s16 cloud_radius_i = 12;
- const float cloud_size = BS*64;
- const v2f cloud_speed(0, -BS*2);
+ 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;
+ 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
@@ -160,32 +160,27 @@ void Clouds::render()
// 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++)
- 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
+ float cloud_size_noise = cloud_size / BS / 200;
+
+ for(s16 zi = -cloud_radius_i; zi < cloud_radius_i; zi++) {
+ u32 si = (zi + cloud_radius_i) * cloud_radius_i * 2 + cloud_radius_i;
+
+ for(s16 xi = -cloud_radius_i; xi < cloud_radius_i; xi++) {
+ u32 i = si + xi;
+
+ v2s16 p_in_noise_i(
+ xi + center_of_drawing_in_noise_i.X,
+ zi + center_of_drawing_in_noise_i.Y
+ );
+
+ double noise = noise2d_perlin(
+ (float)p_in_noise_i.X * cloud_size_noise,
+ (float)p_in_noise_i.Y * cloud_size_noise,
+ m_seed, 3, 0.5);
+ grid[i] = (noise >= 0.4);
+ }
}
#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
@@ -230,8 +225,8 @@ void Clouds::render()
}*/
f32 rx = cloud_size/2;
- f32 ry = 8*BS;
- f32 rz = cloud_size/2;
+ f32 ry = 8 * BS;
+ f32 rz = cloud_size / 2;
for(int i=0; i<num_faces_to_draw; i++)
{