Skip to content

Commit

Permalink
Merge branch 'master' into fix-linux-sumo-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
stefaniapedrazzi authored Jun 21, 2023
2 parents 1087edb + 99094bf commit 93976cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/webots/app/WbSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void WbSelection::selectNodeFromSceneTree(WbBaseNode *node) {
return;
selectNode(node);
emit selectionChangedFromSceneTree(mSelectedAbstractPose);
if (mSelectedAbstractPose)
updateHandlesScale();
}

void WbSelection::selectPoseFromView3D(WbAbstractPose *p, bool handlesDisabled) {
Expand Down
29 changes: 13 additions & 16 deletions src/webots/gui/WbDragPoseEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ WbDragTranslateAlongAxisEvent::WbDragTranslateAlongAxisEvent(const QPoint &initi
mHandleNumber(handleNumber),
mManipulator(selectedPose->translateRotateManipulator()),
mWidgetSizeFactor(1.0 / widgetSize.width(), 1.0 / widgetSize.height()),
mStepSize(selectedPose->translationStep()) {
mStepSize(selectedPose->translationStep()),
mAbsoluteScale(1.0) {
mCoordinate = mManipulator->coordinate(mHandleNumber);

mManipulator->highlightAxis(mHandleNumber);
Expand All @@ -182,12 +183,11 @@ WbDragTranslateAlongAxisEvent::WbDragTranslateAlongAxisEvent(const QPoint &initi
mTextOverlay->applyChangesToWren();

WbMatrix4 matrix(mSelectedPose->matrix());

const WbTransform *t = dynamic_cast<const WbTransform *>(mSelectedPose);
if (t) {
const WbVector3 &scale = t->scale();
matrix.scale(1.0f / scale.x(), 1.0f / scale.y(), 1.0f / scale.z());
}
const WbVector3 &scale = matrix.scale();
matrix.scale(1.0f / scale.x(), 1.0f / scale.y(), 1.0f / scale.z());
const WbTransform *pt = mSelectedPose->baseNode()->upperTransform();
if (pt)
mAbsoluteScale = pt->absoluteScale()[mCoordinate];

// local offset
const WbVector3 attachedHandlePosition(matrix *
Expand All @@ -198,7 +198,7 @@ WbDragTranslateAlongAxisEvent::WbDragTranslateAlongAxisEvent(const QPoint &initi
mHandleOffset = WbVector3(0.0, 0.0, 0.0);
mHandleOffset[mCoordinate] = mouse3dPosition[mCoordinate];
if (mStepSize > 0)
mHandleOffset[mCoordinate] -= mStepSize * 0.5;
mHandleOffset[mCoordinate] -= mStepSize * 0.5 * mAbsoluteScale;
mMouseOffset =
(mViewDistanceUnscaling * mManipulator->relativeHandlePosition(mHandleNumber)[mCoordinate]) - mouse3dPosition[mCoordinate];

Expand Down Expand Up @@ -228,19 +228,16 @@ void WbDragTranslateAlongAxisEvent::apply(const QPoint &currentMousePosition) {
mViewDistanceUnscaling = mViewpoint->viewDistanceUnscaling(mSelectedPose->position());

WbMatrix4 matrix(mSelectedPose->matrix());
const WbTransform *t = dynamic_cast<const WbTransform *>(mSelectedPose);
if (t) {
const WbVector3 &scale = t->scale();
matrix.scale(1.0f / scale.x(), 1.0f / scale.y(), 1.0f / scale.z());
}
const WbVector3 &scale = matrix.scale();
matrix.scale(1.0f / scale.x(), 1.0f / scale.y(), 1.0f / scale.z());

WbVector3 attachedHandlePosition = matrix * (mManipulator->relativeHandlePosition(mHandleNumber) * mViewDistanceUnscaling);
const double zEye = mViewpoint->zEye(attachedHandlePosition);

WbVector3 detachedHandlePosition = mViewpoint->pick(currentMousePosition.x(), currentMousePosition.y(), zEye);
detachedHandlePosition = matrix.pseudoInversed(detachedHandlePosition); // local position

const double difference = detachedHandlePosition[mCoordinate] - mHandleOffset[mCoordinate];
const double difference = (detachedHandlePosition[mCoordinate] - mHandleOffset[mCoordinate]) / mAbsoluteScale;
WbVector3 translationOffset;
if (mStepSize <= 0)
translationOffset[mCoordinate] = difference;
Expand Down Expand Up @@ -271,8 +268,8 @@ void WbDragTranslateAlongAxisEvent::apply(const QPoint &currentMousePosition) {
if (mTranslationOffset > -1e-10 && mTranslationOffset < +1e-10)
mTextOverlay->updateText("0.00 m");
else {
int left = mTranslationOffset;
int right = abs(100 * (mTranslationOffset - left));
const int left = mTranslationOffset;
const int right = abs(100 * (mTranslationOffset - left));
mTextOverlay->updateText((mTranslationOffset < 0 ? "-" : "") + QString::number(abs(left)) +
QString(".%1").arg(right, 2, 10, QChar('0')) + " m");
}
Expand Down
1 change: 1 addition & 0 deletions src/webots/gui/WbDragPoseEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class WbDragTranslateAlongAxisEvent : public WbDragPoseEvent {
WbVector2 mWidgetSizeFactor;
double mStepSize;
WbVector2 mDirectionOnScreen;
double mAbsoluteScale;
};

class WbDragRotateAroundWorldVerticalAxisEvent : public WbDragPoseEvent {
Expand Down
6 changes: 6 additions & 0 deletions src/webots/nodes/WbAbstractPose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ void WbAbstractPose::updateTranslateRotateHandlesSize() {
if (!mTranslateRotateManipulator)
return;

const WbTransform *transform = dynamic_cast<WbTransform *>(mBaseNode);
if (!transform)
transform = mBaseNode->upperTransform();
if (transform)
mTranslateRotateManipulator->updateHandleScale(transform->absoluteScale().ptr());

if (!WbNodeUtilities::isNodeOrAncestorLocked(mBaseNode))
mTranslateRotateManipulator->computeHandleScaleFromViewportSize();
}

0 comments on commit 93976cd

Please sign in to comment.