[vtkusers] Camera movement

IvanKushnar ivan.kushnar at gmail.com
Thu Dec 13 17:18:53 EST 2012


ta-daaaa!

void CamMove(double loc[3])
{
			double p[3];
			//double loc[3]={5,0,0};
			vtkSmartPointer<vtkTransform> tr=vtkSmartPointer<vtkTransform>::New();

			//GetModelViewTransformObject()-матрица преобразования из глобальной в
камеру/локальную
			tr->Identity();
			tr->SetMatrix(camera->GetModelViewTransformObject()->GetMatrix());
			
			tr->Inverse();
			tr->TransformPoint(loc,p);
		
//cout<<p[0]&lt;&lt;endl&lt;&lt;p[1]&lt;&lt;endl&lt;&lt;p[2]&lt;&lt;endl&lt;&lt;endl;

			//double *hzt;
			//hzt=tr->GetPosition();
		
//cout<<endl&lt;&lt;hzt[0]&lt;&lt;endl&lt;&lt;hzt[1]&lt;&lt;endl&lt;&lt;hzt[2]&lt;&lt;endl;

			double *hzc;
			hzc=camera->GetPosition();
		
//cout<<endl&lt;&lt;hzc[0]&lt;&lt;endl&lt;&lt;hzc[1]&lt;&lt;endl&lt;&lt;hzc[2]&lt;&lt;endl;
	
			//change focus
			double camfoc[3];
			camera->GetFocalPoint(camfoc);
			for (int i=0;i<3;i++)
				camfoc[i]+=p[i]-hzc[i];

			camera->SetPosition(p);
			camera->SetFocalPoint(camfoc);


};

// Define interaction style
class MouseInteractorStyleDoubleClick : public
vtkInteractorStyleTrackballCamera
{
public:

	static MouseInteractorStyleDoubleClick* New();
	vtkTypeMacro(MouseInteractorStyleDoubleClick,
vtkInteractorStyleTrackballCamera);

	MouseInteractorStyleDoubleClick() : NumberOfClicks(0),
ResetPixelDistance(5) 
	{ 
		this->PreviousPosition[0] = 0;
		this->PreviousPosition[1] = 0;
	}
	virtual void OnKeyDown() 
	{
		// Get the keypress
		vtkRenderWindowInteractor *rwi = this->Interactor;
		std::string key = rwi->GetKeySym();

		if(key == "Up")
		{
                        double loc[3]={0,0,+delta_move};
			CamMove(loc);
			rwi->Render();
		}

	}
}



--
View this message in context: http://vtk.1045678.n5.nabble.com/Camera-movement-tp5717587p5717608.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list