feat: disable camera spin/inertia by introducing a custom interactor style.r
This commit is contained in:
@@ -37,9 +37,29 @@
|
|||||||
#include <vtkTextProperty.h>
|
#include <vtkTextProperty.h>
|
||||||
#include <vtkAxesActor.h>
|
#include <vtkAxesActor.h>
|
||||||
#include <vtkCamera.h>
|
#include <vtkCamera.h>
|
||||||
|
#include <vtkInteractorStyleTrackballCamera.h>
|
||||||
|
#include <vtkObjectFactory.h>
|
||||||
|
|
||||||
#include "uLibVtkViewer.h"
|
#include "uLibVtkViewer.h"
|
||||||
|
|
||||||
|
// Custom interactor style: disables spin/inertia so the scene only
|
||||||
|
// rotates while the mouse is actively being moved with the button held.
|
||||||
|
class vtkInteractorStyleNoSpin : public vtkInteractorStyleTrackballCamera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static vtkInteractorStyleNoSpin *New();
|
||||||
|
vtkTypeMacro(vtkInteractorStyleNoSpin, vtkInteractorStyleTrackballCamera);
|
||||||
|
|
||||||
|
// Override: when the left button is released, immediately stop any
|
||||||
|
// ongoing motion (rotation/spin) so no momentum is carried over.
|
||||||
|
void OnLeftButtonUp() override
|
||||||
|
{
|
||||||
|
this->StopState();
|
||||||
|
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
vtkStandardNewMacro(vtkInteractorStyleNoSpin);
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
@@ -75,6 +95,11 @@ void Viewer::InstallPipe()
|
|||||||
vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
||||||
renderWindowInteractor->SetRenderWindow(m_RenderWindow);
|
renderWindowInteractor->SetRenderWindow(m_RenderWindow);
|
||||||
|
|
||||||
|
// Use a custom style with no spin/inertia
|
||||||
|
vtkSmartPointer<vtkInteractorStyleNoSpin> style =
|
||||||
|
vtkSmartPointer<vtkInteractorStyleNoSpin>::New();
|
||||||
|
renderWindowInteractor->SetInteractorStyle(style);
|
||||||
|
|
||||||
// annotation //
|
// annotation //
|
||||||
m_Annotation->GetTextProperty()->SetColor(1,1,1);
|
m_Annotation->GetTextProperty()->SetColor(1,1,1);
|
||||||
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
||||||
|
|||||||
Reference in New Issue
Block a user