GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
robot_ground_point_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
9
10#include <Dxlib.h>
11
12#include "dxlib_util.h"
13#include "leg_state.h"
14
15
16namespace designlab
17{
18
20 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr) :
21 kRightLegGroundPointColor(GetColor(230, 15, 145)),
22 kLeftLegGroundPointColor(GetColor(15, 230, 145)),
23 kRightLegGroundPointDarkColor(GetColor(237, 159, 160)),
24 kLeftLegGroundPointDarkColor(GetColor(159, 237, 160)),
25 converter_ptr_(converter_ptr)
26{
27}
28
29
31 const std::vector<RobotStateNode>& node, const std::vector<size_t>& simulation_end_node_index)
32{
33 while (loaded_node_num_ < node.size())
34 {
35 int simulation_num = 0; // このノードのシミュレーション番号.
36
37 for (size_t i = 0; i < simulation_end_node_index.size(); i++)
38 {
39 if (simulation_end_node_index[i] >= loaded_node_num_)
40 {
41 break;
42 }
43 ++simulation_num;
44 }
45
46
47 // 現在のシミュレーション番号のデータがないならば追加する.
48 while (simulation_num >= ground_point_.size())
49 {
50 ground_point_.push_back({});
51 }
52
53
54 // 接地点を計算し,記録する.
55 std::array<VectorAndIsGround, HexapodConst::kLegNum> ground_point;
56
57 for (int i = 0; i < HexapodConst::kLegNum; i++)
58 {
59 ground_point[i] = {
60 converter_ptr_->ConvertLegToGlobalCoordinate(
61 node[loaded_node_num_].leg_pos[i], i, node[loaded_node_num_].center_of_mass_global_coord, node[loaded_node_num_].posture, true),
62 leg_func::IsGrounded(node[loaded_node_num_].leg_state, i)
63 };
64 }
65
66 ground_point_[simulation_num].push_back(ground_point);
67
68 ++loaded_node_num_;
69 }
70}
71
72
73void RobotGroundPointRenderer::Draw(const size_t draw_simulation_num, const bool draw_all_simulation) const
74{
75 unsigned int color[6] = { kRightLegGroundPointColor, kRightLegGroundPointColor, kRightLegGroundPointColor,
76 kLeftLegGroundPointColor, kLeftLegGroundPointColor, kLeftLegGroundPointColor };
77
78 unsigned int color_black[6] = { kRightLegGroundPointDarkColor, kRightLegGroundPointDarkColor, kRightLegGroundPointDarkColor,
79 kLeftLegGroundPointDarkColor, kLeftLegGroundPointDarkColor, kLeftLegGroundPointDarkColor };
80
81 for (size_t i = 0; i < ground_point_.size(); i++)
82 {
83 for (auto& leg_data : ground_point_[i])
84 {
85 for (size_t leg_index = 0; leg_index < HexapodConst::kLegNum; leg_index++)
86 {
87 if (!leg_data[leg_index].is_ground)
88 {
89 continue;
90 }
91
92 if (draw_all_simulation || i == draw_simulation_num)
93 {
94 dxlib_util::DrawCube3DWithTopPos(dxlib_util::ConvertToDxlibVec(leg_data[leg_index].vec), 25, color[leg_index]);
95 }
96 else
97 {
98 SetDrawBlendMode(DX_BLENDMODE_ALPHA, 32);
99
100 dxlib_util::DrawCube3DWithTopPos(dxlib_util::ConvertToDxlibVec(leg_data[leg_index].vec), 25, color_black[leg_index]);
101
102 SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
103 }
104 }
105 }
106 }
107}
108
109} // namespace designlab
static constexpr int kLegNum
void SetNodeAndSimulationEndNodeIndex(const std::vector< RobotStateNode > &result_node, const std::vector< size_t > &simulation_end_node_index)
RobotGroundPointRenderer(const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr)
void Draw(size_t draw_simulation_num, bool draw_all_simulation=false) const
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
bool IsGrounded(const LegStateBit &leg_state, const int leg_index)
脚番号 leg_index 0 ~ 5 に応じて,その脚が接地しているかを調べる. 脚は右前脚を0番として,時計回りに0,1,2,3,4,5となる.左前足が5番.
Definition leg_state.cpp:43