GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
dxlib_gui_camera_parameter_displayer.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 <magic_enum.hpp>
11
12#include "font_loader.h"
13#include "math_rot_converter.h"
14#include "string_util.h"
15
16
17namespace designlab
18{
19
21 const int window_x,
22 const int window_y,
23 const std::shared_ptr<DxlibCamera> camera_ptr) :
24 AbstractDxlibGui{ 470 ,340 },
25 window_x_(window_x),
26 window_y_(window_y),
27 camera_ptr_(camera_ptr)
28{
29 const int close_button_size = 28;
30 const int close_button_x = gui_left_pos_x_ + width_ - close_button_size / 2 - 2;
31 const int close_button_y = gui_top_pos_y_ + close_button_size / 2 + 2;
32
33 button_.push_back(std::make_unique<SimpleButton>("×", close_button_x, close_button_y, close_button_size, close_button_size));
34 button_.back()->SetActivateFunction([this]() { SetVisible(false); });
35}
36
38{
39 // ボタンを更新する.
40 for (auto& i : button_)
41 {
42 i->Update();
43 }
44
45 if (!IsInWindow())
46 {
47 SetVisible(false);
48 }
49}
50
52{
53 // 枠.
54 DrawBackground("CameraParameterDisplayer");
55
56 // ボタンを描画する.
57 for (const auto& i : button_)
58 {
59 i->Draw();
60 }
61
62 DrawCameraParameter();
63}
64
65void DxlibGuiCameraParameterDisplayer::DrawCameraParameter() const
66{
67 const unsigned int text_color = GetColor(10, 10, 10);
68
69 const int font_handle = FontLoader::GetIns()->GetFontHandle("font/Yu_Gothic_UI.dft");
70 const int text_pos_x = gui_left_pos_x_ + 10;
71 const int text_pos_y_min = gui_top_pos_y_ + kTitleBarHeight + 10;
72 const int text_interval_y = kFontSize + 4;
73
74 int text_line = 0;
75
76 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, "カメラの向き(正規化クォータニオン)");
77 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, " (w:%5.3f,x:%5.3f,y:%5.3f,z:%5.3f)",
78 camera_ptr_->GetNowCameraQuat().w, camera_ptr_->GetNowCameraQuat().v.x, camera_ptr_->GetNowCameraQuat().v.y, camera_ptr_->GetNowCameraQuat().v.z);
79
80 EulerXYZ euler_xyz = ToEulerXYZ(camera_ptr_->GetNowCameraQuat());
81 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, "カメラの向き(オイラー角)");
82 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, " (roll:%5.3f[deg],pitch:%5.3f[deg],yaw:%5.3f[deg])",
84
85 text_line++;
86 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, "カメラの表示モード");
87 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, " %s",
88 static_cast<std::string>(magic_enum::enum_name(camera_ptr_->GetCameraViewMode())).c_str());
89
90 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, "カメラの注視点の座標");
91 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, " (x:%5.3f [mm],y:%5.3f [mm],z:%5.3f [mm])",
92 camera_ptr_->GetNowTargetPos().x, camera_ptr_->GetNowTargetPos().y, camera_ptr_->GetNowTargetPos().z);
93
94 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, "カメラと対象との距離");
95 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, " %5.3f [mm]", camera_ptr_->GetNowCameraToTargetLength());
96
97 text_line++;
98 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, "カメラの位置");
99 DrawFormatStringToHandle(text_pos_x, text_pos_y_min + text_interval_y * (text_line++), text_color, font_handle, " (x:%5.3f [mm],y:%5.3f [mm],z:%5.3f [mm])",
100 camera_ptr_->GetNowCameraPos().x, camera_ptr_->GetNowCameraPos().y, camera_ptr_->GetNowCameraPos().z);
101}
102
103bool DxlibGuiCameraParameterDisplayer::IsInWindow() const
104{
105 return gui_left_pos_x_ < window_x_ && gui_top_pos_y_ < window_y_ &&
107}
108
109} // namespace designlab
Dxlibを使ったGUIの抽象クラス.
void DrawBackground(const std::string &str) const
int gui_left_pos_x_
GUIの左端の位置.
static constexpr int kTitleBarHeight
タイトルバーの高さ.
const int width_
GUIの横幅.
int gui_top_pos_y_
GUIの上端の位置.
void SetVisible(bool visible) override
GUIの表示を行うかどうかを設定する.
virtual void Update()=0
GUIの更新,毎フレーム実行すること.
std::vector< std::unique_ptr< SimpleButton > > button_
ボタンのリスト.
const int height_
GUIの縦幅.
DxlibGuiCameraParameterDisplayer()=delete
< デフォルトコンストラクタは生成できない.
void Update() override
GUIの更新,毎フレーム実行すること.
int GetFontHandle(const std::string &file_path)
Dxlibでは特定のフォントで描画する際に,フォントのハンドルを指定する. この関数では,フォントのファイルパスを指定すると, フォントのハンドル番号を返す. フォントがまだ読み込まれていない場...
static FontLoader * GetIns()
インスタンスを取得する. このクラスを継承したクラスは クラス名::getIns()-> の形式でメンバ関数を呼び出す.
Definition singleton.h:34
constexpr T ConvertRadToDeg(const T rad) noexcept
角度を [rad]から [deg] に変換する関数.
Definition math_util.h:117
EulerXYZ ToEulerXYZ(const RotationMatrix3x3 &rot)
回転角行列からXYZオイラー角への変換.
XYZオイラー角を用いた回転を表す構造体.
Definition math_euler.h:33
float x_angle
X 軸周りの回転 [rad]
Definition math_euler.h:109
float y_angle
Y 軸周りの回転 [rad]
Definition math_euler.h:110
float z_angle
Z 軸周りの回転 [rad]
Definition math_euler.h:111