Skip to content

Commit 2fcf1ba

Browse files
authored
Lab camera snapping widget (scp-fs2open#7400)
* camera control widget with snapping * fresh brain, fresh tweaks * clang
1 parent 3bd934e commit 2fcf1ba

8 files changed

Lines changed: 533 additions & 34 deletions

File tree

code/lab/dialogs/lab_ui.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,15 @@ void LabUi::build_options_menu()
301301
{
302302
with_Menu("Options")
303303
{
304+
bool show_widget_menu = getLabManager()->Renderer->getShowOrientationWidget();
304305
MenuItem("Render options", nullptr, &show_render_options_dialog);
305306
MenuItem("Object selector", nullptr, &show_object_selection_dialog);
306307
MenuItem("Background selector", nullptr, &show_background_selection_dialog);
307308
MenuItem("Object options", nullptr, &show_object_options_dialog);
308309
MenuItem("Controls reference", nullptr, &show_controls_reference_dialog);
310+
if (MenuItem("Show orientation cube widget", nullptr, show_widget_menu)) {
311+
getLabManager()->Renderer->setShowOrientationWidget(!show_widget_menu);
312+
}
309313
MenuItem("Reset View", nullptr, &reset_view);
310314
MenuItem("Close lab", "ESC", &close_lab);
311315
}
@@ -521,6 +525,7 @@ void LabUi::show_render_options()
521525
float emissive_factor = ltp::lab_get_emissive();
522526
float exposure_level = ltp::current_exposure();
523527
auto ppcv = ltp::lab_get_ppc();
528+
show_orientation_widget = getLabManager()->Renderer->getShowOrientationWidget();
524529

525530
bool skip_setting_light_options_this_frame = false;
526531

@@ -570,6 +575,7 @@ void LabUi::show_render_options()
570575
Checkbox("Hide particles", &no_particles);
571576
Checkbox("Render as wireframe", &use_wireframe_rendering);
572577
Checkbox("Orthographic projection", &use_orthographic_projection);
578+
Checkbox("Show orientation cube widget", &show_orientation_widget);
573579
Checkbox("Render without light", &no_lighting);
574580
Checkbox("Render with emissive lighting", &show_emissive_lighting);
575581
SliderFloat("Light brightness", &light_factor, 0.0f, 10.0f);
@@ -690,6 +696,7 @@ void LabUi::show_render_options()
690696
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::MoveSubsystems, animate_subsystems);
691697
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::NoParticles, no_particles);
692698
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::UseOrthographicProjection, use_orthographic_projection);
699+
getLabManager()->Renderer->setShowOrientationWidget(show_orientation_widget);
693700
getLabManager()->Renderer->setEmissiveFactor(emissive_factor);
694701
getLabManager()->Renderer->setAmbientFactor(ambient_factor);
695702
getLabManager()->Renderer->setLightFactor(light_factor);

code/lab/dialogs/lab_ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class LabUi {
122122
bool show_emissive_lighting = false;
123123
bool show_particles = true;
124124
bool use_orthographic_projection = false;
125+
bool show_orientation_widget = true;
125126

126127
std::optional<vec3d> volumetrics_pos_backup = std::nullopt;
127128
};

code/lab/manager/lab_manager.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,28 @@ void LabManager::onFrame(float frametime) {
126126
int dx, dy, dz;
127127
mouse_get_delta(&dx, &dy);
128128
mouse_get_wheel_delta(nullptr, &dz);
129+
int mouse_x = 0;
130+
int mouse_y = 0;
131+
mouse_get_pos(&mouse_x, &mouse_y);
132+
133+
const bool lmb_down = mouse_down(MOUSE_LEFT_BUTTON) != 0;
134+
bool lmb_pressed = lmb_down && !LastLmbDown;
135+
LastLmbDown = lmb_down;
136+
137+
if (lmb_pressed && ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)) {
138+
lmb_pressed = false;
139+
}
140+
129141
if (dz != 0 && ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)) {
130142
dz = 0;
131143
}
132-
Renderer->getCurrentCamera()->handleInput(dx, dy, dz, mouse_down(MOUSE_LEFT_BUTTON) != 0, mouse_down(MOUSE_RIGHT_BUTTON) != 0, key_get_shift_status());
144+
auto& current_camera = Renderer->getCurrentCamera();
145+
current_camera->handleInput(
146+
dx, dy, dz, lmb_down, lmb_pressed, mouse_down(MOUSE_RIGHT_BUTTON) != 0, key_get_shift_status(), mouse_x, mouse_y);
133147

134-
if (!Renderer->getCurrentCamera()->handlesObjectPlacement()) {
135-
if (mouse_down(MOUSE_LEFT_BUTTON)) {
148+
if (!current_camera->handlesObjectPlacement()) {
149+
const bool over_camera_overlay = Renderer->getShowOrientationWidget() && current_camera->isOverlayHit(mouse_x, mouse_y);
150+
if (lmb_down && !over_camera_overlay) {
136151
angles rot_angle;
137152
vm_extract_angles_matrix_alternate(&rot_angle, &CurrentOrientation);
138153

code/lab/manager/lab_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class LabManager {
157157
//float Lab_thrust_len = 0.0f; // Unused
158158
bool Weapons_loaded = false;
159159
bool CloseThis = false;
160+
bool LastLmbDown = false;
160161
LabUi labUi;
161162

162163
void changeShipInternal();

0 commit comments

Comments
 (0)