Commit 47dd55fb authored by Frédéric Larue's avatar Frédéric Larue

Bug fixed in the rotation center computation during grabbing.

parent 3501a9e3
...@@ -1624,15 +1624,13 @@ void GLViewer::enterGrabbingMode( bool translation ) ...@@ -1624,15 +1624,13 @@ void GLViewer::enterGrabbingMode( bool translation )
if( dof() != DisplayDoF::DISPLAY_DOF_3D ) if( dof() != DisplayDoF::DISPLAY_DOF_3D )
return; return;
bool itemsAvailableForGrabbing = false; m_GrabbingBoundingBox.SetNull();
for( auto &d : m_Displayables ) for( auto &d : m_Displayables )
if( d.second.displayable->isSelected() && d.second.displayable->isGrabbable() ) if( d.second.displayable->isSelected() && d.second.displayable->isGrabbable() )
{ for( auto c : d.second.boundingBox.Corners() )
itemsAvailableForGrabbing = true; m_GrabbingBoundingBox.Add( d.second.UserTransform().map(c) );
break;
}
if( itemsAvailableForGrabbing ) if( !m_GrabbingBoundingBox.IsNull() )
{ {
m_IsGrabbingTranslationEnabled = translation; m_IsGrabbingTranslationEnabled = translation;
m_IsGrabbingRotationEnabled = !translation; m_IsGrabbingRotationEnabled = !translation;
...@@ -1695,18 +1693,12 @@ void GLViewer::onGrabbing( QMouseEvent *evt ) ...@@ -1695,18 +1693,12 @@ void GLViewer::onGrabbing( QMouseEvent *evt )
} }
else //if( m_IsGrabbingRotationEnabled ) else //if( m_IsGrabbingRotationEnabled )
{ {
Box3f selectionBox; xf.translate( m_GrabbingBoundingBox.Center() );
for( auto &d : m_Displayables )
if( d.second.displayable->isSelected() && d.second.displayable->isGrabbable() )
for( auto c : d.second.boundingBox.Corners() )
selectionBox.Add( d.second.UserTransform().map(c) );
xf.translate( selectionBox.Center() );
if( m_GrabbingAxisConstraint < 0 ) if( m_GrabbingAxisConstraint < 0 )
xf.rotate( 0.5*dx, frontAxis() ); xf.rotate( 0.5*dx, frontAxis() );
else else
xf.rotate( 0.5*dx, constraintAxis ); xf.rotate( 0.5*dx, constraintAxis );
xf.translate( -selectionBox.Center() ); xf.translate( -m_GrabbingBoundingBox.Center() );
} }
for( auto &d : m_Displayables ) for( auto &d : m_Displayables )
...@@ -1779,18 +1771,12 @@ void GLViewer::onGrabbing( QMouseEvent *evt ) ...@@ -1779,18 +1771,12 @@ void GLViewer::onGrabbing( QMouseEvent *evt )
dx = 0.5*(evt->pos().x() - m_PrevMousePos.x()); dx = 0.5*(evt->pos().x() - m_PrevMousePos.x());
} }
Box3f selectionBox; xf.translate( m_GrabbingBoundingBox.Center() );
for( auto &d : m_Displayables )
if( d.second.displayable->isSelected() && d.second.displayable->isGrabbable() )
for( auto c : d.second.boundingBox.Corners() )
selectionBox.Add( d.second.UserTransform().map(c) );
xf.translate( selectionBox.Center() );
if( m_GrabbingAxisConstraint < 0 ) if( m_GrabbingAxisConstraint < 0 )
xf.rotate( dx, frontAxis() ); xf.rotate( dx, frontAxis() );
else else
xf.rotate( dx, constraintAxis ); xf.rotate( dx, constraintAxis );
xf.translate( -selectionBox.Center() ); xf.translate( -m_GrabbingBoundingBox.Center() );
} }
for( auto &d : m_Displayables ) for( auto &d : m_Displayables )
......
...@@ -223,6 +223,7 @@ protected: ...@@ -223,6 +223,7 @@ protected:
bool m_IsCursorInside; bool m_IsCursorInside;
Box3f m_GrabbingBoundingBox;
bool m_IsGrabbingTranslationEnabled = false; bool m_IsGrabbingTranslationEnabled = false;
bool m_IsGrabbingRotationEnabled = false; bool m_IsGrabbingRotationEnabled = false;
int m_GrabbingAxisConstraint = -1; int m_GrabbingAxisConstraint = -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment