29 std::vector<Vector3> map_data;
31 switch (parameter_.
mode) {
33 CreateFlatMap(&map_data);
37 CreateVerticalStripeMap(&map_data);
41 CreateHorizontalStripeMap(&map_data);
45 CreateDiagonalStripeMap(&map_data);
49 CreateMeshMap(&map_data);
53 CreateLatticePointMap(&map_data);
57 CreateCircleMap(&map_data);
61 CreateDonutMap(&map_data);
66 CreateFlatMap(&map_data);
76 ChangeMapToPerforated(&map_data);
82 ChangeMapToStep(&map_data);
88 ChangeMapToSlope(&map_data);
94 ChangeMapToTilt(&map_data);
100 ChangeMapToRough(&map_data);
106 ChangeMapToRadial(&map_data);
113 [[maybe_unused]]
MapState* current_map)
const {
117void MapCreatorForSimulation::CreateFlatMap(std::vector<Vector3>* map)
const {
118 assert(map !=
nullptr);
119 assert(map->empty());
127 for (
int x = 0; x < x_max; x++) {
128 for (
int y = 0; y < y_max; y++) {
138 {x_pos, y_pos, parameter_.
base_z});
143void MapCreatorForSimulation::CreateVerticalStripeMap(
144 std::vector<Vector3>* map)
const {
145 assert(map !=
nullptr);
146 assert(map->empty());
154 for (
int x = 0; x < x_max; x++) {
155 for (
int y = 0; y < y_max; y++) {
157 const float x_rough =
172 {x_pos, y_pos, parameter_.
base_z});
178void MapCreatorForSimulation::CreateHorizontalStripeMap(
179 std::vector<Vector3>* map)
const {
180 assert(map !=
nullptr);
181 assert(map->empty());
189 for (
int x = 0; x < x_max; x++) {
190 for (
int y = 0; y < y_max; y++) {
192 const float x_rough =
207 {x_pos, y_pos, parameter_.
base_z});
213void MapCreatorForSimulation::CreateDiagonalStripeMap(
214 std::vector<Vector3>* map)
const {
215 assert(map !=
nullptr);
216 assert(map->empty());
224 for (
int x = 0; x < x_max; x++) {
225 for (
int y = 0; y < y_max; y++) {
227 const bool x_in_stripe =
230 const bool y_in_stripe =
233 const bool do_create_map = x_in_stripe == y_in_stripe;
235 const float x_rough =
239 if (do_create_map || x < x_rough) {
249 {x_pos, y_pos, parameter_.
base_z});
255void MapCreatorForSimulation::CreateMeshMap(std::vector<Vector3>* map)
const {
256 assert(map !=
nullptr);
257 assert(map->empty());
265 for (
int x = 0; x < x_max; x++) {
266 for (
int y = 0; y < y_max; y++) {
274 do_create_map =
true;
276 do_create_map =
false;
279 do_create_map =
true;
282 const float x_rough =
286 if (do_create_map || x < x_rough) {
296 {x_pos, y_pos, parameter_.
base_z});
302void MapCreatorForSimulation::CreateLatticePointMap(
303 std::vector<Vector3>* map)
const {
304 assert(map !=
nullptr);
305 assert(map->empty());
314 for (
int x = 0; x < x_max; x++) {
315 for (
int y = 0; y < y_max; y++) {
318 bool do_create_map =
false;
323 do_create_map =
false;
325 do_create_map =
true;
328 do_create_map =
false;
331 const float x_rough =
335 if (do_create_map || x < x_rough) {
345 map->push_back({x_pos, y_pos, parameter_.
base_z});
351void MapCreatorForSimulation::CreateCircleMap(std::vector<Vector3>* map)
const {
352 assert(map !=
nullptr);
371 const float distance =
372 Vector2(x_pos, y_pos)
376 map->push_back({x_pos, y_pos, parameter_.
base_z});
382void MapCreatorForSimulation::CreateDonutMap(std::vector<Vector3>* map)
const {
383 assert(map !=
nullptr);
402 const float distance =
403 Vector2(x_pos, y_pos)
408 map->push_back({x_pos, y_pos, parameter_.
base_z});
414void MapCreatorForSimulation::ChangeMapToPerforated(
415 std::vector<Vector3>* map)
const {
416 assert(map !=
nullptr);
420 const int cell_num_x =
425 const int cell_num_y =
430 const int cell_sum = cell_num_x * cell_num_y;
433 std::vector<bool> do_perforated(cell_sum,
false);
436 const int hole_num = cell_sum * parameter_.
hole_rate / 100;
438 for (
int i = 0; i < hole_num; i++) {
439 do_perforated.at(i) =
true;
443 std::shuffle(std::begin(do_perforated), std::end(do_perforated),
444 std::default_random_engine());
447 for (
auto itr = (*map).begin(); itr != (*map).end();) {
455 const int cell_pos_x =
460 const int cell_pos_y =
static_cast<int>(((*itr).y - parameter_.
map_min_y) /
464 const int cell_index = cell_pos_x * cell_num_y + cell_pos_y;
467 if (0 <= cell_index && cell_index < do_perforated.size()) {
469 if (do_perforated[cell_index]) {
471 itr = (*map).erase(itr);
483void MapCreatorForSimulation::ChangeMapToStep(std::vector<Vector3>* map)
const {
484 assert(map !=
nullptr);
486 for (
auto& i : *map) {
490 const int step_count =
500void MapCreatorForSimulation::ChangeMapToSlope(
501 std::vector<Vector3>* map)
const {
502 assert(map !=
nullptr);
504 for (
auto& i : *map) {
514void MapCreatorForSimulation::ChangeMapToTilt(std::vector<Vector3>* map)
const {
515 assert(map !=
nullptr);
517 for (
auto& i : *map) {
526void MapCreatorForSimulation::ChangeMapToRough(
527 std::vector<Vector3>* map)
const {
528 assert(map !=
nullptr);
532 const int cell_num_x =
537 const int cell_num_y =
542 const int cell_sum = cell_num_x * cell_num_y;
545 std::vector<float> change_z_length;
547 for (
int i = 0; i < cell_sum; i++) {
553 for (
auto& i : *map) {
559 const int cell_pos_x =
564 const int cell_pos_y =
static_cast<int>((i.y - parameter_.
map_min_y) /
568 const int cell_index = cell_pos_x * cell_num_y + cell_pos_y;
571 if (0 <= cell_index && cell_index < change_z_length.size()) {
572 i.z += change_z_length[cell_index];
577void MapCreatorForSimulation::ChangeMapToRadial(
578 std::vector<Vector3>* map)
const {
579 assert(map !=
nullptr);
581 const float divided_angle =
584 for (
auto itr = (*map).begin(); itr != (*map).end();) {
589 std::numbers::pi_v<float> +
592 if (
static_cast<int>(angle / divided_angle) % 2 == 1) {
593 const int i =
static_cast<int>(
594 angle / divided_angle);
595 const float angle_dif =
596 angle - i * divided_angle;
601 itr = (*map).erase(itr);
MapState InitMap() const override
マップの初期化を行う.
MapCreatorForSimulation(const SimulationMapParameter ¶m)
コンストラクタで作成するマップ情報を与える.
void UpdateMap(MapState *current_map) const override
マップの更新を行う.
static constexpr float kMapPointDistance
z軸から(上から)みたとき,格子点状に分けられた脚接地可能点の間隔 [mm].
T GenerateRandomNumber(T min, T max)
指定した範囲内の乱数を生成する.
constexpr T ConvertDegToRad(const T deg) noexcept
角度を [deg] から [rad] に変換する関数.
@ kTilt
縦軸を中心軸として回転させた地形に変化させる.
@ kRadiation
放射状の地形に変化させる.
@ kPerforated
穴の空いたマップに変化させる.
@ kHorizontalStripe
横じまの面を生成する.
@ kVerticalStripe
縦じまの面を生成する.
@ kLatticePoint
格子点の面を生成する.網目状の逆.
@ kMesh
格子状の面を生成する.網目状の地形ともいっていい.
@ kDiagonalStripe
斜めじまの面を生成する.
マップ生成時のモードとオプションを指定する構造体.
int radial_hole_rate
放射状の地形のホール率[%].
int radial_division
放射状の地形の分割数.
float map_max_y
マップのY座標の最大値.
int stripe_interval
各種模様や穴を作成する際,これで指定したマス分の1辺を持つ正方形状にあなをあける.
float map_min_x
マップのX座標の最小値.
float step_length
階段の奥行[mm]
float map_start_rough_x
不整地が始まるX座標.
float circle_radius
円 / ドーナツの半径.
float radial_angle_offset
放射状の地形の角度オフセット[deg].
float map_min_y
マップのY座標の最小値.
float donut_radius
ドーナツの内側の半径.
unsigned int option
マップ生成のオプションを指定するbit.
Vector2 radial_center
放射状の地形の中心座標.
float step_height
段差高さ[mm].負の値にすると下りの階段になる.
float rough_min_height
デコボコな地形の最小高さ[mm]
float map_max_x
マップのX座標の最大値.
float slope_angle
斜面の傾斜角[deg]
float rough_max_height
デコボコな地形の最大高さ[mm]
float tilt_angle
地形を傾ける角度[deg]
float base_z
マップの基準となるZ座標.
Vector3 circle_center
円 / ドーナツの中心座標.
int hole_rate
不整地上の足場を除外する割合。ホール率[%]
constexpr Vector2 ProjectedXY() const noexcept
XY平面に射影したベクトルを返す.