]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/selection.cpp
Merge commit '667d3275589dac91b5bfe96f0244183007be6efd' into master-merge
[xonotic/netradiant.git] / radiant / selection.cpp
index 11e2337e0e63700348c4b790546f00f7d4291949..2ac9844517fd49c83203c2c6734afcc2d6cd5e33 100644 (file)
@@ -193,8 +193,8 @@ float distance_for_axis( const Vector3& a, const Vector3& b, const Vector3& axis
 class Manipulatable
 {
 public:
-virtual void Construct( const Matrix4& device2manip, const float x, const float y ) = 0;
-virtual void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ) = 0;
+virtual void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ) = 0;
+virtual void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ) = 0;
 };
 
 void transform_local2object( Matrix4& object, const Matrix4& local, const Matrix4& local2object ){
@@ -219,11 +219,11 @@ public:
 RotateFree( Rotatable& rotatable )
        : m_rotatable( rotatable ){
 }
-void Construct( const Matrix4& device2manip, const float x, const float y ){
+void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ){
        point_on_sphere( m_start, device2manip, x, y );
        vector3_normalise( m_start );
 }
-void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ){
+void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ){
        Vector3 current;
        point_on_sphere( current, device2manip, x, y );
 
@@ -256,12 +256,12 @@ public:
 RotateAxis( Rotatable& rotatable )
        : m_rotatable( rotatable ){
 }
-void Construct( const Matrix4& device2manip, const float x, const float y ){
+void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ){
        point_on_sphere( m_start, device2manip, x, y );
        constrain_to_axis( m_start, m_axis );
 }
 /// \brief Converts current position to a normalised vector orthogonal to axis.
-void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ){
+void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ){
        Vector3 current;
        point_on_sphere( current, device2manip, x, y );
        constrain_to_axis( current, m_axis );
@@ -300,20 +300,43 @@ class TranslateAxis : public Manipulatable
 Vector3 m_start;
 Vector3 m_axis;
 Translatable& m_translatable;
+AABB m_bounds;
 public:
 TranslateAxis( Translatable& translatable )
        : m_translatable( translatable ){
 }
-void Construct( const Matrix4& device2manip, const float x, const float y ){
+void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ){
        point_on_axis( m_start, m_axis, device2manip, x, y );
+       m_bounds = bounds;
 }
-void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ){
+void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ){
        Vector3 current;
        point_on_axis( current, m_axis, device2manip, x, y );
        current = vector3_scaled( m_axis, distance_for_axis( m_start, current, m_axis ) );
 
        translation_local2object( current, current, manip2object );
-       vector3_snap( current, GetSnapGridSize() );
+       if( snapbbox ){
+               float grid = GetSnapGridSize();
+               Vector3 maxs( m_bounds.origin + m_bounds.extents );
+               Vector3 mins( m_bounds.origin - m_bounds.extents );
+//             globalOutputStream() << "current: " << current << "\n";
+               for( std::size_t i = 0; i < 3; ++i ){
+                       if( m_axis[i] != 0.f ){
+                               float snapto1 = float_snapped( maxs[i] + current[i] , grid );
+                               float snapto2 = float_snapped( mins[i] + current[i] , grid );
+
+                               float dist1 = fabs( fabs( maxs[i] + current[i] ) - fabs( snapto1 ) );
+                               float dist2 = fabs( fabs( mins[i] + current[i] ) - fabs( snapto2 ) );
+
+//                             globalOutputStream() << "maxs[i] + current[i]: " << maxs[i] + current[i]  << "    snapto1: " << snapto1 << "   dist1: " << dist1 << "\n";
+//                             globalOutputStream() << "mins[i] + current[i]: " << mins[i] + current[i]  << "    snapto2: " << snapto2 << "   dist2: " << dist2 << "\n";
+                               current[i] = dist2 > dist1 ? snapto1 - maxs[i] : snapto2 - mins[i];
+                       }
+               }
+       }
+       else{
+               vector3_snap( current, GetSnapGridSize() );
+       }
 
        m_translatable.translate( current );
 }
@@ -328,14 +351,16 @@ class TranslateFree : public Manipulatable
 private:
 Vector3 m_start;
 Translatable& m_translatable;
