3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "constants.h"
25 #include "main.h" // For g_profiler
28 scene::ISceneNode* parent,
29 scene::ISceneManager* mgr,
34 scene::ISceneNode(parent, mgr, id),
40 dstream<<__FUNCTION_NAME<<std::endl;
42 m_material.setFlag(video::EMF_LIGHTING, false);
43 m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
44 m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
45 m_material.setFlag(video::EMF_FOG_ENABLE, false);
46 //m_material.setFlag(video::EMF_ANTI_ALIASING, true);
47 //m_material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
49 m_box = core::aabbox3d<f32>(-BS*1000000,cloud_y-BS,-BS*1000000,
50 BS*1000000,cloud_y+BS,BS*1000000);
56 dstream<<__FUNCTION_NAME<<std::endl;
59 void Clouds::OnRegisterSceneNode()
63 //SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
64 SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
67 ISceneNode::OnRegisterSceneNode();
70 #define MYROUND(x) (x > 0.0 ? (int)x : (int)x - 1)
74 video::IVideoDriver* driver = SceneManager->getVideoDriver();
76 /*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
78 if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
81 ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);
83 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
84 driver->setMaterial(m_material);
87 Clouds move from X+ towards X-
90 const s16 cloud_radius_i = 12;
91 const float cloud_size = BS*48;
92 const v2f cloud_speed(-BS*2, 0);
94 // Position of cloud noise origin in world coordinates
95 v2f world_cloud_origin_pos_f = m_time*cloud_speed;
96 // Position of cloud noise origin from the camera
97 v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos;
98 // The center point of drawing in the noise
99 v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f;
100 // The integer center point of drawing in the noise
101 v2s16 center_of_drawing_in_noise_i(
102 MYROUND(center_of_drawing_in_noise_f.X / cloud_size),
103 MYROUND(center_of_drawing_in_noise_f.Y / cloud_size)
105 // The world position of the integer center point of drawing in the noise
106 v2f world_center_of_drawing_in_noise_f = v2f(
107 center_of_drawing_in_noise_i.X * cloud_size,
108 center_of_drawing_in_noise_i.Y * cloud_size
109 ) + world_cloud_origin_pos_f;
111 for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
112 for(s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++)
115 xi+center_of_drawing_in_noise_i.X,
116 zi+center_of_drawing_in_noise_i.Y
119 /*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0)
121 /*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0)
124 v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;
126 double noise = noise2d_perlin_abs(
127 (float)p_in_noise_i.X*cloud_size/BS/200,
128 (float)p_in_noise_i.Y*cloud_size/BS/200,
133 float b = m_brightness;
134 video::SColor c_top(128,b*240,b*240,b*255);
135 video::SColor c_side_1(128,b*230,b*230,b*255);
136 video::SColor c_side_2(128,b*220,b*220,b*245);
137 video::SColor c_bottom(128,b*205,b*205,b*230);
139 video::S3DVertex v[4] =
141 video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
142 video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
143 video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
144 video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
156 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
157 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
158 v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
159 v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
164 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
165 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
166 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
167 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
172 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
173 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
174 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
175 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
180 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
181 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
182 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
183 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
188 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
189 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
190 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
191 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
196 v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
197 v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
198 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
199 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
203 v3f pos = v3f(p0.X,m_cloud_y,p0.Y);
205 for(u16 i=0; i<4; i++)
207 u16 indices[] = {0,1,2,2,3,0};
208 driver->drawVertexPrimitiveList(v, 4, indices, 2,
209 video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
215 void Clouds::step(float dtime)
220 void Clouds::update(v2f camera_p, float brightness)
222 m_camera_pos = camera_p;
223 m_brightness = brightness;