]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clouds.h
clientmap, clientmedia: code modernization
[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         );
43
44         ~Clouds();
45
46         /*
47                 ISceneNode methods
48         */
49
50         virtual void OnRegisterSceneNode();
51
52         virtual void render();
53
54         virtual const aabb3f &getBoundingBox() const
55         {
56                 return m_box;
57         }
58
59         virtual u32 getMaterialCount() const
60         {
61                 return 1;
62         }
63
64         virtual video::SMaterial& getMaterial(u32 i)
65         {
66                 return m_material;
67         }
68
69         /*
70                 Other stuff
71         */
72
73         void step(float dtime);
74
75         void update(const v3f &camera_p, const video::SColorf &color);
76
77         void updateCameraOffset(v3s16 camera_offset)
78         {
79                 m_camera_offset = camera_offset;
80                 updateBox();
81         }
82
83         void readSettings();
84
85         void setDensity(float density)
86         {
87                 m_params.density = density;
88                 // currently does not need bounding
89         }
90
91         void setColorBright(const video::SColor &color_bright)
92         {
93                 m_params.color_bright = color_bright;
94         }
95
96         void setColorAmbient(const video::SColor &color_ambient)
97         {
98                 m_params.color_ambient = color_ambient;
99         }
100
101         void setHeight(float height)
102         {
103                 m_params.height = height; // add bounding when necessary
104                 updateBox();
105         }
106
107         void setSpeed(v2f speed)
108         {
109                 m_params.speed = speed;
110         }
111
112         void setThickness(float thickness)
113         {
114                 m_params.thickness = thickness;
115                 updateBox();
116         }
117
118         bool isCameraInsideCloud() const { return m_camera_inside_cloud; }
119
120         const video::SColor getColor() const { return m_color.toSColor(); }
121
122 private:
123         void updateBox()
124         {
125                 float height_bs    = m_params.height    * BS;
126                 float thickness_bs = m_params.thickness * BS;
127                 m_box = aabb3f(-BS * 1000000.0f, height_bs - BS * m_camera_offset.Y, -BS * 1000000.0f,
128                                 BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f);
129         }
130
131         bool gridFilled(int x, int y) const;
132
133         video::SMaterial m_material;
134         aabb3f m_box;
135         u16 m_cloud_radius_i;
136         bool m_enable_3d;
137         u32 m_seed;
138         v3f m_camera_pos;
139         v2f m_origin;
140         v3s16 m_camera_offset;
141         video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
142         CloudParams m_params;
143         bool m_camera_inside_cloud = false;
144
145 };
146
147
148
149 #endif