[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]<<endl<<p[1]<<endl<<p[2]<<endl<<endl;
//double *hzt;
//hzt=tr->GetPosition();
//cout<<endl<<hzt[0]<<endl<<hzt[1]<<endl<<hzt[2]<<endl;
double *hzc;
hzc=camera->GetPosition();
//cout<<endl<<hzc[0]<<endl<<hzc[1]<<endl<<hzc[2]<<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