mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
position and rotation adjustment value snap mode in scenery editor, position adjustment for memory cells in scenery editor
This commit is contained in:
2
EU07.cpp
2
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.shiftState = ( mods & GLFW_MOD_SHIFT ) ? true : false;
|
||||||
Global.ctrlState = ( mods & GLFW_MOD_CONTROL ) ? 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...
|
// give the ui first shot at the input processing...
|
||||||
if( true == UILayer.on_key( key, action ) ) { return; }
|
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
|
// ...if the input is left untouched, pass it on
|
||||||
input::Keyboard.key( key, action );
|
input::Keyboard.key( key, action );
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ struct global_settings {
|
|||||||
GLFWwindow *window{ nullptr };
|
GLFWwindow *window{ nullptr };
|
||||||
bool shiftState{ false }; //m7todo: brzydko
|
bool shiftState{ false }; //m7todo: brzydko
|
||||||
bool ctrlState{ false };
|
bool ctrlState{ false };
|
||||||
|
bool altState{ false };
|
||||||
std::mt19937 random_engine{ std::mt19937( static_cast<unsigned int>( std::time( NULL ) ) ) };
|
std::mt19937 random_engine{ std::mt19937( static_cast<unsigned int>( std::time( NULL ) ) ) };
|
||||||
TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu
|
TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu
|
||||||
TWorld *pWorld{ nullptr }; // wskaźnik na świat do usuwania pojazdów
|
TWorld *pWorld{ nullptr }; // wskaźnik na świat do usuwania pojazdów
|
||||||
|
|||||||
@@ -1670,7 +1670,7 @@ opengl_renderer::Render( scene::basic_region *Region ) {
|
|||||||
Update_Lights( simulation::Lights );
|
Update_Lights( simulation::Lights );
|
||||||
|
|
||||||
Render( std::begin( m_sectionqueue ), std::end( m_sectionqueue ) );
|
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
|
// when editor mode is active calculate world position of the cursor
|
||||||
// at this stage the z-buffer is filled with only ground geometry
|
// at this stage the z-buffer is filled with only ground geometry
|
||||||
Update_Mouse_Position();
|
Update_Mouse_Position();
|
||||||
|
|||||||
23
scene.cpp
23
scene.cpp
@@ -422,6 +422,18 @@ basic_cell::erase( TAnimModel *Instance ) {
|
|||||||
// TODO: update cell bounding area
|
// 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
|
// registers provided path in the lookup directory of the cell
|
||||||
void
|
void
|
||||||
basic_cell::register_end( TTrack *Path ) {
|
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
|
// inserts provided sound in the region
|
||||||
void
|
void
|
||||||
basic_region::insert_sound( sound_source *Sound, scratch_data &Scratchpad ) {
|
basic_region::insert_sound( sound_source *Sound, scratch_data &Scratchpad ) {
|
||||||
|
|||||||
6
scene.h
6
scene.h
@@ -129,6 +129,9 @@ public:
|
|||||||
// removes provided model instance from the cell
|
// removes provided model instance from the cell
|
||||||
void
|
void
|
||||||
erase( TAnimModel *Instance );
|
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
|
// find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance
|
||||||
std::tuple<TDynamicObject *, float>
|
std::tuple<TDynamicObject *, float>
|
||||||
find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ) const;
|
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
|
// removes specified instance of 3d model from the region
|
||||||
void
|
void
|
||||||
erase_instance( TAnimModel *Instance );
|
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
|
// find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance
|
||||||
std::tuple<TDynamicObject *, float>
|
std::tuple<TDynamicObject *, float>
|
||||||
find_vehicle( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler );
|
find_vehicle( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler );
|
||||||
|
|||||||
@@ -18,13 +18,26 @@ namespace scene {
|
|||||||
|
|
||||||
basic_editor Editor;
|
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
|
bool
|
||||||
basic_editor::on_mouse_button( int const Button, int const Action ) {
|
basic_editor::on_mouse_button( int const Button, int const Action ) {
|
||||||
|
|
||||||
if( false == EditorModeFlag ) { return false; }
|
if( false == EditorModeFlag ) { return false; }
|
||||||
// TBD: automatically activate and enforce picking mode and/or freefly mode when editor is active?
|
// TBD: automatically activate and enforce freefly mode when editor is active?
|
||||||
if( false == FreeFlyModeFlag ) { return false; }
|
if( false == FreeFlyModeFlag ) { return false; }
|
||||||
if( false == Global.ControlPicking ) { return false; }
|
|
||||||
|
|
||||||
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
|
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 *node { m_node }; // placeholder for operations on multiple nodes
|
||||||
|
|
||||||
auto location { Location };
|
auto location { Location };
|
||||||
|
if( false == mode_snap() ) {
|
||||||
|
location.y = node->location().y;
|
||||||
|
}
|
||||||
|
|
||||||
if( typeid( *node ) == typeid( TAnimModel ) ) {
|
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<TAnimModel *>( node ), location );
|
translate_instance( static_cast<TAnimModel *>( node ), location );
|
||||||
}
|
}
|
||||||
|
else if( typeid( *node ) == typeid( TMemCell ) ) {
|
||||||
|
translate_memorycell( static_cast<TMemCell *>( node ), location );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -110,6 +128,9 @@ basic_editor::translate( float const Offset ) {
|
|||||||
if( typeid( *node ) == typeid( TAnimModel ) ) {
|
if( typeid( *node ) == typeid( TAnimModel ) ) {
|
||||||
translate_instance( static_cast<TAnimModel *>( node ), offset );
|
translate_instance( static_cast<TAnimModel *>( node ), offset );
|
||||||
}
|
}
|
||||||
|
else if( typeid( *node ) == typeid( TMemCell ) ) {
|
||||||
|
translate_memorycell( static_cast<TMemCell *>( node ), offset );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -128,6 +149,22 @@ basic_editor::translate_instance( TAnimModel *Instance, float const Offset ) {
|
|||||||
Instance->location( location );
|
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
|
void
|
||||||
basic_editor::rotate( glm::vec3 const &Angle ) {
|
basic_editor::rotate( glm::vec3 const &Angle ) {
|
||||||
|
|
||||||
@@ -144,6 +181,10 @@ basic_editor::rotate_instance( TAnimModel *Instance, glm::vec3 const &Angle ) {
|
|||||||
// adjust node data
|
// adjust node data
|
||||||
glm::vec3 angle = glm::dvec3 { Instance->Angles() };
|
glm::vec3 angle = glm::dvec3 { Instance->Angles() };
|
||||||
angle.y = clamp_circular( angle.y + Angle.y, 360.f );
|
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 );
|
Instance->Angles( angle );
|
||||||
// update scene
|
// update scene
|
||||||
}
|
}
|
||||||
@@ -151,7 +192,7 @@ basic_editor::rotate_instance( TAnimModel *Instance, glm::vec3 const &Angle ) {
|
|||||||
bool
|
bool
|
||||||
basic_editor::mode_translation() const {
|
basic_editor::mode_translation() const {
|
||||||
|
|
||||||
return ( false == Global.ctrlState );
|
return ( false == Global.altState );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -160,6 +201,12 @@ basic_editor::mode_translation_vertical() const {
|
|||||||
return ( true == Global.shiftState );
|
return ( true == Global.shiftState );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
basic_editor::mode_snap() const {
|
||||||
|
|
||||||
|
return ( true == Global.ctrlState );
|
||||||
|
}
|
||||||
|
|
||||||
} // scene
|
} // scene
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class basic_editor {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// methods
|
// methods
|
||||||
|
bool
|
||||||
|
on_key( int const Key, int const Action );
|
||||||
bool
|
bool
|
||||||
on_mouse_button( int const Button, int const Action );
|
on_mouse_button( int const Button, int const Action );
|
||||||
bool
|
bool
|
||||||
@@ -43,6 +45,8 @@ private:
|
|||||||
mode_translation() const;
|
mode_translation() const;
|
||||||
bool
|
bool
|
||||||
mode_translation_vertical() const;
|
mode_translation_vertical() const;
|
||||||
|
bool
|
||||||
|
mode_snap() const;
|
||||||
void
|
void
|
||||||
translate( glm::dvec3 const &Location );
|
translate( glm::dvec3 const &Location );
|
||||||
void
|
void
|
||||||
@@ -51,6 +55,10 @@ private:
|
|||||||
translate_instance( TAnimModel *Instance, glm::dvec3 const &Location );
|
translate_instance( TAnimModel *Instance, glm::dvec3 const &Location );
|
||||||
void
|
void
|
||||||
translate_instance( TAnimModel *Instance, float const Offset );
|
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
|
void
|
||||||
rotate( glm::vec3 const &Angle );
|
rotate( glm::vec3 const &Angle );
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -105,6 +105,13 @@ ui_layer::on_key( int const Key, int const Action ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( Action == GLFW_RELEASE ) { return true; } // recognized, but ignored
|
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
|
default: { // everything else
|
||||||
@@ -243,8 +250,6 @@ ui_layer::update() {
|
|||||||
"" ) );
|
"" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorModeFlag = ( Global.iTextMode == GLFW_KEY_F11 );
|
|
||||||
|
|
||||||
switch( Global.iTextMode ) {
|
switch( Global.iTextMode ) {
|
||||||
|
|
||||||
case( GLFW_KEY_F1 ) : {
|
case( GLFW_KEY_F1 ) : {
|
||||||
|
|||||||
Reference in New Issue
Block a user