nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
gate.cc
Go to the documentation of this file.
1#include "client/gate.h"
2
3#include <array>
4#include <cmath>
5#include <numbers>
6#include <vector>
7
8#include "client/atmosphere.h"
9#include "terrain/lands.h"
10
11namespace nanommo {
12
13namespace {
14
15constexpr int kStones = 6;
16
17// From the middle of the gate.
18constexpr float kRing = 2.2f;
19
20constexpr Vector3 kStone{0.6f, 3.0f, 0.6f};
21
22// Under each stone, a flat block a little wider, sunk into the ground a bit,
23// so that it sits on a slope too.
24constexpr Vector3 kBase{0.95f, 0.3f, 0.95f};
25constexpr float kSunk = 0.1f;
26
27// The platform: a rim of stone, and the sky's colour inside it, a little
28// higher, so that it shows.
29constexpr float kRim = 0.3f;
30constexpr float kPlatform = 0.3f;
31constexpr float kInside = 0.36f;
32
33} // namespace
34
35std::vector<Cube> GateCubes(const Terrain& terrain, int land) {
36 std::vector<Cube> cubes;
37 for (const Gate& gate : kGates) {
38 if (gate.land != land) {
39 continue;
40 }
41 const Place& place = gate.place;
42 for (int i = 0; i < kStones; ++i) {
43 const float angle = 2.0f * std::numbers::pi_v<float> * i / kStones;
44 const float x = place.x + kRing * std::cos(angle);
45 const float z = place.z + kRing * std::sin(angle);
46 // A cube's position is its middle, so it goes up by half its height.
47 const float ground = terrain.Height(x, z);
48 cubes.push_back({.position = {x, ground + kBase.y / 2 - kSunk, z},
49 .size = kBase,
50 .color = kLooks[land].rock});
51 cubes.push_back({.position = {x, ground + kStone.y / 2, z},
52 .size = kStone,
53 .color = kLooks[land].rock,
54 .shape = Shape::kSpire});
55 }
56 const float ground = terrain.Height(place.x, place.z);
57 const float across = 2 * (kGateRadius + kRim);
58 cubes.push_back({.position = {place.x, ground, place.z},
59 .size = {across, kPlatform, across},
60 .color = kLooks[land].rock,
61 .shape = Shape::kDisc});
62 const std::array<float, 3>& sky = kLooks[gate.to].atmosphere.sky;
63 cubes.push_back(
64 {.position = {place.x, ground, place.z},
65 .size = {2 * kGateRadius, kInside, 2 * kGateRadius},
66 .color = ColorFromNormalized({sky[0], sky[1], sky[2], 1.0f}),
67 .shape = Shape::kDisc});
68 }
69 return cubes;
70}
71
72} // namespace nanommo
float Height(float x, float z) const
On the triangles between the grid's corners, as the client draws them.
Definition terrain.cc:102
Definition chat.cc:9
constexpr std::array< Gate, 4 > kGates
Definition lands.h:45
constexpr std::array< Look, 3 > kLooks
In the order of the lands.
Definition atmosphere.h:164
std::vector< Cube > GateCubes(const Terrain &terrain, int land)
Definition gate.cc:35
constexpr float kGateRadius
In metres from the middle of a gate.
Definition lands.h:81
A ring of stones in a land, which takes players to another.
Definition lands.h:38
In metres from the middle of a land.
Definition lands.h:13
float z
Definition lands.h:15
float x
Definition lands.h:14