]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/clouds.h
c009a05b76b76601666a7ae4524e06fcac4a3984
[dragonfireclient.git] / src / client / 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 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include <iostream>
24 #include "constants.h"
25 #include "cloudparams.h"
26
27 // Menu clouds
28 class Clouds;
29 extern Clouds *g_menuclouds;
30
31 // Scene manager used for menu clouds
32 extern scene::ISceneManager *g_menucloudsmgr;
33
34 class Clouds : public scene::ISceneNode
35 {
36 public:
37         Clouds(scene::ISceneManager* mgr,
38                         s32 id,
39                         u32 seed
40         );
41
42         ~Clouds();
43
44         /*
45                 ISceneNode methods
46         */
47
48         virtual void OnRegisterSceneNode();
49
50         virtual void render();
51
52         virtual const aabb3f &getBoundingBox() const
53         {
54                 return m_box;
55         }
56
57         virtual u32 getMaterialCount() const
58         {
59                 return 1;
60         }
61
62         virtual video::SMaterial& getMaterial(u32 i)
63         {
64                 return m_material;
65         }
66
67         /*
68                 Other stuff
69         */
70
71         void step(float dtime);
72
73         void update(const v3f &camera_p, const video::SColorf &color);
74
75         void updateCameraOffset(const v3s16 &camera_offset)
76         {
77                 m_camera_offset = camera_offset;
78                 updateBox();
79         }
80
81         void readSettings();
82
83         void setDensity(float density)
84         {
85                 m_params.density = density;
86                 // currently does not need bounding
87         }
88
89         void setColorBright(const video::SColor &color_bright)
90         {
91                 m_params.color_bright = color_bright;
92         }
93
94         void setColorAmbient(const video::SColor &color_ambient)
95         {
96                 m_params.color_ambient = color_ambient;
97         }
98
99         void setHeight(float height)
100         {
101                 m_params.height = height; // add bounding when necessary
102                 updateBox();
103         }
104
105         void setSpeed(v2f speed)
106         {
107                 m_params.speed = speed;
108         }
109
110         void setThickness(float thickness)
111         {
112                 m_params.thickness = thickness;
113                 updateBox();
114         }
115
116         bool isCameraInsideCloud() const { return m_camera_inside_cloud; }
117
118         const video::SColor getColor() const { return m_color.toSColor(); }
119
120 private:
121         void updateBox()
122         {
123                 float height_bs    = m_params.height    * BS;
124                 float thickness_bs = m_params.thickness * BS;
125                 m_box = aabb3f(-BS * 1000000.0f, height_bs - BS * m_camera_offset.Y, -BS * 1000000.0f,
126                                 BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f);
127         }
128
129         bool gridFilled(int x, int y) const;
130
131         video::SMaterial m_material;
132         aabb3f m_box;
133         u16 m_cloud_radius_i;
134         bool m_enable_3d;
135         u32 m_seed;
136         v3f m_camera_pos;
137         v2f m_origin;
138         v3s16 m_camera_offset;
139         video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
140         CloudParams m_params;
141         bool m_camera_inside_cloud = false;
142
143 };