When I use vtkLineWidget2, when it rotates, its handle does not follow its rotation
This is the core codeļ¼
{ vtkNew line;
line->SetInteractor(Interactor);
line->SetCurrentRenderer(renderer);
//mLine->SetPlaceFactor(1.0);
line->SetEnabled(1);
vtkNew<vtkLineRepresentation> lineRep;
lineRep->SetPoint1WorldPosition(picked);
lineRep->SetPlaceFactor(1.0);
vtkNew<vtkActorCollection> actors;
lineRep->GetActors(actors);
lineRep->SetLineColor(0, 1, 0);
actors->InitTraversal();
vtkNew<vtkTransform> transform;
mLine2TransformMap[line.Get()] = transform.Get();
while (vtkActor* actor = actors->GetNextActor())
{
actor->SetUserTransform(transform);
}
line->SetRepresentation(lineRep);
line->On();
}
void CustomVtkInteractorStyleRuler::Rotate() {
if (!mPicked) {
CustomVtkInteractorStyleCtrlModel::Rotate();
int dx = this->Interactor->GetEventPosition()[0] - this->Interactor->GetLastEventPosition()[0];
int dy = this->Interactor->GetEventPosition()[1] - this->Interactor->GetLastEventPosition()[1];
double angleX = dx * 0.5; // Adjust sensitivity
double angleY = dy * 0.5;
for (auto kvp : mLine2TransformMap)
{
vtkTransform* transform = kvp.second;
transform->PostMultiply();
transform->RotateY(angleX);
transform->RotateX(-angleY);
}
}
else
{
......
}
}