From c92c662abbbbc7ed93f628ad0e0f25e996ab686c Mon Sep 17 00:00:00 2001 From: Garux Date: Wed, 2 Aug 2017 09:22:10 +0300 Subject: [PATCH] Radiant: binds... * Tab in freelook: smooth turn around selected, while focusing on one misc... * activate key_press_handler before special_key_press_handler to allow CameraFree* commands, bound to special (gtk: !accelerator_is_valid) keys * update workzone on partial deselecting too (was updating only on adding to selection) --- libs/gtkutil/accelerator.cpp | 4 +-- radiant/camwindow.cpp | 61 ++++++++++++++++++++++++------------ radiant/select.cpp | 4 +-- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/libs/gtkutil/accelerator.cpp b/libs/gtkutil/accelerator.cpp index 5e01456c..596c1878 100644 --- a/libs/gtkutil/accelerator.cpp +++ b/libs/gtkutil/accelerator.cpp @@ -522,10 +522,10 @@ void global_accel_connect_window( GtkWindow* window ){ unsigned int override_handler = g_signal_connect( G_OBJECT( window ), "key_press_event", G_CALLBACK( override_global_accelerators ), 0 ); g_object_set_data( G_OBJECT( window ), "override_handler", gint_to_pointer( override_handler ) ); + GlobalPressedKeys_connect( window ); + unsigned int special_key_press_handler = g_signal_connect( G_OBJECT( window ), "key_press_event", G_CALLBACK( accelerator_key_event ), &g_special_accelerators ); g_object_set_data( G_OBJECT( window ), "special_key_press_handler", gint_to_pointer( special_key_press_handler ) ); - - GlobalPressedKeys_connect( window ); #else unsigned int key_press_handler = g_signal_connect( G_OBJECT( window ), "key_press_event", G_CALLBACK( accelerator_key_event ), &g_keydown_accelerators ); unsigned int key_release_handler = g_signal_connect( G_OBJECT( window ), "key_release_event", G_CALLBACK( accelerator_key_event ), &g_keyup_accelerators ); diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 99210352..a5ac5885 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -371,7 +371,10 @@ const unsigned int MOVE_UP = 1 << 6; const unsigned int MOVE_DOWN = 1 << 7; const unsigned int MOVE_PITCHUP = 1 << 8; const unsigned int MOVE_PITCHDOWN = 1 << 9; -const unsigned int MOVE_ALL = MOVE_FORWARD | MOVE_BACK | MOVE_ROTRIGHT | MOVE_ROTLEFT | MOVE_STRAFERIGHT | MOVE_STRAFELEFT | MOVE_UP | MOVE_DOWN | MOVE_PITCHUP | MOVE_PITCHDOWN; +const unsigned int MOVE_FOCUS = 1 << 10; +const unsigned int MOVE_ALL = MOVE_FORWARD | MOVE_BACK | MOVE_ROTRIGHT | MOVE_ROTLEFT | MOVE_STRAFERIGHT | MOVE_STRAFELEFT | MOVE_UP | MOVE_DOWN | MOVE_PITCHUP | MOVE_PITCHDOWN | MOVE_FOCUS; + +Vector3 Camera_getFocusPos( camera_t& camera ); void Cam_KeyControl( camera_t& camera, float dtime ){ // Update angles @@ -416,6 +419,9 @@ void Cam_KeyControl( camera_t& camera, float dtime ){ if ( camera.movementflags & MOVE_DOWN ) { vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); } + if ( camera.movementflags & MOVE_FOCUS ) { + camera.origin = Camera_getFocusPos( camera ); + } Camera_updateModelview( camera ); } @@ -519,6 +525,12 @@ void Camera_PitchDown_KeyUp( camera_t& camera ){ Camera_clearMovementFlags( camera, MOVE_PITCHDOWN ); } +void Camera_Focus_KeyDown( camera_t& camera ){ + Camera_setMovementFlags( camera, MOVE_FOCUS ); +} +void Camera_Focus_KeyUp( camera_t& camera ){ + Camera_clearMovementFlags( camera, MOVE_FOCUS ); +} typedef ReferenceCaller FreeMoveCameraMoveForwardKeyDownCaller; typedef ReferenceCaller FreeMoveCameraMoveForwardKeyUpCaller; @@ -533,6 +545,8 @@ typedef ReferenceCaller FreeMoveCameraMoveUpKeyU typedef ReferenceCaller FreeMoveCameraMoveDownKeyDownCaller; typedef ReferenceCaller FreeMoveCameraMoveDownKeyUpCaller; +typedef ReferenceCaller FreeMoveCameraFocusKeyDownCaller; +typedef ReferenceCaller FreeMoveCameraFocusKeyUpCaller; #define SPEED_MOVE 32 #define SPEED_TURN 22.5 @@ -1040,6 +1054,11 @@ void CamWnd_registerCommands( CamWnd& camwnd ){ FreeMoveCameraMoveDownKeyUpCaller( camwnd.getCamera() ) ); + GlobalKeyEvents_insert( "CameraFreeFocus", accelerator_null(), + FreeMoveCameraFocusKeyDownCaller( camwnd.getCamera() ), + FreeMoveCameraFocusKeyUpCaller( camwnd.getCamera() ) + ); + GlobalCommands_insert( "CameraForward", ReferenceCaller( camwnd.getCamera() ) ); GlobalCommands_insert( "CameraBack", ReferenceCaller( camwnd.getCamera() ) ); GlobalCommands_insert( "CameraLeft", ReferenceCaller( camwnd.getCamera() ) ); @@ -1188,6 +1207,8 @@ void CamWnd_Add_Handlers_FreeMove( CamWnd& camwnd ){ KeyEvent_connect( "CameraFreeMoveUp" ); KeyEvent_connect( "CameraFreeMoveDown" ); + + KeyEvent_connect( "CameraFreeFocus" ); } void CamWnd_Remove_Handlers_FreeMove( CamWnd& camwnd ){ @@ -1204,6 +1225,8 @@ void CamWnd_Remove_Handlers_FreeMove( CamWnd& camwnd ){ KeyEvent_disconnect( "CameraFreeMoveUp" ); KeyEvent_disconnect( "CameraFreeMoveDown" ); + KeyEvent_disconnect( "CameraFreeFocus" ); + g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler ); g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler ); g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler ); @@ -1693,23 +1716,22 @@ void GlobalCamera_ResetAngles(){ #include "select.h" -void GlobalCamera_FocusOnSelected(){ - CamWnd& camwnd = *g_camwnd; -/* - Vector3 angles( Camera_getAngles( camwnd ) ); +Vector3 Camera_getFocusPos( camera_t& camera ){ + Vector3 camorigin( Camera_getOrigin( camera ) ); + AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) ); + View& view = *( camera.m_view ); +#if 0 + Vector3 angles( Camera_getAngles( camera ) ); Vector3 radangles( degrees_to_radians( angles[0] ), degrees_to_radians( angles[1] ), degrees_to_radians( angles[2] ) ); Vector3 viewvector; viewvector[0] = cos( radangles[1] ) * cos( radangles[0] ); viewvector[1] = sin( radangles[1] ) * cos( radangles[0] ); viewvector[2] = sin( radangles[0] ); -*/ - Vector3 camorigin( Camera_getOrigin( camwnd ) ); - - AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) ); - - View& view = *( camwnd.getCamera().m_view ); - +#elif 0 Vector3 viewvector( -view.GetModelview()[2], -view.GetModelview()[6], -view.GetModelview()[10] ); +#elif 1 + Vector3 viewvector( -camera.vpn ); +#endif Plane3 frustumPlanes[4]; frustumPlanes[0] = plane3_translated( view.getFrustum().left, camorigin - aabb.origin ); @@ -1734,14 +1756,11 @@ void GlobalCamera_FocusOnSelected(){ } } } -/* - globalOutputStream() << viewvector << "\n"; - globalOutputStream() << view.GetModelview()[0] << " " << view.GetModelview()[1] << " " << view.GetModelview()[2] << " " << view.GetModelview()[3] << "\n" - << view.GetModelview()[4] << " " << view.GetModelview()[5] << " " << view.GetModelview()[6] << " " << view.GetModelview()[7] << "\n" - << view.GetModelview()[8] << " " << view.GetModelview()[9] << " " << view.GetModelview()[10] << " " << view.GetModelview()[11] << "\n" - << view.GetModelview()[12] << " " << view.GetModelview()[13] << " " << view.GetModelview()[14] << " " << view.GetModelview()[15] << "\n"; -*/ - Camera_setOrigin( camwnd, aabb.origin - viewvector * offset ); + return ( aabb.origin - viewvector * offset ); +} + +void GlobalCamera_FocusOnSelected(){ + Camera_setOrigin( *g_camwnd, Camera_getFocusPos( g_camwnd->getCamera() ) ); } void Camera_ChangeFloorUp(){ @@ -2053,6 +2072,8 @@ void CamWnd_Construct(){ GlobalShortcuts_insert( "CameraFreeMoveUp", accelerator_null() ); GlobalShortcuts_insert( "CameraFreeMoveDown", accelerator_null() ); + GlobalShortcuts_insert( "CameraFreeFocus", Accelerator( GDK_Tab ) ); + GlobalToggles_insert( "ShowStats", FreeCaller(), ToggleItem::AddCallbackCaller( g_show_stats ) ); GlobalPreferenceSystem().registerPreference( "ShowStats", BoolImportStringCaller( g_camwindow_globals_private.m_showStats ), BoolExportStringCaller( g_camwindow_globals_private.m_showStats ) ); diff --git a/radiant/select.cpp b/radiant/select.cpp index 651397ea..7a85f59d 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -450,9 +450,9 @@ void UpdateWorkzone_ForSelection(){ // update the workzone to the current selection void UpdateWorkzone_ForSelectionChanged( const Selectable& selectable ){ - if ( selectable.isSelected() ) { + //if ( selectable.isSelected() ) { UpdateWorkzone_ForSelection(); - } + //} } void Select_SetShader( const char* shader ){ -- 2.39.2