GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
map_renderer.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#include "map_renderer.h"
9
10#include <Dxlib.h>
11
12#include "dxlib_util.h"
13#include "loop_util.h"
14
15namespace designlab {
16
18 : color_gray_(GetColor(180, 80, 80)),
19 color_light_gray_(GetColor(200, 160, 160)),
20 color_dark_gray_(GetColor(40, 40, 40)),
21 cube_size_(15.f) {}
22
24 hexapod_pos_ = pos.center_of_mass_global_coord;
25
26 divided_map_.Init(map_, hexapod_pos_);
27}
28
30 map_ = map;
31
32 divided_map_.Init(map_, hexapod_pos_);
33}
34
35void MapRenderer::Draw() const {
38
39 const size_t map_point_size = map_.GetMapPointSize(); // マップの点の数.
40
41 for (size_t i = 0; i < map_point_size; i++) {
42 DrawCube3DWithTopPos(ConvertToDxlibVec(map_.GetMapPoint(i)), cube_size_,
43 color_dark_gray_);
44 }
45
46 for (const auto& [i, j] : DoubleIntRange(30, 30)) {
47 const auto num = divided_map_.GetPointNum(i, j);
48 if (!num) {
49 continue; // このマスに脚設置可能点が存在しない場合はスキップ.
50 }
51
52 for (int k = 0; k < *num; k++) {
53 // 脚設置可能点を描画する.
54 const auto point_pos = divided_map_.GetPointPos(i, j, k);
55 if (!point_pos) {
56 continue; // このマスに脚設置可能点が存在しない場合はスキップ.
57 }
58
59 DrawCube3DWithTopPos(ConvertToDxlibVec(*point_pos), cube_size_,
60 (i + j) % 2 == 0 ? color_light_gray_ : color_gray_);
61 }
62 }
63}
64
65} // namespace designlab
nostd::expected< Vector3, std::string > GetPointPos(int x_index, int y_index, int divided_map_index) const
格子状に切り分けられたマップから,脚設置可能点の実際の座標を取得する. 範囲外の値を指定した場合は, unexpected を返す.
void Init(const MapState &map_state, const Vector3 global_robot_com)
マップのデータを初期化する. ロボットの重心座標を中心にマップのデータを格子状に分割し, その中に存在する脚設置可能点を集める.
nostd::expected< int, std::string > GetPointNum(int x_index, int y_index) const
格子状に切り分けられたマップから,脚設置可能点の数を取得する. 範囲外の値を指定した場合は, unexpected を返す.
void SetNode(const RobotStateNode &pos) override
ロボットの重心のグローバル座標を設定する. DividedMap はロボットの重心を中心にしているので, ロボットの重心のグローバル座標を設定する必要がある. 代入と同時に DividedMap...
void Draw() const override
マップの描画を行う.
void SetMapState(const MapState &map)
マップの状態を設定する.代入と同時に DividedMap も更新される.
マップを表すクラス.
Definition map_state.h:29
size_t GetMapPointSize() const noexcept
脚設置可能点の総数を返す.
Definition map_state.h:50
Vector3 GetMapPoint(const size_t index) const noexcept
脚設置可能点の座標を返す.
Definition map_state.h:42
void DrawCube3DWithTopPos(const VECTOR &top_pos, const float side_len, const unsigned int color)
3D空間に立方体を描画する.立方体の上面の中心の座標から描画する.
VECTOR ConvertToDxlibVec(const Vector3 &vec)
Dxlibの座標を示すVECTORと,このプログラムで使用しているVectorを変換する. ロボット座標系は右手座標系, Dxlibは左手座標系(工学は右手・ゲームライブラリは左手が多い)なのでyを...
Definition dxlib_util.h:35
グラフ構造のためのノード(頂点).
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM