include/terraingen/layers/boulders/boulder_fragments.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief Boulder shapes split into pieces that fit back together. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/layers/boulders/boulder_shape.h" | ||
| 8 | #include "terraingen/mesh/mesh.h" | ||
| 9 | |||
| 10 | #include <cstdint> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | namespace terraingen { | ||
| 14 | |||
| 15 | /// How the cracks of a split boulder run. | ||
| 16 | enum class BoulderCracks { | ||
| 17 | Radial, ///< Out from the middle, like wedges of a pie. | ||
| 18 | Slabs, ///< Roughly parallel, right through it, like a block split into slabs. | ||
| 19 | }; | ||
| 20 | |||
| 21 | /// One piece of a split boulder shape. | ||
| 22 | 6726 | struct BoulderFragment { | |
| 23 | /// The piece as `(parent point - center) / scale`: the unit form of `BoulderShape` scaled to | ||
| 24 | /// its largest horizontal extent rather than turned to its long axis, so that placing it with | ||
| 25 | /// its parent's pose puts it back where it was. | ||
| 26 | BoulderShape shape; | ||
| 27 | Vec3d center; ///< Center of the piece's box in the parent's unit form. | ||
| 28 | double scale = 1.0; ///< The piece's largest horizontal extent in the parent's unit form. | ||
| 29 | }; | ||
| 30 | |||
| 31 | /// `parent` split into `pieces` pieces by near-vertical cracks running as `cracks` says, a pure | ||
| 32 | /// function of the seed; neighboring pieces meet on the same plane. | ||
| 33 | /// @throws std::invalid_argument for fewer than 2 pieces or more than 12. | ||
| 34 | std::vector<BoulderFragment> FragmentBoulderShape(const BoulderShape& parent, int pieces, | ||
| 35 | std::uint64_t seed, | ||
| 36 | BoulderCracks cracks = BoulderCracks::Radial); | ||
| 37 | |||
| 38 | } // namespace terraingen | ||
| 39 |