]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clouds.h
Fog effect when camera is inside cloud
[dragonfireclient.git] / src / clouds.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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.
18 */
19
20 #ifndef CLOUDS_HEADER
21 #define CLOUDS_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include <iostream>
25 #include "constants.h"
26 #include "cloudparams.h"
27
28 // Menu clouds
29 class Clouds;
30 extern Clouds *g_menuclouds;
31
32 // Scene manager used for menu clouds
33 namespace irr{namespace scene{class ISceneManager;}}
34 extern irr::scene::ISceneManager *g_menucloudsmgr;
35
36 class Clouds : public scene::ISceneNode
37 {
38 public:
39         Clouds(scene::ISceneManager* mgr,
40                         s32 id,
41                         u32 seed,
42                         s16 cloudheight=0
43         );
44
45         ~Clouds();
46
47         /*
48                 ISceneNode methods
49         */
50
51         virtual void OnRegisterSceneNode();
52
53         virtual void render();
54
55         virtual const aabb3f &getBoundingBox() const
56         {
57                 return m_box;
58         }
59
60         virtual u32 getMaterialCount() const
61         {
62                 return 1;
63         }
64
65         virtual video::SMaterial& getMaterial(u32 i)
66         {
67                 return m_material;
68         }
69
70         /*
71                 Other stuff
72         */
73
74         void step(float dtime);
75
76         void update(const v3f &camera_p, const video::SColorf &color);
77
78         void updateCameraOffset(v3s16 camera_offset)
79         {
80                 m_camera_offset = camera_offset;
81                 updateBox();
82         }
83
84         void readSettings();
85
86         void setDensity(float density)
87         {
88                 m_params.density = density;
89                 // currently does not need bounding
90         }
91
92         void setColorBright(const video::SColor &color_bright)
93         {
94                 m_params.color_bright = color_bright;
95         }
96
97         void setColorAmbient(const video::SColor &color_ambient)
98         {
99                 m_params.color_ambient = color_ambient;
100         }
101
102         void setHeight(float height)
103         {
104                 m_params.height = height; // add bounding when necessary
105                 updateBox();
106         }
107
108         void setSpeed(v2f speed)
109         {
110                 m_params.speed = speed;
111         }
112
113         void setThickness(float thickness)
114         {
115                 m_params.thickness = thickness;
116                 updateBox();
117         }
118
119         bool isCameraInsideCloud() const { return m_camera_inside_cloud; }
120
121         const video::SColor getColor() const { return m_color.toSColor(); }
122
123 private:
124         void updateBox()
125         {
126                 float height_bs    = m_params.height    * BS;
127                 float thickness_bs = m_params.thickness * BS;
128                 m_box = aabb3f(-BS * 1000000.0f, height_bs - BS * m_camera_offset.Y, -BS * 1000000.0f,
129                                 BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f);
130         }
131
132         bool gridFilled(int x, int y) const;
133
134         video::SMaterial m_material;
135         aabb3f m_box;
136         s16 m_passed_cloud_y;
137         u16 m_cloud_radius_i;
138         bool m_enable_3d;
139         u32 m_seed;
140         v3f m_camera_pos;
141         v2f m_origin;
142         v3s16 m_camera_offset;
143         video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
144         CloudParams m_params;
145         bool m_camera_inside_cloud = false;
146
147 };
148
149
150
151 #endif