nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
sky.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_SKY_H_
2#define NANOMMO_CLIENT_SKY_H_
3
4#include <raylib.h>
5
6#include <cstdint>
7#include <vector>
8
9#include "client/atmosphere.h"
10
11namespace nanommo {
12
13/// The sky over a land: its colour from the horizon up, the sun, and low-poly
14/// clouds that drift over with the wind, whose shadows drift over the ground
15/// beneath them.
16class Sky {
17 public:
18 /// The most clouds a land has, all of them on a cloudy day.
19 static constexpr int kClouds = 40;
20 /// The world's shader darkens the ground under this many of the clouds'
21 /// balls, those nearest to what the camera looks at, as it can't afford
22 /// all of them for each pixel.
23 static constexpr int kShadows = 64;
24 /// In metres a second, which way the wind blows the clouds.
25 static constexpr Vector2 kWind = {2.5f, 1.0f};
26 /// The clouds drift through a square this wide, in metres, around the
27 /// camera, and come back in at the other side when they leave it.
28 static constexpr float kSpread = 900.0f;
29
30 Sky();
31 ~Sky();
32
33 Sky(const Sky&) = delete;
34 Sky& operator=(const Sky&) = delete;
35
36 /// The land's clouds, from its seed, so that a land's clouds are its own,
37 /// and the same each time.
38 void Gather(uint32_t seed);
39
40 /// Draws the sky, and the atmosphere's share of the clouds where the wind
41 /// has blown them by then, around the camera. Inside BeginMode3D, first.
42 void Draw(const Camera3D& camera, const Atmosphere& atmosphere,
43 float seconds) const;
44
45 /// Tells the world's shader where the clouds' shadows are: the middle of
46 /// each of their balls, its height, and how wide its shadow is.
47 void Shade(Shader shader, const Camera3D& camera,
48 const Atmosphere& atmosphere, float seconds) const;
49
50 private:
51 /// One of the low-poly balls a cloud is made of, from the cloud's middle,
52 /// and its size along each axis, in metres.
53 struct Puff {
54 Vector3 offset;
55 Vector3 size;
56 };
57 struct Cloud {
58 Vector2 at;
59 float height = 0.0f;
60 /// Clouds come in this order as the sky gets cloudier: the first on a
61 /// clear day, all of them on a cloudy one.
62 float rank = 0.0f;
63 std::vector<Puff> puffs;
64 };
65
66 /// Where the cloud is after the seconds of wind, in the square around the
67 /// camera.
68 Vector2 Blown(const Cloud& cloud, const Camera3D& camera,
69 float seconds) const;
70
71 std::vector<Cloud> clouds_;
72 Shader dome_shader_;
73 Shader cloud_shader_;
74 Model dome_;
75 Model puff_;
76};
77
78} // namespace nanommo
79
80#endif // NANOMMO_CLIENT_SKY_H_
Sky & operator=(const Sky &)=delete
void Shade(Shader shader, const Camera3D &camera, const Atmosphere &atmosphere, float seconds) const
Definition sky.cc:245
static constexpr Vector2 kWind
In metres a second, which way the wind blows the clouds.
Definition sky.h:25
static constexpr int kClouds
The most clouds a land has, all of them on a cloudy day.
Definition sky.h:19
static constexpr float kSpread
Definition sky.h:28
void Gather(uint32_t seed)
Definition sky.cc:165
static constexpr int kShadows
Definition sky.h:23
void Draw(const Camera3D &camera, const Atmosphere &atmosphere, float seconds) const
Definition sky.cc:204
Sky(const Sky &)=delete
Definition chat.cc:9
The sky and the light, which the shaders read each frame.
Definition atmosphere.h:13