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