[vtk-developers] update position when moving a sphere
M.M Mhiri
mhiri_m at hotmail.com
Fri Apr 13 05:32:07 EDT 2012
hi, i'm using multiple Style for the windows interactorso no way to use trackballActor.
i want to move a sphereSource with the key button
press up button to move on the x axis etc ...
the sphere is moving correctly but i have to clic anywhere to validate the movementor to update the position. I don't know how to resolve this.
why i have to clic to update the position of the sphere?
here is my code :------------------------------------------------------------------------
float posX =0.0;
float posY= 0.0;
float posZ =0.0;
vtkSphereSource *sphere0;
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public: static KeyPressInteractorStyle* New();
vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);
virtual void OnKeyPress()
{
// Get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
std::string key = rwi->GetKeySym();
// Output the key that was pressed
std::cout << "Pressed " << key << std::endl;
// pos x Right
if(key == "Right")
{
posX+=0.1;
sphere0->SetCenter(posX,posY,posZ);
sphere0->Update();
}
// pos x Left
if(key == "Left")
{
posX-=0.1;
sphere0->SetCenter(posX,posY,posZ);
sphere0->Update();
}
if(key == "Up")
{
posY+=0.1;
sphere0->SetCenter(posX,posY,posZ);
sphere0->Update();
}
if(key == "Down")
{
posY-=0.1;
sphere0->UpdateInformation();
sphere0->SetCenter(posX,posY,posZ);
sphere0->Update();
}
// Forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
};
vtkStandardNewMacro(KeyPressInteractorStyle);
int main(int, char *[])
{ sphere0 = vtkSphereSource::New();
sphere0->SetPhiResolution(50);
sphere0->SetThetaResolution(50);
sphere0->SetCenter(posX,posY,posZ);
sphere0->SetRadius(0.4);
sphere0->Update();
Mapper, Actor, etc .....
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20120413/4d75aeaa/attachment.html>
More information about the vtk-developers
mailing list