+AABB m_bounds;
 public:
 TranslateFree( Translatable& translatable )
        : m_translatable( translatable ){
 }
-void Construct( const Matrix4& device2manip, const float x, const float y ){
+void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ){
        point_on_plane( m_start, device2manip, x, y );
+       m_bounds = bounds;
 }
-void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ){
+void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ){
        Vector3 current;
        point_on_plane( current, device2manip, x, y );
        current = vector3_subtracted( current, m_start );
@@ -352,15 +377,31 @@ void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const
        }
 
        translation_local2object( current, current, manip2object );
-       vector3_snap( current, GetSnapGridSize() );
+       if( snapbbox ){
+               float grid = GetSnapGridSize();
+               Vector3 maxs( m_bounds.origin + m_bounds.extents );
+               Vector3 mins( m_bounds.origin - m_bounds.extents );
+               //globalOutputStream() << "current: " << current << "\n";
+               for( std::size_t i = 0; i < 3; ++i ){
+                       if( fabs( current[i] ) > 0.000001f ){
+                               float snapto1 = float_snapped( maxs[i] + current[i] , grid );
+                               float snapto2 = float_snapped( mins[i] + current[i] , grid );
+
+                               float dist1 = fabs( fabs( maxs[i] + current[i] ) - fabs( snapto1 ) );
+                               float dist2 = fabs( fabs( mins[i] + current[i] ) - fabs( snapto2 ) );
+
+                               current[i] = dist2 > dist1 ? snapto1 - maxs[i] : snapto2 - mins[i];
+                       }
+               }
+       }
+       else{
+               vector3_snap( current, GetSnapGridSize() );
+       }
 
        m_translatable.translate( current );
 }
 };
 
