[vtkusers] vtk keyboard keys

aria dob minaninina1 at gmail.com
Thu Apr 7 09:39:47 EDT 2016


hi ,
i try this programme wich is true i guess but it doesn't work ,i don't khnow
why please help me 

#include "stdafx.h"
#include <vtkPolyData.h>
#include <vtkArrowSource.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataReader.h> 
#include <vtkProperty.h>
#include <vtkTextActor.h>
#include <vtkTextProperty.h>
#include <vtkTriangleFilter.h>
#include <vtkTriangleFilter.h>
#include <vtkOBBTree.h>	
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkDataSet.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include<vtkObjectFactory.h>

vtkSmartPointer<vtkActor> act =vtkSmartPointer<vtkActor>::New();
 vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow
=vtkSmartPointer<vtkRenderWindow>::New();

     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
=vtkSmartPointer<vtkRenderWindowInteractor>::New();

class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
	static KeyPressInteractorStyle* New();
	vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);

	virtual void OnKeyPress()
	{    double handpos[3] = {0.7,-1.2,2.6};
		  
       // Get the keypress
		vtkRenderWindowInteractor *rwi = this->Interactor;
		std::string key = rwi->GetKeySym();

		// Output the key that was pressed
		std::cout << "Pressed " << key << std::endl;

		// Handle an arrow key
		if (key == "Up")
		{   
			std::cout << "The up arrow was pressed." << std::endl;
			handpos[0]++;
			act->SetPosition(handpos[0], handpos[1], handpos[2]);
			renderer->Render();
			renderWindow->Render();
		}
		
		if (key == "a")
		{
			std::cout << "The up arrow was pressed." << std::endl;
			handpos[1]++;
			act->SetPosition(handpos[0], handpos[1], handpos[2]);
			renderer->Render();
			renderWindow->Render();
		}
		if (key == "h")
		{
			std::cout << "The up arrow was pressed." << std::endl;
			handpos[2]++;
			act->SetPosition(handpos[0], handpos[1], handpos[2]);
			renderer->Render();
			renderWindow->Render();
		}
		// Forward events
		vtkInteractorStyleTrackballCamera::OnKeyPress();
	}
};
vtkStandardNewMacro(KeyPressInteractorStyle);





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


More information about the vtkusers mailing list