xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
listui.cc
浏览该文件的文档.
1#include <imgui.h>
2
8
9#define ROLE OpenGL
10#define LABEL ListUi
12#define _CONST_MPTR(mobj) static_cast<const xcal::mobject::MObject*>(mobj)
13#define _CONST_CPTR(mobj) static_cast<const xcal::camera::AbsCamera*>(mobj)
14#define _CONST_PCPTR(mobj) \
15 static_cast<const xcal::camera::PerspectiveCamera*>(mobj)
16#define _PCPTR(mobj) static_cast<xcal::camera::PerspectiveCamera*>(mobj)
17
18bool xcal::render::opengl::ui::ListUi::render_vec3f_edit(
19 const xcmath::vec3<float_t>& vec3f, const char* label, const char* x_label,
20 const char* y_label, const char* z_label) {
21 namespace I = ImGui;
22 auto tmp = vec3f;
23 I::Text("%s: ", label);
24 I::Text("%s: ", x_label);
25 I::SameLine();
26 I::InputFloat("##X", &tmp.x());
27 I::Text("%s: ", y_label);
28 I::SameLine();
29 I::InputFloat("##Y", &tmp.y());
30 I::Text("%s: ", z_label);
31 I::SameLine();
32 I::InputFloat("##Z", &tmp.z());
33 if ((tmp == vec3f).all()) {
34 return false;
35 }
36 vec3f_tmp_ = tmp;
37 return true;
38}
39void xcal::render::opengl::ui::ListUi::render_obj(ObjectHandle& obj) {
40 // namespace I = ImGui;
41 // if (I::CollapsingHeader(obj.name.c_str())) {
42 // I::Text("pos: ");
43 // tmp_ = _CONST_MPTR(obj.obj)->pos().x();
44 // switch (obj.obj->type()) {
45 // case xcal::mobject::Type::Circle:
46 // static_cast<mobject::Circle*>(obj.obj)->pos();
47 // default:
48 // break;
49 // }
50 // if (I::InputFloat("X", &tmp_)) {
51 // obj.obj->pos().x() = tmp_;
52 // _D("updating x of object: " << obj.obj << " to: " << tmp_
53 // << " change state: "
54 // << obj.obj->pos().is_changed());
55 // }
56 // tmp_ = _CONST_MPTR(obj.obj)->pos().y();
57 // if (I::InputFloat("Y", &tmp_)) obj.obj->pos().y() = tmp_;
58 // I::Text("depth: ");
59 // tmp_ = _CONST_MPTR(obj.obj)->depth();
60 // if (I::InputFloat("Depth", &tmp_)) obj.obj->depth() = tmp_;
61 // }
62}
63void xcal::render::opengl::ui::ListUi::render_camera(CameraHandle& cam) {
64 if (!cam.camera) return;
65
66 namespace I = ImGui;
67 if (I::CollapsingHeader(cam.name.c_str())) {
68 int id = 0;
69 {
70 I::PushID(++id);
71 if (render_vec3f_edit(_CONST_CPTR(cam.camera)->position().value(),
72 "pos")) {
73 cam.camera->position() = vec3f_tmp_;
74 _D("updating position of camera: "
75 << cam.camera << " to: " << vec3f_tmp_
76 << " change state: " << cam.camera->position().is_changed());
77 }
78 I::PopID();
79 }
80 {
81 I::PushID(++id);
82 if (render_vec3f_edit(_CONST_CPTR(cam.camera)->target().value(),
83 "target", "X", "Y", "Z")) {
84 cam.camera->target() = vec3f_tmp_;
85 _D("updating target of camera: "
86 << cam.camera << " to: " << vec3f_tmp_
87 << " change state: " << cam.camera->target().is_changed());
88 }
89 I::PopID();
90 }
91 {
92 I::PushID(++id);
93 if (render_vec3f_edit(_CONST_CPTR(cam.camera)->up().value(), "up",
94 "X", "Y", "Z")) {
95 cam.camera->up() = vec3f_tmp_;
96 _D("updating up of camera: "
97 << cam.camera << " to: " << vec3f_tmp_
98 << " change state: " << cam.camera->up().is_changed());
99 }
100 I::PopID();
101 }
102 if (cam.camera->type() == xcal::camera::CameraType::Perspective) {
103 I::Text("Perspective properties: ");
104 I::Text("fov: ");
105 tmp_ = _CONST_PCPTR(cam.camera)->fov();
106 if (I::InputFloat("FOV", &tmp_)) {
107 _PCPTR(cam.camera)->fov() = tmp_;
108 _D("updating fov of camera: "
109 << cam.camera << " to: " << tmp_ << " change state: "
110 << _PCPTR(cam.camera)->fov().is_changed());
111 }
112 I::Text("near: ");
113 tmp_ = _CONST_PCPTR(cam.camera)->near();
114 if (I::InputFloat("Near", &tmp_)) {
115 _PCPTR(cam.camera)->near() = tmp_;
116 _D("updating near of camera: "
117 << cam.camera << " to: " << tmp_ << " change state: "
118 << _PCPTR(cam.camera)->near().is_changed());
119 }
120 I::Text("far: ");
121 tmp_ = _CONST_PCPTR(cam.camera)->far();
122 if (I::InputFloat("Far", &tmp_)) {
123 _PCPTR(cam.camera)->far() = tmp_;
124 _D("updating far of camera: "
125 << cam.camera << " to: " << tmp_ << " change state: "
126 << _PCPTR(cam.camera)->far().is_changed());
127 }
128 }
129 }
130}
131void xcal::render::opengl::ui::ListUi::render_animation(AnimationHandle& anim) {
132 if (!anim.animation) return;
133 namespace I = ImGui;
134 if (I::CollapsingHeader(anim.name.c_str())) {
135 int id = 0;
136 }
137}
138void xcal::render::opengl::ui::ListUi::render_timeline(
139 TimelineHandle& timeline) {
140 if (!timeline.timeline) return;
141 namespace I = ImGui;
142 if (I::CollapsingHeader(timeline.name.c_str())) {
143 }
144 if (I::Button("Play")) {
145 _I("play timeline:" << timeline.timeline);
146 renderer()->play_timeline(timeline.timeline);
147 }
148}
150 namespace I = ImGui;
151 if (!show_) return;
152 default_camera_handle().camera = renderer()->default_camera();
153 I::Begin("XCAL UI", &show_);
154 I::SetWindowFontScale(2);
155 int id = 0;
156 if (I::CollapsingHeader("Objects")) {
157 for (int i = 0; i < object_handles().size(); ++i) {
158 I::PushID(++id);
159 render_obj(object_handles()[i]);
160 I::PopID();
161 }
162 }
163 if (I::CollapsingHeader("Cameras")) {
164 I::PushID(++id);
165 render_camera(default_camera_handle());
166 I::PopID();
167
168 for (int i = 0; i < camera_handles().size(); ++i) {
169 I::PushID(++id);
170 render_camera(camera_handles()[i]);
171 I::PopID();
172 }
173 }
174 if (I::CollapsingHeader("Timelines")) {
175 for (int i = 0; i < timeline_handles().size(); ++i) {
176 I::PushID(++id);
177 render_timeline(timeline_handles()[i]);
178 I::PopID();
179 }
180 }
181 if (I::CollapsingHeader("Animations")) {
182 for (int i = 0; i < animation_handles().size(); ++i) {
183 I::PushID(++id);
184 render_animation(animation_handles()[i]);
185 I::PopID();
186 }
187 }
188 I::Text("fps: %.3f", 1.f / fps());
189 I::End();
190}
Vector class template
Definition vec.hpp:206
基础图形对象类
#define _PCPTR(mobj)
Definition listui.cc:16
#define _CONST_CPTR(mobj)
Definition listui.cc:13
#define _CONST_PCPTR(mobj)
Definition listui.cc:14
@ Perspective
透视相机
透视相机类