-void GetSelectionAABB( AABB& bounds );
-const Matrix4& SelectionSystem_GetPivot2World();
-
 class Scalable
 {
 public:
@@ -377,25 +418,23 @@ Vector3 m_axis;
 Scalable& m_scalable;
 
 Vector3 m_choosen_extent;
+AABB m_bounds;
 
 public:
 ScaleAxis( Scalable& scalable )
        : m_scalable( scalable ){
 }
-void Construct( const Matrix4& device2manip, const float x, const float y ){
+void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ){
        point_on_axis( m_start, m_axis, device2manip, x, y );
 
-       AABB aabb;
-       GetSelectionAABB( aabb );
-       Vector3 transform_origin = vector4_to_vector3( SelectionSystem_GetPivot2World().t() );
        m_choosen_extent = Vector3(
-                                       std::max( aabb.origin[0] + aabb.extents[0] - transform_origin[0], - aabb.origin[0] + aabb.extents[0] + transform_origin[0] ),
-                                       std::max( aabb.origin[1] + aabb.extents[1] - transform_origin[1], - aabb.origin[1] + aabb.extents[1] + transform_origin[1] ),
-                                       std::max( aabb.origin[2] + aabb.extents[2] - transform_origin[2], - aabb.origin[2] + aabb.extents[2] + transform_origin[2] )
+                                       std::max( bounds.origin[0] + bounds.extents[0] - transform_origin[0], - bounds.origin[0] + bounds.extents[0] + transform_origin[0] ),
+                                       std::max( bounds.origin[1] + bounds.extents[1] - transform_origin[1], - bounds.origin[1] + bounds.extents[1] + transform_origin[1] ),
+                                       std::max( bounds.origin[2] + bounds.extents[2] - transform_origin[2], - bounds.origin[2] + bounds.extents[2] + transform_origin[2] )
                                                        );
-
+       m_bounds = bounds;
 }
-void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ){
+void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ){
        //globalOutputStream() << "manip2object: " << manip2object << "  device2manip: " << device2manip << "  x: " << x << "  y:" << y <<"\n";
        Vector3 current;
        point_on_axis( current, m_axis, device2manip, x, y );
@@ -418,8 +457,12 @@ void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const
                );
 
        for( std::size_t i = 0; i < 3; i++ ){
-               if( m_choosen_extent[i] > 0.0625f ){ //epsilon to prevent super high scale for set of models, having really small extent, formed by origins
+               if( m_choosen_extent[i] > 0.0625f && m_axis[i] != 0.f ){ //epsilon to prevent super high scale for set of models, having really small extent, formed by origins
                        scale[i] = ( m_choosen_extent[i] + delta[i] ) / m_choosen_extent[i];
+                       if( snapbbox ){
+                               float snappdwidth = float_snapped( scale[i] * m_bounds.extents[i] * 2.f, GetSnapGridSize() );
+                               scale[i] = snappdwidth / ( m_bounds.extents[i] * 2.f );
+                       }
                }
        }
        if( snap ){
@@ -445,24 +488,23 @@ Vector3 m_start;
 Scalable& m_scalable;
 
 Vector3 m_choosen_extent;
+AABB m_bounds;
 
 public:
 ScaleFree( Scalable& scalable )
        : m_scalable( scalable ){
 }
-void Construct( const Matrix4& device2manip, const float x, const float y ){
+void Construct( const Matrix4& device2manip, const float x, const float y, const AABB bounds, const Vector3 transform_origin ){
        point_on_plane( m_start, device2manip, x, y );
 
-       AABB aabb;
-       GetSelectionAABB( aabb );
-       Vector3 transform_origin = vector4_to_vector3( SelectionSystem_GetPivot2World().t() );
        m_choosen_extent = Vector3(
-                                       std::max( aabb.origin[0] + aabb.extents[0] - transform_origin[0], - aabb.origin[0] + aabb.extents[0] + transform_origin[0] ),
-                                       std::max( aabb.origin[1] + aabb.extents[1] - transform_origin[1], - aabb.origin[1] + aabb.extents[1] + transform_origin[1] ),
-                                       std::max( aabb.origin[2] + aabb.extents[2] - transform_origin[2], - aabb.origin[2] + aabb.extents[2] + transform_origin[2] )
+                                       std::max( bounds.origin[0] + bounds.extents[0] - transform_origin[0], - bounds.origin[0] + bounds.extents[0] + transform_origin[0] ),
+                                       std::max( bounds.origin[1] + bounds.extents[1] - transform_origin[1], - bounds.origin[1] + bounds.extents[1] + transform_origin[1] ),
+                                       std::max( bounds.origin[2] + bounds.extents[2] - transform_origin[2], - bounds.origin[2] + bounds.extents[2] + transform_origin[2] )
                                                        );
+       m_bounds = bounds;
 }
-void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap ){
+void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y, const bool snap, const bool snapbbox ){
        Vector3 current;
        point_on_plane( current, device2manip, x, y );
        Vector3 delta = vector3_subtracted( current, m_start );
@@ -486,6 +528,10 @@ void Transform( const Matrix4& manip2object, const Matrix4& device2manip, const
        for( std::size_t i = 0; i < 3; i++ ){
                if( m_choosen_extent[i] > 0.0625f ){
                        scale[i] = ( m_choosen_extent[i] + delta[i] ) / m_choosen_extent[i];
+                       if( snapbbox && start[i] != 0.f ){
+                               float snappdwidth = float_snapped( scale[i] * m_bounds.extents[i] * 2.f, GetSnapGridSize() );
+                               scale[i] = snappdwidth / ( m_bounds.extents[i] * 2.f );
+                       }
                }
        }
        //globalOutputStream() << "pre snap scale: " << scale <<"\n";
@@ -1845,6 +1891,59 @@ bool Scene_forEachPlaneSelectable_selectPlanes( scene::Graph& graph, Selector& s
        return !selectedPlanes.empty();
 }
 
+
+#include "brush.h"
+/*
+class TestedBrushPlanesSelectVeritces : public scene::Graph::Walker
+{
+SelectionTest& m_test;
+public:
+TestedBrushPlanesSelectVeritces( SelectionTest& test )
+       : m_test( test ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+       if ( path.top().get().visible() ) {
+               Selectable* selectable = Instance_getSelectable( instance );
+               if ( selectable != 0 && selectable->isSelected() ) {
+                       BrushInstance* brushInstance = Instance_getBrush( instance );
+                       if ( brushInstance != 0 ) {
+                               brushInstance->selectVerticesOnPlanes( m_test );
+                       }
+               }
+       }
+       return true;
+}
+};
+
+void Scene_forEachTestedBrushPlane_selectVertices( scene::Graph& graph, SelectionTest& test ){
+       graph.traverse( TestedBrushPlanesSelectVeritces( test ) );
+}
+*/
+class BrushPlanesSelectVeritces : public scene::Graph::Walker
+{
+SelectionTest& m_test;
+public:
+BrushPlanesSelectVeritces( SelectionTest& test )
+       : m_test( test ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+       if ( path.top().get().visible() ) {
+               Selectable* selectable = Instance_getSelectable( instance );
+               if ( selectable != 0 && selectable->isSelected() ) {
+                       BrushInstance* brushInstance = Instance_getBrush( instance );
+                       if ( brushInstance != 0 ) {
+                               brushInstance->selectVerticesOnPlanes( m_test );
+                       }
+               }
+       }
+       return true;
+}
+};
+
+void Scene_forEachBrushPlane_selectVertices( scene::Graph& graph, SelectionTest& test ){
+       graph.traverse( BrushPlanesSelectVeritces( test ) );
+}
+
 void Scene_Translate_Component_Selected( scene::Graph& graph, const Vector3& translation );
 void Scene_Translate_Selected( scene::Graph& graph, const Vector3& translation );
 void Scene_TestSelect_Primitive( Selector& selector, SelectionTest& test, const VolumeTest& volume );
@@ -2508,16 +2607,54 @@ std::list<Selectable*>& best(){
 }
 };
 
+class DeepBestSelector : public Selector
+{
+SelectionIntersection m_intersection;
+Selectable* m_selectable;
+SelectionIntersection m_bestIntersection;
+std::list<Selectable*> m_bestSelectable;
+public:
+DeepBestSelector() : m_bestIntersection( SelectionIntersection() ), m_bestSelectable( 0 ){
+}
+
+void pushSelectable( Selectable& selectable ){
+       m_intersection = SelectionIntersection();
+       m_selectable = &selectable;
+}
+void popSelectable(){
+       if ( m_intersection.equalEpsilon( m_bestIntersection, 0.25f, 2.f ) ) {
+               m_bestSelectable.push_back( m_selectable );
+               m_bestIntersection = m_intersection;
+       }
+       else if ( m_intersection < m_bestIntersection ) {
+               m_bestSelectable.clear();
+               m_bestSelectable.push_back( m_selectable );
+               m_bestIntersection = m_intersection;
+       }
+       m_intersection = SelectionIntersection();
+}
+void addIntersection( const SelectionIntersection& intersection ){
+       assign_if_closer( m_intersection, intersection );
+}
+
+std::list<Selectable*>& best(){
+       return m_bestSelectable;
+}
+};
+
+bool g_bAltDragManipulatorResize = false; //+select primitives in component modes
+bool g_bTmpComponentMode = false;
+
 class DragManipulator : public Manipulator
 {
 TranslateFree m_freeResize;
 TranslateFree m_freeDrag;
 ResizeTranslatable m_resize;
 DragTranslatable m_drag;
-SelectableBool m_dragSelectable;
+SelectableBool m_dragSelectable; //drag already selected stuff
 public:
 
-bool m_selected;
+bool m_selected; //selected temporally for drag
 
 DragManipulator() : m_freeResize( m_resize ), m_freeDrag( m_drag ), m_selected( false ){
 }
@@ -2537,12 +2674,38 @@ void testSelect( const View& view, const Matrix4& pivot2world ){
                Scene_TestSelect_Primitive( booleanSelector, test, view );
 
                if ( booleanSelector.isSelected() ) {
-                       selector.addSelectable( SelectionIntersection( 0, 0 ), &m_dragSelectable );
-                       m_selected = false;
+                       if( g_bAltDragManipulatorResize ){
+                               DeepBestSelector deepSelector;
+                               Scene_TestSelect_Component_Selected( deepSelector, test, view, SelectionSystem::eVertex );
+                               for ( std::list<Selectable*>::iterator i = deepSelector.best().begin(); i != deepSelector.best().end(); ++i )
+                               {
+                                       if ( !( *i )->isSelected() ) {
+                                               GlobalSelectionSystem().setSelectedAllComponents( false );
+                                       }
+                                       selector.addSelectable( SelectionIntersection( 0, 0 ), ( *i ) );
+                                       m_selected = true;
+                                       m_dragSelectable.setSelected( false );
+                               }
+                               if( deepSelector.best().empty() ){
+                                       //Scene_forEachTestedBrushPlane_selectVertices( GlobalSceneGraph(), test );     //todo? drag clicked face
+                                       Scene_forEachBrushPlane_selectVertices( GlobalSceneGraph(), test );
+                                       m_selected = true;
+                               }
+                       }
+                       else{
+                               selector.addSelectable( SelectionIntersection( 0, 0 ), &m_dragSelectable );
+                               m_selected = false;
+                       }
                }
                else
                {
-                       m_selected = Scene_forEachPlaneSelectable_selectPlanes( GlobalSceneGraph(), selector, test );
+                       if( g_bAltDragManipulatorResize ){
+                               Scene_forEachBrushPlane_selectVertices( GlobalSceneGraph(), test );
+                               m_selected = true;
+                       }
+                       else{
+                               m_selected = Scene_forEachPlaneSelectable_selectPlanes( GlobalSceneGraph(), selector, test );
+                       }
                }
        }
        else
@@ -2558,12 +2721,16 @@ void testSelect( const View& view, const Matrix4& pivot2world ){
                        selector.addSelectable( SelectionIntersection( 0, 0 ), ( *i ) );
                        m_dragSelectable.setSelected( true );
                }
+               if( GlobalSelectionSystem().countSelectedComponents() != 0 ){
+                       m_dragSelectable.setSelected( true );
+               }
        }
 
        for ( SelectionPool::iterator i = selector.begin(); i != selector.end(); ++i )
        {
                ( *i ).second->setSelected( true );
        }
+       g_bTmpComponentMode = m_selected;
 }
 
 void setSelected( bool select ){
@@ -2673,7 +2840,7 @@ Signal1<const Selectable&> m_selectionChanged_callbacks;
 void ConstructPivot() const;
 void setCustomPivotOrigin( Vector3& point ) const;
 public:
-void getSelectionAABB( AABB& bounds ) const;
+AABB getSelectionAABB() const;
 private:
 mutable bool m_pivotChanged;
 bool m_pivot_moving;
@@ -2870,7 +3037,7 @@ bool SelectManipulator( const View& view, const float device_point[2], const flo
 
                        Matrix4 device2manip;
                        ConstructDevice2Manip( device2manip, m_pivot2world_start, view.GetModelview(), view.GetProjection(), view.GetViewport() );
-                       m_manipulator->GetManipulatable()->Construct( device2manip, device_point[0], device_point[1] );
+                       m_manipulator->GetManipulatable()->Construct( device2manip, device_point[0], device_point[1], getSelectionAABB(), vector4_to_vector3( GetPivot2World().t() ) );
 
                        m_undo_begun = false;
                }
@@ -2994,7 +3161,7 @@ void SelectPoint( const View& view, const float device_point[2], const float dev
                                Scene_TestSelect_Component( selector, volume, scissored, eFace );
                        }
                        else{
-                               Scene_TestSelect( selector, volume, scissored, Mode(), ComponentMode() );
+                               Scene_TestSelect( selector, volume, scissored, g_bAltDragManipulatorResize ? ePrimitive : Mode(), ComponentMode() );
                        }
 
                        if ( !selector.failed() ) {
@@ -3143,7 +3310,7 @@ bool SelectPoint_InitPaint( const View& view, const float device_point[2], const
                                Scene_TestSelect_Component( selector, volume, scissored, eFace );
                        }
                        else{
-                               Scene_TestSelect( selector, volume, scissored, Mode(), ComponentMode() );
+                               Scene_TestSelect( selector, volume, scissored, g_bAltDragManipulatorResize ? ePrimitive : Mode(), ComponentMode() );
                        }
                        if ( !selector.failed() ){
                                SelectableSortedSet::iterator best = selector.begin();
@@ -3288,7 +3455,7 @@ void scaleSelected( const Vector3& scaling ){
        freezeTransforms();
 }
 
-void MoveSelected( const View& view, const float device_point[2], bool snap ){
+void MoveSelected( const View& view, const float device_point[2], bool snap, bool snapbbox ){
        if ( m_manipulator->isSelected() ) {
                if ( !m_undo_begun ) {
                        m_undo_begun = true;
@@ -3297,15 +3464,15 @@ void MoveSelected( const View& view, const float device_point[2], bool snap ){
 
                Matrix4 device2manip;
                ConstructDevice2Manip( device2manip, m_pivot2world_start, view.GetModelview(), view.GetProjection(), view.GetViewport() );
-               m_manipulator->GetManipulatable()->Transform( m_manip2pivot_start, device2manip, device_point[0], device_point[1], snap );
+               m_manipulator->GetManipulatable()->Transform( m_manip2pivot_start, device2manip, device_point[0], device_point[1], snap, snapbbox );
        }
 }
 
 /// \todo Support view-dependent nudge.
 void NudgeManipulator( const Vector3& nudge, const Vector3& view ){
-       if ( ManipulatorMode() == eTranslate || ManipulatorMode() == eDrag ) {
+//     if ( ManipulatorMode() == eTranslate || ManipulatorMode() == eDrag ) {
                translateSelected( nudge );
-       }
+//     }
 }
 
 void endMove();
@@ -3516,7 +3683,13 @@ void RadiantSelectionSystem::endMove(){
 
        if ( Mode() == ePrimitive ) {
                if ( ManipulatorMode() == eDrag ) {
-                       Scene_SelectAll_Component( false, SelectionSystem::eFace );
+                       g_bTmpComponentMode = false;
+                       if( g_bAltDragManipulatorResize ){
+                               Scene_SelectAll_Component( false, SelectionSystem::eVertex );
+                       }
+                       else{
+                               Scene_SelectAll_Component( false, SelectionSystem::eFace );
+                       }
                }
        }
 
@@ -3754,9 +3927,10 @@ void RadiantSelectionSystem::setCustomPivotOrigin( Vector3& point ) const {
        }
 }
 
-void RadiantSelectionSystem::getSelectionAABB( AABB& bounds ) const {
+AABB RadiantSelectionSystem::getSelectionAABB() const {
+       AABB bounds;
        if ( !nothingSelected() ) {
-               if ( Mode() == eComponent ) {
+               if ( Mode() == eComponent || g_bTmpComponentMode ) {
                        Scene_BoundsSelectedComponent( GlobalSceneGraph(), bounds );
                }
                else
@@ -3764,14 +3938,7 @@ void RadiantSelectionSystem::getSelectionAABB( AABB& bounds ) const {
                        Scene_BoundsSelected( GlobalSceneGraph(), bounds );
                }
        }
-}
-
-void GetSelectionAABB( AABB& bounds ){
-       getSelectionSystem().getSelectionAABB( bounds );
-}
-
-const Matrix4& SelectionSystem_GetPivot2World(){
-       return getSelectionSystem().GetPivot2World();
+       return bounds;
 }
 
 void RadiantSelectionSystem::renderSolid( Renderer& renderer, const VolumeTest& volume ) const {
@@ -3796,8 +3963,11 @@ void RadiantSelectionSystem::renderSolid( Renderer& renderer, const VolumeTest&
 #include "preferencesystem.h"
 #include "preferences.h"
 
+bool g_bLeftMouseClickSelector = true;
+
 void SelectionSystem_constructPreferences( PreferencesPage& page ){
        page.appendCheckBox( "", "Prefer point entities in 2D", getSelectionSystem().m_bPreferPointEntsIn2D );
+       page.appendCheckBox( "", "Left mouse click tunnel selector", g_bLeftMouseClickSelector );
 }
 void SelectionSystem_constructPage( PreferenceGroup& group ){
        PreferencesPage page( group.createPage( "Selection", "Selection System Settings" ) );
@@ -3825,6 +3995,7 @@ void SelectionSystem_Construct(){
        GlobalShaderCache().attachRenderable( getSelectionSystem() );
 
        GlobalPreferenceSystem().registerPreference( "PreferPointEntsIn2D", make_property_string( getSelectionSystem().m_bPreferPointEntsIn2D ) );
+       GlobalPreferenceSystem().registerPreference( "LeftMouseClickSelector", make_property_string( g_bLeftMouseClickSelector ) );
        SelectionSystem_registerPreferencesPage();
 }
 
@@ -3898,7 +4069,7 @@ const ModifierFlags c_modifier_copy_texture = c_modifierNone;
 class Selector_
 {
 RadiantSelectionSystem::EModifier modifier_for_state( ModifierFlags state ){
-       if ( ( state == c_modifier_toggle || state == c_modifier_toggle_face || state == c_modifier_face ) ) {
+       if ( ( state == c_modifier_toggle || state == c_modifier_toggle_face || state == c_modifier_face || state == c_modifierAlt ) ) {
                if( m_mouse2 ){
                        return RadiantSelectionSystem::eReplace;
                }
@@ -3968,7 +4139,9 @@ void testSelect_simpleM1( DeviceVector position ){
                modifier = RadiantSelectionSystem::eCycle;
        }
        getSelectionSystem().SelectPoint( *m_view, &position[0], &m_epsilon[0], modifier, false );*/
-       getSelectionSystem().SelectPoint( *m_view, &position[0], &m_epsilon[0], m_mouseMoved ? RadiantSelectionSystem::eReplace : RadiantSelectionSystem::eCycle, false );
+       if( g_bLeftMouseClickSelector ){
+               getSelectionSystem().SelectPoint( *m_view, &position[0], &m_epsilon[0], m_mouseMoved ? RadiantSelectionSystem::eReplace : RadiantSelectionSystem::eCycle, false );
+       }
        m_start = m_current = device_constrained( position );
 }
 
@@ -4047,7 +4220,7 @@ bool mouseDown( DeviceVector position ){
 }
 
 void mouseMoved( DeviceVector position ){
-       getSelectionSystem().MoveSelected( *m_view, &position[0], ( m_state & c_modifierShift ) == c_modifierShift );
+       getSelectionSystem().MoveSelected( *m_view, &position[0], ( m_state & c_modifierShift ) == c_modifierShift, ( m_state & c_modifierControl ) == c_modifierControl );
 }
 typedef MemberCaller<Manipulator_, void(DeviceVector), &Manipulator_::mouseMoved> MouseMovedCaller;
 
@@ -4117,18 +4290,14 @@ void onMouseDown( const WindowVector& position, ButtonIdentifier button, Modifie
                //m_selector.m_mouseMoved = false;
 
                DeviceVector devicePosition( window_to_normalised_device( position, m_width, m_height ) );
-               if ( modifiers == c_modifier_manipulator && m_manipulator.mouseDown( devicePosition ) ) {
+               g_bAltDragManipulatorResize = ( modifiers == c_modifierAlt ) ? true : false;
+               if ( ( modifiers == c_modifier_manipulator || ( modifiers == c_modifierAlt && getSelectionSystem().Mode() != SelectionSystem::eComponent ) ) && m_manipulator.mouseDown( devicePosition ) ) {
                        g_mouseMovedCallback.insert( MouseEventCallback( Manipulator_::MouseMovedCaller( m_manipulator ) ) );
                        g_mouseUpCallback.insert( MouseEventCallback( Manipulator_::MouseUpCaller( m_manipulator ) ) );
                }
                else
                {
-                       if ( button == c_button_select ) {
-                               m_selector.m_mouse2 = false;
-                       }
-                       else{
-                               m_selector.m_mouse2 = true;
-                       }
+                       m_selector.m_mouse2 = ( button == c_button_select ) ? false : true;
                        m_selector.mouseDown( devicePosition );
                        g_mouseMovedCallback.insert( MouseEventCallback( Selector_::MouseMovedCaller( m_selector ) ) );
                        g_mouseUpCallback.insert( MouseEventCallback( Selector_::MouseUpCaller( m_selector ) ) );