From 219e8badc54622e02c714065128c088ddb33e418 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Tue, 10 Jul 2018 01:09:20 +0200 Subject: [PATCH] position and rotation adjustment value snap mode in scenery editor, position adjustment for memory cells in scenery editor --- EU07.cpp | 2 ++ Globals.h | 1 + renderer.cpp | 2 +- scene.cpp | 23 +++++++++++++++++++ scene.h | 6 +++++ sceneeditor.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++------ sceneeditor.h | 8 +++++++ uilayer.cpp | 9 ++++++-- 8 files changed, 102 insertions(+), 10 deletions(-) diff --git a/EU07.cpp b/EU07.cpp index 281a8b38..0c0b8208 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -153,9 +153,11 @@ void key_callback( GLFWwindow *window, int key, int scancode, int action, int mo Global.shiftState = ( mods & GLFW_MOD_SHIFT ) ? true : false; Global.ctrlState = ( mods & GLFW_MOD_CONTROL ) ? true : false; + Global.altState = ( mods & GLFW_MOD_ALT ) ? true : false; // give the ui first shot at the input processing... if( true == UILayer.on_key( key, action ) ) { return; } + if( true == scene::Editor.on_key( key, action ) ) { return; } // ...if the input is left untouched, pass it on input::Keyboard.key( key, action ); diff --git a/Globals.h b/Globals.h index f141c17e..b9af0d59 100644 --- a/Globals.h +++ b/Globals.h @@ -23,6 +23,7 @@ struct global_settings { GLFWwindow *window{ nullptr }; bool shiftState{ false }; //m7todo: brzydko bool ctrlState{ false }; + bool altState{ false }; std::mt19937 random_engine{ std::mt19937( static_cast( std::time( NULL ) ) ) }; TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu TWorld *pWorld{ nullptr }; // wskaźnik na świat do usuwania pojazdów diff --git a/renderer.cpp b/renderer.cpp index 42be7b0e..a27fbb66 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -1670,7 +1670,7 @@ opengl_renderer::Render( scene::basic_region *Region ) { Update_Lights( simulation::Lights ); Render( std::begin( m_sectionqueue ), std::end( m_sectionqueue ) ); - if( EditorModeFlag && FreeFlyModeFlag && Global.ControlPicking ) { + if( EditorModeFlag && FreeFlyModeFlag ) { // when editor mode is active calculate world position of the cursor // at this stage the z-buffer is filled with only ground geometry Update_Mouse_Position(); diff --git a/scene.cpp b/scene.cpp index 4586f442..569af7e3 100644 --- a/scene.cpp +++ b/scene.cpp @@ -422,6 +422,18 @@ basic_cell::erase( TAnimModel *Instance ) { // TODO: update cell bounding area } +// removes provided memory cell from the cell +void +basic_cell::erase( TMemCell *Memorycell ) { + + m_memorycells.erase( + std::remove_if( + std::begin( m_memorycells ), std::end( m_memorycells ), + [=]( TMemCell *memorycell ) { + return memorycell == Memorycell; } ), + std::end( m_memorycells ) ); +} + // registers provided path in the lookup directory of the cell void basic_cell::register_end( TTrack *Path ) { @@ -1282,6 +1294,17 @@ basic_region::erase_instance( TAnimModel *Instance ) { } } +// removes specified memory cell from the region +void +basic_region::erase_memorycell( TMemCell *Memorycell ) { + + auto const location { Memorycell->location() }; + + if( point_inside( location ) ) { + section( location ).erase( Memorycell ); + } +} + // inserts provided sound in the region void basic_region::insert_sound( sound_source *Sound, scratch_data &Scratchpad ) { diff --git a/scene.h b/scene.h index 1b7be690..041c8443 100644 --- a/scene.h +++ b/scene.h @@ -129,6 +129,9 @@ public: // removes provided model instance from the cell void erase( TAnimModel *Instance ); + // removes provided memory cell from the cell + void + erase( TMemCell *Memorycell ); // find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance std::tuple find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ) const; @@ -361,6 +364,9 @@ public: // removes specified instance of 3d model from the region void erase_instance( TAnimModel *Instance ); + // removes specified memory cell from the region + void + erase_memorycell( TMemCell *Memorycell ); // find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance std::tuple find_vehicle( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ); diff --git a/sceneeditor.cpp b/sceneeditor.cpp index fec5381a..51289923 100644 --- a/sceneeditor.cpp +++ b/sceneeditor.cpp @@ -18,13 +18,26 @@ namespace scene { basic_editor Editor; +bool +basic_editor::on_key( int const Key, int const Action ) { + + if( false == EditorModeFlag ) { return false; } + + if( ( Key == GLFW_KEY_LEFT_ALT ) + || ( Key == GLFW_KEY_RIGHT_ALT ) ) { + // intercept these while in editor mode + return true; + } + + return false; +} + bool basic_editor::on_mouse_button( int const Button, int const Action ) { - if( false == EditorModeFlag ) { return false; } - // TBD: automatically activate and enforce picking mode and/or freefly mode when editor is active? - if( false == FreeFlyModeFlag ) { return false; } - if( false == Global.ControlPicking ) { return false; } + if( false == EditorModeFlag ) { return false; } + // TBD: automatically activate and enforce freefly mode when editor is active? + if( false == FreeFlyModeFlag ) { return false; } if( Button == GLFW_MOUSE_BUTTON_LEFT ) { @@ -89,12 +102,17 @@ basic_editor::translate( glm::dvec3 const &Location ) { auto *node { m_node }; // placeholder for operations on multiple nodes auto location { Location }; + if( false == mode_snap() ) { + location.y = node->location().y; + } if( typeid( *node ) == typeid( TAnimModel ) ) { - // TBD, TODO: don't modify y coordinate if snap-to-ground mode is active? -// location.y = node->location().y; translate_instance( static_cast( node ), location ); } + else if( typeid( *node ) == typeid( TMemCell ) ) { + translate_memorycell( static_cast( node ), location ); + } + } void @@ -110,6 +128,9 @@ basic_editor::translate( float const Offset ) { if( typeid( *node ) == typeid( TAnimModel ) ) { translate_instance( static_cast( node ), offset ); } + else if( typeid( *node ) == typeid( TMemCell ) ) { + translate_memorycell( static_cast( node ), offset ); + } } void @@ -128,6 +149,22 @@ basic_editor::translate_instance( TAnimModel *Instance, float const Offset ) { Instance->location( location ); } +void +basic_editor::translate_memorycell( TMemCell *Memorycell, glm::dvec3 const &Location ) { + + simulation::Region->erase_memorycell( Memorycell ); + Memorycell->location( Location ); + simulation::Region->insert_memorycell( Memorycell, scene::scratch_data() ); +} + +void +basic_editor::translate_memorycell( TMemCell *Memorycell, float const Offset ) { + + auto location { Memorycell->location() }; + location.y += Offset; + Memorycell->location( location ); +} + void basic_editor::rotate( glm::vec3 const &Angle ) { @@ -144,6 +181,10 @@ basic_editor::rotate_instance( TAnimModel *Instance, glm::vec3 const &Angle ) { // adjust node data glm::vec3 angle = glm::dvec3 { Instance->Angles() }; angle.y = clamp_circular( angle.y + Angle.y, 360.f ); + if( mode_snap() ) { + auto const quantizationstep { 15.f }; + angle.y = quantizationstep * std::round( angle.y * ( 1.f / quantizationstep ) ); + } Instance->Angles( angle ); // update scene } @@ -151,7 +192,7 @@ basic_editor::rotate_instance( TAnimModel *Instance, glm::vec3 const &Angle ) { bool basic_editor::mode_translation() const { - return ( false == Global.ctrlState ); + return ( false == Global.altState ); } bool @@ -160,6 +201,12 @@ basic_editor::mode_translation_vertical() const { return ( true == Global.shiftState ); } +bool +basic_editor::mode_snap() const { + + return ( true == Global.ctrlState ); +} + } // scene //--------------------------------------------------------------------------- diff --git a/sceneeditor.h b/sceneeditor.h index 74f96d4a..b69874b8 100644 --- a/sceneeditor.h +++ b/sceneeditor.h @@ -17,6 +17,8 @@ class basic_editor { public: // methods + bool + on_key( int const Key, int const Action ); bool on_mouse_button( int const Button, int const Action ); bool @@ -43,6 +45,8 @@ private: mode_translation() const; bool mode_translation_vertical() const; + bool + mode_snap() const; void translate( glm::dvec3 const &Location ); void @@ -51,6 +55,10 @@ private: translate_instance( TAnimModel *Instance, glm::dvec3 const &Location ); void translate_instance( TAnimModel *Instance, float const Offset ); + void + translate_memorycell( TMemCell *Memorycell, glm::dvec3 const &Location ); + void + translate_memorycell( TMemCell *Memorycell, float const Offset ); void rotate( glm::vec3 const &Angle ); void diff --git a/uilayer.cpp b/uilayer.cpp index d0f98db6..69fd954c 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -105,6 +105,13 @@ ui_layer::on_key( int const Key, int const Action ) { } if( Action == GLFW_RELEASE ) { return true; } // recognized, but ignored + + EditorModeFlag = ( Key == GLFW_KEY_F11 ); + if( ( true == EditorModeFlag ) + && ( false == Global.ControlPicking ) ) { + glfwSetInputMode( m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL ); + Global.ControlPicking = true; + } } default: { // everything else @@ -243,8 +250,6 @@ ui_layer::update() { "" ) ); } - EditorModeFlag = ( Global.iTextMode == GLFW_KEY_F11 ); - switch( Global.iTextMode ) { case( GLFW_KEY_F1 ) : {