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*50;
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 v2f p1 = p0 + v2f(1,1)*cloud_size;
131 //video::SColor c(128,255,255,255);
132 float b = m_brightness;
133 video::SColor c(128,b*230,b*230,b*255);
134 video::S3DVertex vertices[4] =
136 video::S3DVertex(p0.X,m_cloud_y,p0.Y, 0,0,0, c, 0,1),
137 video::S3DVertex(p0.X,m_cloud_y,p1.Y, 0,0,0, c, 1,1),
138 video::S3DVertex(p1.X,m_cloud_y,p1.Y, 0,0,0, c, 1,0),
139 video::S3DVertex(p1.X,m_cloud_y,p0.Y, 0,0,0, c, 0,0),
141 u16 indices[] = {0,1,2,2,3,0};
142 driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
143 video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
147 void Clouds::step(float dtime)
152 void Clouds::update(v2f camera_p, float brightness)
154 m_camera_pos = camera_p;
155 m_brightness = brightness;