src/interactions.cpp
/***********************************************************
* Interaction between MouseMarker and Vertices
* -> Handles movement of vertices through mouse
***********************************************************/
Interaction between MouseMarker and Vertices
> Handles movement of vertices through mouse
Interaction between MouseMarker and Vertices > Handles movement of vertices through mouse
void interaction(const WorldSpace&     world, 
                 SimplexContainer&     objects,
                 MouseMarker&          mouse)
{
  Vec2 marker_world {};
  world.screen_to_world( mouse.marker_position(), 
                         marker_world );
  if (!mouse.simplex() )
  {
    Simplex* snap = nullptr;
    for (const auto& s_ptr : objects)
    {
      Vec2 diff = s_ptr->xy() - marker_world;
      Simplex* ptr = s_ptr.get();
      if (  diff.near_zero_values(0.005) 
         && typeid(*ptr) == typeid(Vertex))
      {
        snap = ptr;
        break;
      }
    }
    if (snap)
    { 
      mouse.hover( snap );
      if ( IsMouseButtonDown( MOUSE_BUTTON_RIGHT) )
      {
        mouse.simplex( snap );
        snap->active( true );
      }
    }
  }
  Simplex* mouse_simplex = mouse.simplex();
  if ( mouse_simplex )
  {
    if ( IsMouseButtonDown(MOUSE_BUTTON_RIGHT) )
    {
      if ( typeid(*mouse_simplex) == typeid(Vertex) )
      {
        Vertex* v = reinterpret_cast<Vertex*>(mouse_simplex);
        v->xy( marker_world );
        v->updating( true );
      }
    }
    if ( IsMouseButtonReleased( MOUSE_BUTTON_RIGHT ) )
    {
      mouse_simplex->active( false );
      mouse.simplex( nullptr );
    }
  }
}
void interaction ( const WorldSpace & world , SimplexContainer & objects , MouseMarker & mouse ) { Vec2 marker_world { } ; world . screen_to_world ( mouse . marker_position ( ) , marker_world ) ; if ( ! mouse . simplex ( ) ) { Simplex * snap = nullptr ; for ( const auto & s_ptr : objects ) { Vec2 diff = s_ptr -> xy ( ) - marker_world ; Simplex * ptr = s_ptr . get ( ) ; if ( diff . near_zero_values ( 0.005 ) && typeid ( * ptr ) == typeid ( Vertex ) ) { snap = ptr ; break ; } } if ( snap ) { mouse . hover ( snap ) ; if ( IsMouseButtonDown ( MOUSE_BUTTON_RIGHT ) ) { mouse . simplex ( snap ) ; snap -> active ( true ) ; } } } Simplex * mouse_simplex = mouse . simplex ( ) ; if ( mouse_simplex ) { if ( IsMouseButtonDown ( MOUSE_BUTTON_RIGHT ) ) { if ( typeid ( * mouse_simplex ) == typeid ( Vertex ) ) { Vertex * v = reinterpret_cast < Vertex * > ( mouse_simplex ) ; v -> xy ( marker_world ) ; v -> updating ( true ) ; } } if ( IsMouseButtonReleased ( MOUSE_BUTTON_RIGHT ) ) { mouse_simplex -> active ( false ) ; mouse . simplex ( nullptr ) ; } } }
Interaction between MouseMarker and Vertices
> Handles movement of vertices through mouse
Interaction between MouseMarker and Vertices > Handles movement of vertices through mouse
// No active object -> Find nearest object //-------------------------------------------------------- // Check if mouse is over any object // Object has been detected // Active object exists -> Move object //-------------------------------------------------------- // Move object // Release object