position and rotation adjustment value snap mode in scenery editor, position adjustment for memory cells in scenery editor

This commit is contained in:
tmj-fstate
2018-07-10 01:09:20 +02:00
parent e01f05f57c
commit 219e8badc5
8 changed files with 102 additions and 10 deletions

View File

@@ -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 );

View File

@@ -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<unsigned int>( std::time( NULL ) ) ) };
TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu
TWorld *pWorld{ nullptr }; // wskaźnik na świat do usuwania pojazdów

View File

@@ -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();

View File

@@ -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 ) {

View File

@@ -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<TDynamicObject *, float>
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<TDynamicObject *, float>
find_vehicle( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler );

View File

@@ -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?
// TBD: automatically activate and enforce freefly mode when editor is active?
if( false == FreeFlyModeFlag ) { return false; }
if( false == Global.ControlPicking ) { 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<TAnimModel *>( node ), location );
}
else if( typeid( *node ) == typeid( TMemCell ) ) {
translate_memorycell( static_cast<TMemCell *>( node ), location );
}
}
void
@@ -110,6 +128,9 @@ basic_editor::translate( float const Offset ) {
if( typeid( *node ) == typeid( TAnimModel ) ) {
translate_instance( static_cast<TAnimModel *>( node ), offset );
}
else if( typeid( *node ) == typeid( TMemCell ) ) {
translate_memorycell( static_cast<TMemCell *>( 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
//---------------------------------------------------------------------------

View File

@@ -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

View File

@@ -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 ) : {