Assembly: Ball drag mode. (#26222)

This commit is contained in:
PaddleStroke
2025-12-16 19:08:50 +01:00
committed by GitHub
parent a13502dccb
commit 8fd81d4109

View File

@@ -503,6 +503,28 @@ bool ViewProviderAssembly::tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInv
Base::Placement jcsPlcRelativeToPart = plc.inverse() * jcsGlobalPlc;
plc = rotatedGlovalJcsPlc * jcsPlcRelativeToPart.inverse();
}
else if (dragMode == DragMode::Ball) {
Base::Vector3d center = jcsGlobalPlc.getPosition();
// Vectors from joint center to initial click and current drag position
Base::Vector3d u = initialPosition - center;
Base::Vector3d v = newPos - center;
// Ensure vectors are valid to prevent singularities
if (u.Length() > Precision::Confusion() && v.Length() > Precision::Confusion()) {
// Calculate rotation that moves vector u to v
Base::Rotation rot;
rot.setValue(u, v);
// Apply this rotation to the global joint placement (around the joint center)
Base::Placement rotatedGlobalJcsPlc = jcsGlobalPlc;
rotatedGlobalJcsPlc.setRotation(rot * jcsGlobalPlc.getRotation());
// Calculate the initial offset of the part relative to the joint
// and apply the new global joint placement to find the new part placement.
Base::Placement jcsPlcRelativeToPart = plc.inverse() * jcsGlobalPlc;
plc = rotatedGlobalJcsPlc * jcsPlcRelativeToPart.inverse();
}
}
else if (dragMode == DragMode::TranslationOnAxis) {
Base::Vector3d pos = plc.getPosition() + (newPos - initialPosition);
plc.setPosition(pos);
@@ -942,7 +964,7 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
return DragMode::TranslationOnAxisAndRotationOnePlane;
}
else if (jointType == JointType::Ball) {
// return DragMode::Ball;
return DragMode::Ball;
}
else if (jointType == JointType::Distance) {
// depends on the type of distance. For example plane-plane: