Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
clouds.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
8#include "constants.h"
9#include "irr_ptr.h"
10#include "skyparams.h"
11#include <ISceneNode.h>
12#include <SMaterial.h>
13#include <CMeshBuffer.h>
14
15class IShaderSource;
16
17namespace scene
18{
19 class ISceneManager;
20}
21
22// Menu clouds
23// The mainmenu and the loading screen use the same Clouds object so that the
24// clouds don't jump when switching between the two.
25class Clouds;
26extern scene::ISceneManager *g_menucloudsmgr;
27extern Clouds *g_menuclouds;
28
29class Clouds : public scene::ISceneNode
30{
31public:
32 Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc,
33 s32 id,
34 u32 seed
35 );
36
37 ~Clouds();
38
39 /*
40 ISceneNode methods
41 */
42
43 virtual void OnRegisterSceneNode();
44
45 virtual void render();
46
47 virtual const aabb3f &getBoundingBox() const
48 {
49 return m_box;
50 }
51
52 virtual u32 getMaterialCount() const
53 {
54 return 1;
55 }
56
57 virtual video::SMaterial& getMaterial(u32 i)
58 {
59 return m_material;
60 }
61
62 /*
63 Other stuff
64 */
65
66 void step(float dtime);
67
68 void update(const v3f &camera_p, const video::SColorf &color);
69
70 void updateCameraOffset(v3s16 camera_offset)
71 {
72 m_camera_offset = camera_offset;
73 updateBox();
74 }
75
76 void readSettings();
77
78 void setDensity(float density)
79 {
80 if (m_params.density == density)
81 return;
82 m_params.density = density;
84 }
85
86 void setColorBright(video::SColor color_bright)
87 {
88 m_params.color_bright = color_bright;
89 }
90
91 void setColorAmbient(video::SColor color_ambient)
92 {
93 m_params.color_ambient = color_ambient;
94 }
95
96 void setColorShadow(video::SColor color_shadow)
97 {
98 if (m_params.color_shadow == color_shadow)
99 return;
100 m_params.color_shadow = color_shadow;
102 }
103
104 void setHeight(float height)
105 {
106 if (m_params.height == height)
107 return;
108 m_params.height = height;
109 updateBox();
111 }
112
113 void setSpeed(v2f speed)
114 {
115 m_params.speed = speed;
116 }
117
118 void setThickness(float thickness)
119 {
120 if (m_params.thickness == thickness)
121 return;
122 m_params.thickness = thickness;
123 updateBox();
125 }
126
128
129 const video::SColor getColor() const { return m_color.toSColor(); }
130
131private:
133 {
134 float height_bs = m_params.height * BS;
135 float thickness_bs = m_params.thickness * BS;
136 float far_bs = 1000000.0f * BS;
137 m_box = aabb3f(-far_bs, height_bs, -far_bs,
138 far_bs, height_bs + thickness_bs, far_bs);
139 m_box.MinEdge -= v3f::from(m_camera_offset) * BS;
140 m_box.MaxEdge -= v3f::from(m_camera_offset) * BS;
141 }
142
143 void updateMesh();
145 {
146 m_mesh_valid = false;
147 }
148
149 bool gridFilled(int x, int y) const;
150
151 // Are the clouds 3D?
152 inline bool is3D() const {
153 return m_enable_3d && m_params.thickness >= 0.01f;
154 }
155
156 video::SMaterial m_material;
157 irr_ptr<scene::SMeshBuffer> m_meshbuffer;
158 // Value of m_origin at the time the mesh was last updated
160 // Value of center_of_drawing_in_noise_i at the time the mesh was last updated
162 // Was the mesh ever generated?
163 bool m_mesh_valid = false;
164
165 aabb3f m_box{{0.0f, 0.0f, 0.0f}};
170
173
175 video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
177};
Definition clouds.h:30
void setColorAmbient(video::SColor color_ambient)
Definition clouds.h:91
irr_ptr< scene::SMeshBuffer > m_meshbuffer
Definition clouds.h:157
bool gridFilled(int x, int y) const
Definition clouds.cpp:473
virtual u32 getMaterialCount() const
Definition clouds.h:52
video::SColorf m_color
Definition clouds.h:175
bool isCameraInsideCloud() const
Definition clouds.h:127
virtual video::SMaterial & getMaterial(u32 i)
Definition clouds.h:57
bool m_enable_3d
Definition clouds.h:174
bool is3D() const
Definition clouds.h:152
CloudParams m_params
Definition clouds.h:176
void step(float dtime)
Definition clouds.cpp:431
v3f m_camera_pos
Definition clouds.h:169
v2f m_origin
Definition clouds.h:166
void invalidateMesh()
Definition clouds.h:144
u32 m_seed
Definition clouds.h:168
virtual void OnRegisterSceneNode()
Definition clouds.cpp:71
void setThickness(float thickness)
Definition clouds.h:118
void update(const v3f &camera_p, const video::SColorf &color)
Definition clouds.cpp:436
void updateBox()
Definition clouds.h:132
void setColorShadow(video::SColor color_shadow)
Definition clouds.h:96
void readSettings()
Definition clouds.cpp:461
void setHeight(float height)
Definition clouds.h:104
const video::SColor getColor() const
Definition clouds.h:129
void setColorBright(video::SColor color_bright)
Definition clouds.h:86
u16 m_cloud_radius_i
Definition clouds.h:167
void setDensity(float density)
Definition clouds.h:78
void setSpeed(v2f speed)
Definition clouds.h:113
~Clouds()
Definition clouds.cpp:66
aabb3f m_box
Definition clouds.h:165
bool m_camera_inside_cloud
Definition clouds.h:172
video::SMaterial m_material
Definition clouds.h:156
v3s16 m_camera_offset
Definition clouds.h:171
Clouds(scene::ISceneManager *mgr, IShaderSource *ssrc, s32 id, u32 seed)
Definition clouds.cpp:28
bool m_mesh_valid
Definition clouds.h:163
v2s16 m_last_noise_center
Definition clouds.h:161
void updateCameraOffset(v3s16 camera_offset)
Definition clouds.h:70
v2f m_mesh_origin
Definition clouds.h:159
virtual const aabb3f & getBoundingBox() const
Definition clouds.h:47
virtual void render()
Definition clouds.cpp:365
void updateMesh()
Definition clouds.cpp:81
Definition shader.h:241
scene::ISceneManager * g_menucloudsmgr
Definition clouds.cpp:17
Clouds * g_menuclouds
Definition clouds.cpp:18
#define BS
Definition constants.h:61
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
Definition camera.h:24
Definition skyparams.h:71
video::SColor color_shadow
Definition skyparams.h:75
video::SColor color_bright
Definition skyparams.h:73
float thickness
Definition skyparams.h:76
video::SColor color_ambient
Definition skyparams.h:74
v2f speed
Definition skyparams.h:78
float height
Definition skyparams.h:77
float density
Definition skyparams.h:72
constexpr v3f x
Definition test_irr_matrix4.cpp:18
constexpr v3f y
Definition test_irr_matrix4.cpp:19