(06)vtk修改默认鼠标操作,实现鼠标按键控制模型旋转

本文介绍了一种自定义的交互式VTK类MouseInteractorHighLightActor222,它通过继承vtkInteractorStyleTrackballCamera,实现了通过鼠标左右键在平面上旋转模型,并能高亮选定对象。通过实例展示了如何保存和恢复选中对象的属性以及旋转操作的细节。
摘要由CSDN通过智能技术生成

前言

通过鼠标的左右键按键,实现模型的旋转操作(在一个平面内)

方法

继承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);

效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rexinx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值