GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
dxlib_gui_camera.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 "dxlib_gui_camera.h"
9
10#include <string>
11
12#include "dxlib_util.h"
13#include "font_loader.h"
14#include "mouse.h"
15
16
17namespace designlab
18{
19
20DxlibGuiCamera::DxlibGuiCamera(const int window_x, const int window_y,
21 const std::shared_ptr<DxlibCamera> camera) :
22 AbstractDxlibGui(kWidth, kHeight),
23 window_x_(window_x),
24 window_y_(window_y),
25 camera_(camera)
26{
27 const int button_distance = 10;
28 const int button_size = 60;
29
30 const int button_range = button_size + button_distance;
31 const int left_pos_x = gui_left_pos_x_ + button_range / 2 + 15;
32 const int top_pos_y = gui_top_pos_y_ + button_range / 2 + 40;
33
34 button_.push_back(std::make_unique<SimpleButton>(
35 "Reset\nZoom", left_pos_x, top_pos_y, button_size, button_size));
36 button_.back()->SetActivateFunction(
37 [this]() { camera_->InitCameraTargetLength(); });
38
39 button_.push_back(std::make_unique<SimpleButton>(
40 "Front",
41 left_pos_x + button_range, top_pos_y, button_size, button_size));
42 button_.back()->SetActivateFunction([this]() {
43 camera_->SetCameraViewMode(enums::CameraViewMode::kFrontView); });
44
45 button_.push_back(std::make_unique<SimpleButton>(
46 "Left", left_pos_x, top_pos_y + button_range, button_size, button_size));
47 button_.back()->SetActivateFunction([this]() {
48 camera_->SetCameraViewMode(enums::CameraViewMode::kLeftSideView); });
49
50 button_.push_back(std::make_unique<SimpleButton>(
51 "Top", left_pos_x + button_range, top_pos_y + button_range,
52 button_size, button_size));
53 button_.back()->SetActivateFunction([this]() {
54 camera_->SetCameraViewMode(enums::CameraViewMode::kTopView); });
55
56 button_.push_back(std::make_unique<SimpleButton>(
57 "Right", left_pos_x + button_range * 2, top_pos_y + button_range,
58 button_size, button_size));
59 button_.back()->SetActivateFunction([this]() {
60 camera_->SetCameraViewMode(enums::CameraViewMode::kRightSideView); });
61
62 button_.push_back(std::make_unique<SimpleButton>(
63 "Back", left_pos_x + button_range, top_pos_y + button_range * 2,
64 button_size, button_size));
65 button_.back()->SetActivateFunction([this]() {
66 camera_->SetCameraViewMode(enums::CameraViewMode::kBackView); });
67
68 button_.push_back(std::make_unique<SimpleButton>(
69 "Reset\nTarget", left_pos_x + button_range * 2, top_pos_y,
70 button_size, button_size));
71 button_.back()->SetActivateFunction([this]() {
72 camera_->SetCameraViewMode(enums::CameraViewMode::kFreeControlled); });
73
74 const int close_button_size = 28;
75 const int close_button_x = gui_left_pos_x_ + kWidth - close_button_size / 2 - 2;
76 const int close_button_y = gui_top_pos_y_ + close_button_size / 2 + 2;
77
78 button_.push_back(std::make_unique<SimpleButton>(
79 "×", close_button_x, close_button_y,
80 close_button_size, close_button_size));
81 button_.back()->SetActivateFunction([this]() { SetVisible(false); });
82}
83
85{
86 camera_->SetTargetPos(node.center_of_mass_global_coord);
87}
88
90{
91 // 各ボタンの処理.
92 for (auto& button : button_)
93 {
94 button->Update();
95 }
96
97 // カメラの更新.
98 camera_->Update();
99
100 if (!IsInWindow())
101 {
102 SetVisible(false);
103 }
104}
105
107{
108 DrawBackground("CameraGui");
109
110 // 全てのボタンの描画.
111 for (auto& button : button_)
112 {
113 button->Draw();
114 }
115
116 DrawString();
117}
118
119void DxlibGuiCamera::DrawString() const
120{
121 const unsigned int str_color = GetColor(54, 54, 54);
122
123 const int text_interval_y = 20;
124 const int text_top_y = gui_top_pos_y_ + 250;
125
126 int text_line = 0;
127
128 DrawFormatStringToHandle(
129 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
130 str_color, font_handle_, "ズーム");
131 DrawFormatStringToHandle(
132 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
133 str_color, font_handle_, " ・マウスホイール回転");
134
135 DrawFormatStringToHandle(
136 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
137 str_color, font_handle_, "ビューを回転");
138 DrawFormatStringToHandle(
139 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
140 str_color, font_handle_, " ・ホイールクリック&ドラッグ");
141
142 DrawFormatStringToHandle(
143 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
144 str_color, font_handle_, "画面の中心から回転");
145 DrawFormatStringToHandle(
146 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
147 str_color, font_handle_, " ・左クリック&ドラッグ");
148
149 DrawFormatStringToHandle(
150 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
151 str_color, font_handle_, "画面の平行移動");
152 DrawFormatStringToHandle(
153 gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++),
154 str_color, font_handle_, " ・右クリック&ドラッグ");
155}
156
157bool DxlibGuiCamera::IsInWindow() const
158{
159 return gui_left_pos_x_ < window_x_ && gui_top_pos_y_ < window_y_ &&
160 0 < gui_left_pos_x_ + kWidth && 0 < gui_top_pos_y_ + kHeight;
161}
162
163} // namespace designlab
Dxlibを使ったGUIの抽象クラス.
void DrawBackground(const std::string &str) const
int gui_left_pos_x_
GUIの左端の位置.
int gui_top_pos_y_
GUIの上端の位置.
void SetVisible(bool visible) override
GUIの表示を行うかどうかを設定する.
int font_handle_
フォントハンドル.
std::vector< std::unique_ptr< SimpleButton > > button_
ボタンのリスト.
void Update() override
GUIの更新,毎フレーム実行すること.
void SetNode(const RobotStateNode &node) override
ノードをセットする.
void Draw() const override
GUIの描画.
DxlibGuiCamera()=delete
デフォルトコンストラクタは生成できない.
@ kLeftSideView
右から真横の視点.
@ kTopView
上からの見下ろし視点.
@ kRightSideView
右から真横の視点.
@ kBackView
背面からの視点.
@ kFrontView
正面からの視点.
@ kFreeControlled
自由に操作可能.
グラフ構造のためのノード(頂点).旧名 LNODE
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM