Minetest  5.4.0
clouds.h
Go to the documentation of this file.
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 
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 namespace irr{namespace scene{class ISceneManager;}}
33 extern irr::scene::ISceneManager *g_menucloudsmgr;
34 
35 class Clouds : public scene::ISceneNode
36 {
37 public:
38  Clouds(scene::ISceneManager* mgr,
39  s32 id,
40  u32 seed
41  );
42 
43  ~Clouds();
44 
45  /*
46  ISceneNode methods
47  */
48 
49  virtual void OnRegisterSceneNode();
50 
51  virtual void render();
52 
53  virtual const aabb3f &getBoundingBox() const
54  {
55  return m_box;
56  }
57 
58  virtual u32 getMaterialCount() const
59  {
60  return 1;
61  }
62 
63  virtual video::SMaterial& getMaterial(u32 i)
64  {
65  return m_material;
66  }
67 
68  /*
69  Other stuff
70  */
71 
72  void step(float dtime);
73 
74  void update(const v3f &camera_p, const video::SColorf &color);
75 
76  void updateCameraOffset(const v3s16 &camera_offset)
77  {
78  m_camera_offset = camera_offset;
79  updateBox();
80  }
81 
82  void readSettings();
83 
84  void setDensity(float density)
85  {
86  m_params.density = density;
87  // currently does not need bounding
88  }
89 
90  void setColorBright(const video::SColor &color_bright)
91  {
92  m_params.color_bright = color_bright;
93  }
94 
95  void setColorAmbient(const video::SColor &color_ambient)
96  {
97  m_params.color_ambient = color_ambient;
98  }
99 
100  void setHeight(float height)
101  {
102  m_params.height = height; // add bounding when necessary
103  updateBox();
104  }
105 
106  void setSpeed(v2f speed)
107  {
108  m_params.speed = speed;
109  }
110 
111  void setThickness(float thickness)
112  {
113  m_params.thickness = thickness;
114  updateBox();
115  }
116 
118 
119  const video::SColor getColor() const { return m_color.toSColor(); }
120 
121 private:
122  void updateBox()
123  {
124  float height_bs = m_params.height * BS;
125  float thickness_bs = m_params.thickness * BS;
126  m_box = aabb3f(-BS * 1000000.0f, height_bs - BS * m_camera_offset.Y, -BS * 1000000.0f,
127  BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f);
128  }
129 
130  bool gridFilled(int x, int y) const;
131 
132  video::SMaterial m_material;
136  u32 m_seed;
140  video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
142  bool m_camera_inside_cloud = false;
143 
144 };
Definition: clouds.h:36
void setColorBright(const video::SColor &color_bright)
Definition: clouds.h:90
bool gridFilled(int x, int y) const
Definition: clouds.cpp:373
virtual u32 getMaterialCount() const
Definition: clouds.h:58
video::SColorf m_color
Definition: clouds.h:140
bool isCameraInsideCloud() const
Definition: clouds.h:117
bool m_enable_3d
Definition: clouds.h:135
CloudParams m_params
Definition: clouds.h:141
void step(float dtime)
Definition: clouds.cpp:337
void setColorAmbient(const video::SColor &color_ambient)
Definition: clouds.h:95
virtual video::SMaterial & getMaterial(u32 i)
Definition: clouds.h:63
v3f m_camera_pos
Definition: clouds.h:137
v2f m_origin
Definition: clouds.h:138
u32 m_seed
Definition: clouds.h:136
virtual void OnRegisterSceneNode()
Definition: clouds.cpp:79
void setThickness(float thickness)
Definition: clouds.h:111
void update(const v3f &camera_p, const video::SColorf &color)
Definition: clouds.cpp:342
void updateCameraOffset(const v3s16 &camera_offset)
Definition: clouds.h:76
void updateBox()
Definition: clouds.h:122
void readSettings()
Definition: clouds.cpp:367
void setHeight(float height)
Definition: clouds.h:100
const video::SColor getColor() const
Definition: clouds.h:119
u16 m_cloud_radius_i
Definition: clouds.h:134
void setDensity(float density)
Definition: clouds.h:84
void setSpeed(v2f speed)
Definition: clouds.h:106
~Clouds()
Definition: clouds.cpp:73
aabb3f m_box
Definition: clouds.h:133
bool m_camera_inside_cloud
Definition: clouds.h:142
video::SMaterial m_material
Definition: clouds.h:132
v3s16 m_camera_offset
Definition: clouds.h:139
Clouds(scene::ISceneManager *mgr, s32 id, u32 seed)
Definition: clouds.cpp:43
virtual const aabb3f & getBoundingBox() const
Definition: clouds.h:53
virtual void render()
Definition: clouds.cpp:90
irr::scene::ISceneManager * g_menucloudsmgr
Definition: clouds.cpp:33
Clouds * g_menuclouds
Definition: clouds.cpp:32
#define BS
Definition: constants.h:74
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector2d< f32 > v2f
Definition: irr_v2d.h:26
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: clouds.h:32
static std::random_device seed
Definition: serverenvironment.cpp:392
Definition: cloudparams.h:23
video::SColor color_bright
Definition: cloudparams.h:25
float thickness
Definition: cloudparams.h:27
video::SColor color_ambient
Definition: cloudparams.h:26
v2f speed
Definition: cloudparams.h:29
float height
Definition: cloudparams.h:28
float density
Definition: cloudparams.h:24