GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
movement_locus_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
14
15namespace designlab
16{
17
19 kHiddenLocusLineColor(GetColor(173, 187, 50)),
20 kDisplayLocusLineColor(GetColor(239, 237, 84)),
21 kHiddenLocusLineAlpha(128),
22 kLocusLineMaxLength(300.0f),
23 kLocusLineRadius(5.0f),
24 is_high_quality_(false)
25{
26}
27
28
29void MovementLocusRenderer::SetSimulationEndIndexes(const std::vector<size_t>& index)
30{
31 simulation_end_indexes_.clear();
32
33 for (const auto& i : index)
34 {
35 simulation_end_indexes_.push_back(i);
36 }
37}
38
39
40void MovementLocusRenderer::SetMoveLocusPoint(const std::vector<RobotStateNode>& locus)
41{
42 move_locus_point_.clear();
43
44 for (const auto& i : locus)
45 {
46 move_locus_point_.push_back(i.center_of_mass_global_coord);
47 }
48}
49
50
51void MovementLocusRenderer::Draw(const size_t draw_simulation_num,
52 const bool draw_all_simulation) const
53{
54 const size_t kSize = move_locus_point_.size();
55
56 if (kSize < 2)
57 {
58 return;
59 }
60
61 for (size_t i = 0; i < kSize - 1; i++)
62 {
63 // 範囲外アクセスを防ぐ.
64 if (i < 0 && kSize - 1 <= i)
65 {
66 break;
67 }
68
69 // 現在のシミュレーション回数.
70 size_t now_simulation_num = simulation_end_indexes_.size();
71
72 bool do_draw = true; // 描画するかどうか.
73
74
75 // 始点のインデックスがシミュレーション終了インデックスに含まれているならば描画を飛ばす.
76 for (size_t j = 0; j < simulation_end_indexes_.size(); j++)
77 {
78 if (i == simulation_end_indexes_[j])
79 {
80 do_draw = false;
81 }
82
83 if (i < simulation_end_indexes_[j])
84 {
85 now_simulation_num = j;
86 break;
87 }
88 }
89
90 // 始点と終点の座標を描画座標に変換する.
91 VECTOR start = dxlib_util::ConvertToDxlibVec(move_locus_point_.at(i));
92 VECTOR end = dxlib_util::ConvertToDxlibVec(move_locus_point_.at(i + 1));
93
94
95 // 描画.
96 if (do_draw)
97 {
98 int kDivNum = 6;
99
100 if (draw_simulation_num == now_simulation_num || draw_all_simulation)
101 {
102 if (is_high_quality_)
103 {
104 DrawCapsule3D(start, end, kLocusLineRadius, kDivNum,
105 kDisplayLocusLineColor, kDisplayLocusLineColor, TRUE);
106 }
107 else
108 {
109 DrawLine3D(start, end, kDisplayLocusLineColor);
110 }
111 }
112 else
113 {
114 SetDrawBlendMode(DX_BLENDMODE_ALPHA, kHiddenLocusLineAlpha);
115
116 if (is_high_quality_)
117 {
118 DrawCapsule3D(start, end, kLocusLineRadius, kDivNum,
119 kHiddenLocusLineColor, kHiddenLocusLineColor, TRUE);
120 }
121 else
122 {
123 DrawLine3D(start, end, kHiddenLocusLineColor);
124 }
125
126 SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
127 }
128 }
129 }
130}
131
132} // namespace designlab
void SetMoveLocusPoint(const std::vector< RobotStateNode > &locus)
ロボットの移動軌跡を記録する.ノードの配列から,重心位置の軌跡を取得する.
void SetSimulationEndIndexes(const std::vector< size_t > &index)
シミュレーションの終了点を取得する.
void Draw(const size_t draw_simulation_num, bool draw_all_simulation=false) const
ロボットの移動軌跡を描画する.
VECTOR ConvertToDxlibVec(const Vector3 &vec)
Dxlibの座標を示すVECTORと,このプログラムで使用しているVectorを変換する. ロボット座標系は右手座標系, Dxlibは左手座標系(工学は右手・ゲームライブラリは左手が多い)なのでyを...
Definition dxlib_util.h:35