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"
26 scene::ISceneNode* parent,
27 scene::ISceneManager* mgr,
32 scene::ISceneNode(parent, mgr, id),
38 dstream<<__FUNCTION_NAME<<std::endl;
40 m_material.setFlag(video::EMF_LIGHTING, false);
41 m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
42 m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
43 m_material.setFlag(video::EMF_FOG_ENABLE, false);
44 //m_material.setFlag(video::EMF_ANTI_ALIASING, true);
45 //m_material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
47 m_box = core::aabbox3d<f32>(-BS*1000000,cloud_y-BS,-BS*1000000,
48 BS*1000000,cloud_y+BS,BS*1000000);
54 dstream<<__FUNCTION_NAME<<std::endl;
57 void Clouds::OnRegisterSceneNode()
61 //SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
62 SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
65 ISceneNode::OnRegisterSceneNode();
68 #define MYROUND(x) (x > 0.0 ? (int)x : (int)x - 1)
72 video::IVideoDriver* driver = SceneManager->getVideoDriver();
74 /*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
76 if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
79 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
80 driver->setMaterial(m_material);
83 Clouds move from X+ towards X-
86 const s16 cloud_radius_i = 12;
87 const float cloud_size = BS*48;
88 const v2f cloud_speed(-BS*2, 0);
90 // Position of cloud noise origin in world coordinates
91 v2f world_cloud_origin_pos_f = m_time*cloud_speed;
92 // Position of cloud noise origin from the camera
93 v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos;
94 // The center point of drawing in the noise
95 v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f;
96 // The integer center point of drawing in the noise
97 v2s16 center_of_drawing_in_noise_i(
98 MYROUND(center_of_drawing_in_noise_f.X / cloud_size),
99 MYROUND(center_of_drawing_in_noise_f.Y / cloud_size)
101 // The world position of the integer center point of drawing in the noise
102 v2f world_center_of_drawing_in_noise_f = v2f(
103 center_of_drawing_in_noise_i.X * cloud_size,
104 center_of_drawing_in_noise_i.Y * cloud_size
105 ) + world_cloud_origin_pos_f;
107 for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
108 for(s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++)
111 xi+center_of_drawing_in_noise_i.X,
112 zi+center_of_drawing_in_noise_i.Y
115 /*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0)
117 /*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0)
120 v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;
122 double noise = noise2d_perlin_abs(
123 (float)p_in_noise_i.X*cloud_size/BS/200,
124 (float)p_in_noise_i.Y*cloud_size/BS/200,
129 float b = m_brightness;
130 video::SColor c_top(128,b*240,b*240,b*255);
131 video::SColor c_side_1(128,b*230,b*230,b*255);
132 video::SColor c_side_2(128,b*220,b*220,b*245);
133 video::SColor c_bottom(128,b*205,b*205,b*230);
135 video::S3DVertex v[4] =
137 video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
138 video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
139 video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
140 video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
152 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
153 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
154 v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
155 v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
160 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
161 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
162 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
163 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
168 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
169 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
170 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
171 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
176 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
177 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
178 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
179 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
184 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
185 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
186 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
187 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
192 v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
193 v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
194 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
195 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
199 v3f pos = v3f(p0.X,m_cloud_y,p0.Y);
201 for(u16 i=0; i<4; i++)
203 u16 indices[] = {0,1,2,2,3,0};
204 driver->drawVertexPrimitiveList(v, 4, indices, 2,
205 video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
211 void Clouds::step(float dtime)
216 void Clouds::update(v2f camera_p, float brightness)
218 m_camera_pos = camera_p;
219 m_brightness = brightness;