Commit 68fb97f4 authored by Frédéric Larue's avatar Frédéric Larue

Grabbing of objects in the 3D view improved.

parent 47dd55fb
...@@ -1627,13 +1627,16 @@ void GLViewer::enterGrabbingMode( bool translation ) ...@@ -1627,13 +1627,16 @@ void GLViewer::enterGrabbingMode( bool translation )
m_GrabbingBoundingBox.SetNull(); 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() )
{
d.second.BackupUserTransform();
for( auto c : d.second.boundingBox.Corners() ) for( auto c : d.second.boundingBox.Corners() )
m_GrabbingBoundingBox.Add( d.second.UserTransform().map(c) ); m_GrabbingBoundingBox.Add( d.second.UserTransform().map(c) );
}
if( !m_GrabbingBoundingBox.IsNull() ) if( !m_GrabbingBoundingBox.IsNull() )
{ {
m_IsGrabbingTranslationEnabled = translation; m_IsGrabbingTranslationEnabled = translation;
m_IsGrabbingRotationEnabled = !translation; m_IsGrabbingRotationEnabled = !translation;
m_GrabbingAxisConstraint = -1; m_GrabbingAxisConstraint = -1;
setCursor( QCursor(Qt::CursorShape::SizeAllCursor) ); setCursor( QCursor(Qt::CursorShape::SizeAllCursor) );
m_ClickMousePos = m_PrevMousePos = mapFromGlobal( cursor().pos() ); m_ClickMousePos = m_PrevMousePos = mapFromGlobal( cursor().pos() );
...@@ -1650,11 +1653,7 @@ void GLViewer::exitGrabbingMode( bool validateTransformations ) ...@@ -1650,11 +1653,7 @@ void GLViewer::exitGrabbingMode( bool validateTransformations )
if( validateTransformations ) if( validateTransformations )
d.second.displayable->onUpdatingTransformation( d.second.UserTransform() ); d.second.displayable->onUpdatingTransformation( d.second.UserTransform() );
else else
{ d.second.RestoreUserTransform();
QMatrix4x4 xf;
d.second.displayable->transformation( xf );
d.second.SetUserTransform( xf );
}
} }
m_IsGrabbingTranslationEnabled = m_IsGrabbingRotationEnabled = false; m_IsGrabbingTranslationEnabled = m_IsGrabbingRotationEnabled = false;
...@@ -1668,10 +1667,6 @@ void GLViewer::exitGrabbingMode( bool validateTransformations ) ...@@ -1668,10 +1667,6 @@ void GLViewer::exitGrabbingMode( bool validateTransformations )
void GLViewer::onGrabbing( QMouseEvent *evt ) void GLViewer::onGrabbing( QMouseEvent *evt )
{ {
#if 0
double dx = evt->pos().x() - m_PrevMousePos.x();
double dy = evt->pos().y() - m_PrevMousePos.y();
QVector3D constraintAxis( 0.0f, 0.0f, 0.0f ); QVector3D constraintAxis( 0.0f, 0.0f, 0.0f );
if( m_GrabbingAxisConstraint >= 0 ) if( m_GrabbingAxisConstraint >= 0 )
constraintAxis[m_GrabbingAxisConstraint] = 1.0f; constraintAxis[m_GrabbingAxisConstraint] = 1.0f;
...@@ -1679,72 +1674,24 @@ void GLViewer::onGrabbing( QMouseEvent *evt ) ...@@ -1679,72 +1674,24 @@ void GLViewer::onGrabbing( QMouseEvent *evt )
QMatrix4x4 xf; QMatrix4x4 xf;
if( m_IsGrabbingTranslationEnabled ) if( m_IsGrabbingTranslationEnabled )
{ {
double translationScale = 2.0 / (width()*projectionMatrix()(0,0)); double viewScale = 2.0 / (width()*projectionMatrix()(0,0));
if( !isProjectionOrthographic() ) if( !isProjectionOrthographic() )
translationScale *= distToFocusPoint(); viewScale *= distToFocusPoint();
dx *= translationScale;
dy *= translationScale;
if( m_GrabbingAxisConstraint < 0 )
xf.translate( dx*viewRotationMatrix().row(0).toVector3D() - dy*viewRotationMatrix().row(1).toVector3D() );
else
xf.translate( (dx-dy)*constraintAxis );
}
else //if( m_IsGrabbingRotationEnabled )
{
xf.translate( m_GrabbingBoundingBox.Center() );
if( m_GrabbingAxisConstraint < 0 )
xf.rotate( 0.5*dx, frontAxis() );
else
xf.rotate( 0.5*dx, constraintAxis );
xf.translate( -m_GrabbingBoundingBox.Center() );
}
for( auto &d : m_Displayables ) double dx = viewScale * (evt->pos().x() - m_ClickMousePos.x());
if( d.second.displayable->isSelected() && d.second.displayable->isGrabbable() ) double dy = viewScale * (evt->pos().y() - m_ClickMousePos.y());
d.second.SetUserTransform( xf * d.second.UserTransform() ); double dt = dx - dy;
m_PrevMousePos = evt->pos();
update();
#else
double dx, dy, dt;
QVector3D constraintAxis( 0.0f, 0.0f, 0.0f );
if( m_GrabbingAxisConstraint >= 0 )
constraintAxis[m_GrabbingAxisConstraint] = 1.0f;
QMatrix4x4 xf;
if( m_IsGrabbingTranslationEnabled )
{
double translationScale = 2.0 / (width()*projectionMatrix()(0,0));
if( !isProjectionOrthographic() )
translationScale *= distToFocusPoint();
if( evt->modifiers() & Qt::ControlModifier ) if( evt->modifiers() & Qt::ControlModifier )
{ {
double viewScale1 = m_View.metricGrid3D.currentSpacing(); double translationScale = m_View.metricGrid3D.currentSpacing();
double viewScale2 = viewScale1; double translationSpeed = translationScale;
if( evt->modifiers() & Qt::ShiftModifier ) if( evt->modifiers() & Qt::ShiftModifier )
viewScale2 *= 0.1; translationSpeed *= 0.1;
double ddx1 = int( translationScale*(m_PrevMousePos.x() - m_ClickMousePos.x()) / viewScale1 );
double ddy1 = int( translationScale*(m_PrevMousePos.y() - m_ClickMousePos.y()) / viewScale1 );
double ddt1 = int( translationScale*(m_PrevMousePos.x() - m_ClickMousePos.x() - m_PrevMousePos.y() + m_ClickMousePos.y()) / viewScale1 );
double ddx2 = int( translationScale*(evt->pos().x() - m_ClickMousePos.x()) / viewScale1 ); dx = translationSpeed * int(dx / translationScale);
double ddy2 = int( translationScale*(evt->pos().y() - m_ClickMousePos.y()) / viewScale1 ); dy = translationSpeed * int(dy / translationScale);
double ddt2 = int( translationScale*(evt->pos().x() - m_ClickMousePos.x() - evt->pos().y() + m_ClickMousePos.y()) / viewScale1 ); dt = translationSpeed * int(dt / translationScale);
dx = (ddx1 != ddx2)? viewScale2*(ddx2-ddx1) : 0.0;
dy = (ddy1 != ddy2)? viewScale2*(ddy2-ddy1) : 0.0;
dt = (ddt1 != ddt2)? viewScale2*(ddt2-ddt1) : 0.0;
}
else
{
dx = translationScale * (evt->pos().x() - m_PrevMousePos.x());
dy = translationScale * (evt->pos().y() - m_PrevMousePos.y());
dt = dx - dy;
} }
if( m_GrabbingAxisConstraint < 0 ) if( m_GrabbingAxisConstraint < 0 )
...@@ -1754,38 +1701,25 @@ void GLViewer::onGrabbing( QMouseEvent *evt ) ...@@ -1754,38 +1701,25 @@ void GLViewer::onGrabbing( QMouseEvent *evt )
} }
else //if( m_IsGrabbingRotationEnabled ) else //if( m_IsGrabbingRotationEnabled )
{ {
if( evt->modifiers() & Qt::ControlModifier ) double dt = 0.5*(evt->pos().x() - m_ClickMousePos.x());
{
double rotationScale1 = 15.0;
double rotationScale2 = rotationScale1;
if( evt->modifiers() & Qt::ShiftModifier )
rotationScale2 = 1.0;
double ddx1 = int( 0.5*(m_PrevMousePos.x() - m_ClickMousePos.x()) / rotationScale1 );
double ddx2 = int( 0.5*(evt->pos().x() - m_ClickMousePos.x()) / rotationScale1 );
dx = (ddx1 != ddx2)? rotationScale2*(ddx2-ddx1) : 0.0; if( evt->modifiers() & Qt::ControlModifier )
}
else
{ {
dx = 0.5*(evt->pos().x() - m_PrevMousePos.x()); double rotationScale = 15.0;
double rotationSpeed = (evt->modifiers() & Qt::ShiftModifier)? 1.0 : rotationScale;
dt = rotationSpeed * int(dt / rotationScale);
} }
xf.translate( m_GrabbingBoundingBox.Center() ); xf.translate( m_GrabbingBoundingBox.Center() );
if( m_GrabbingAxisConstraint < 0 ) xf.rotate( dt, m_GrabbingAxisConstraint < 0? frontAxis() : constraintAxis );
xf.rotate( dx, frontAxis() );
else
xf.rotate( dx, constraintAxis );
xf.translate( -m_GrabbingBoundingBox.Center() ); xf.translate( -m_GrabbingBoundingBox.Center() );
} }
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() )
d.second.SetUserTransform( xf * d.second.UserTransform() ); d.second.SetGrabbingTransform( xf );
m_PrevMousePos = evt->pos();
update(); update();
#endif
} }
......
...@@ -88,6 +88,7 @@ protected: ...@@ -88,6 +88,7 @@ protected:
class DisplayableInfo class DisplayableInfo
{ {
QMatrix4x4 backupTransform;
QMatrix4x4 userTransform; QMatrix4x4 userTransform;
QMatrix4x4 packingTransform; QMatrix4x4 packingTransform;
QMatrix4x4 fullTransform; QMatrix4x4 fullTransform;
...@@ -101,6 +102,9 @@ protected: ...@@ -101,6 +102,9 @@ protected:
inline const QMatrix4x4& UserTransform() const { return userTransform; } inline const QMatrix4x4& UserTransform() const { return userTransform; }
inline void SetPackingTransform( const QMatrix4x4& tr ) { packingTransform = tr; fullTransform = userTransform * tr; } inline void SetPackingTransform( const QMatrix4x4& tr ) { packingTransform = tr; fullTransform = userTransform * tr; }
inline const QMatrix4x4& GetTransform() const { return fullTransform; } inline const QMatrix4x4& GetTransform() const { return fullTransform; }
inline void BackupUserTransform() { backupTransform = userTransform; }
inline void RestoreUserTransform() { SetUserTransform( backupTransform ); }
inline void SetGrabbingTransform( const QMatrix4x4& tr ){ SetUserTransform( tr * backupTransform ); }
DisplayableInterface *displayable; DisplayableInterface *displayable;
QVector<SelectionManager*> selectionMgr; QVector<SelectionManager*> selectionMgr;
......
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