前言
通过鼠标的左右键按键,实现模型的旋转操作(在一个平面内)
方法
继承vtkInteractorStyleTrackballCamera类,重写鼠标左右键操作,完成特定功能
class MouseInteractorHighLightActor222 : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorHighLightActor222* New();
vtkTypeMacro(MouseInteractorHighLightActor222, vtkInteractorStyleTrackballCamera);
MouseInteractorHighLightActor222(){
m_RotateZStep = 0.0;
LastPickedActor = NULL;
LastPickedProperty = vtkProperty::New();
}
virtual ~MouseInteractorHighLightActor222(){LastPickedProperty->Delete();}
//左键按下执行以下操作
virtual void OnLeftButtonDown()
{
this->LastPickedActor = tActor;
if (this->LastPickedActor)
{
// Save the property of the picked actor so that we can
// restore it next time
this->LastPickedProperty->DeepCopy(this->LastPickedActor->GetProperty());
// Highlight the picked actor by changing its properties
m_RotateZStep += 10.05;
this->LastPickedActor->GetCenter();//得到床的中心点(30,680,1080)
//this->LastPickedActor->SetPosition(222 + m_RotateZStep, 3333, 3333);
this->LastPickedActor->RotateZ(m_RotateZStep);
}
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
//右键按下执行以下操作
virtual void OnRightButtonDown()
{
this->LastPickedActor = tActor;
if (this->LastPickedActor)
{
// Save the property of the picked actor so that we can
// restore it next time
this->LastPickedProperty->DeepCopy(this->LastPickedActor->GetProperty());
// Highlight the picked actor by changing its properties
m_RotateZStep += 10.05;
this->LastPickedActor->RotateZ(m_RotateZStep);
}
// Forward events
vtkInteractorStyleTrackballCamera::OnRightButtonDown();
}
virtual void OnChar()
{
this->LastPickedActor = tActor;
switch (this->Interactor->GetKeyCode())
{
case VK_SPACE:
{
//if (this->LastPickedActor)
{
// Save the property of the picked actor so that we can
// restore it next time
this->LastPickedProperty->DeepCopy(this->LastPickedActor->GetProperty());
// Highlight the picked actor by changing its properties
m_RotateZStep += 10.05;
this->LastPickedActor->RotateZ(m_RotateZStep);
}
cout << "sssssss38up " << endl;
break;
}
case 26:
{
cout << "wertyuio " << endl;
break;
}
}
//vtkInteractorStyleTrackballCamera::OnRightButtonDown();
}
vtkActor *tActor;
double m_RotateZStep;
private:
vtkActor *LastPickedActor;
vtkProperty *LastPickedProperty;
};
vtkStandardNewMacro(MouseInteractorHighLightActor222);
效果