feat (wip): implementing camera zooming and panning functionality
This commit is contained in:
74
vtk/src/commands/CameraMoveCallback.cpp
Normal file
74
vtk/src/commands/CameraMoveCallback.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "CameraMoveCallback.h"
|
||||
|
||||
#include <vtkVertex.h>
|
||||
#include <vtkRenderer.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkCommand.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
void CameraMoveCallback::Execute(vtkObject *caller, unsigned long evId,
|
||||
void *callData) {
|
||||
// Note the use of reinterpret_cast to cast the caller to the expected type.
|
||||
auto interactor = reinterpret_cast<vtkRenderWindowInteractor *>(caller);
|
||||
|
||||
switch (evId) {
|
||||
case vtkCommand::KeyPressEvent:
|
||||
pan(interactor->GetKeySym());
|
||||
break;
|
||||
case vtkCommand::MouseWheelForwardEvent:
|
||||
zoom(true);
|
||||
break;
|
||||
case vtkCommand::MouseWheelBackwardEvent:
|
||||
zoom(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraMoveCallback::zoom(const bool in) {
|
||||
double pos[3];
|
||||
this->cam->GetPosition(pos);
|
||||
|
||||
if (in) {
|
||||
pos[2] -= 50;
|
||||
} else {
|
||||
pos[2] += 50;
|
||||
}
|
||||
this->cam->SetPosition(pos);
|
||||
|
||||
}
|
||||
|
||||
void CameraMoveCallback::pan(const string dir) {
|
||||
double pos[3];
|
||||
this->cam->GetPosition(pos);
|
||||
|
||||
if (dir == "Left" or dir == "h") {
|
||||
pos[0] -= 1;
|
||||
this->cam->SetPosition(pos);
|
||||
} else if (dir == "Up" or dir == "j" ) {
|
||||
pos[1] += 1;
|
||||
this->cam->SetPosition(pos);
|
||||
} else if (dir == "Right" or dir == "k" ) {
|
||||
pos[0] += 1;
|
||||
this->cam->SetPosition(pos);
|
||||
} else if (dir == "Down" or dir == "l" ) {
|
||||
pos[1] -= 1;
|
||||
this->cam->SetPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {}
|
||||
|
||||
CameraMoveCallback *CameraMoveCallback::New(vtkCamera *cam) {
|
||||
auto me = new CameraMoveCallback;
|
||||
me->setCam(cam);
|
||||
return me;
|
||||
}
|
||||
|
||||
void CameraMoveCallback::setCam(const vtkSmartPointer<vtkCamera> &cam) {
|
||||
this->cam = cam;
|
||||
}
|
||||
27
vtk/src/commands/CameraMoveCallback.h
Normal file
27
vtk/src/commands/CameraMoveCallback.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef VTKBASE_CAMERAMOVECALLBACK_H
|
||||
#define VTKBASE_CAMERAMOVECALLBACK_H
|
||||
|
||||
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include <vtkCamera.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkMatrix4x4.h>
|
||||
|
||||
class CameraMoveCallback : public vtkCallbackCommand {
|
||||
|
||||
public:
|
||||
static CameraMoveCallback *New(vtkCamera *cam);
|
||||
CameraMoveCallback();
|
||||
|
||||
void setCam(const vtkSmartPointer<vtkCamera> &cam);
|
||||
|
||||
private:
|
||||
vtkSmartPointer<vtkCamera> cam;
|
||||
|
||||
void Execute(vtkObject *caller, unsigned long evId, void *callData) override;
|
||||
void zoom(const bool in);
|
||||
void pan(const std::string dir);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -39,7 +39,7 @@ void SpawnPointCallback::Execute(vtkObject *caller, unsigned long evId, void *ca
|
||||
ren->DisplayToWorld();
|
||||
ren->GetWorldPoint(worldPos);
|
||||
inverseCartographicProjection->MultiplyPoint(worldPos, worldPos);
|
||||
cout << "clicked on lon = " << worldPos[0] << " and lat = " << worldPos[1] << endl;
|
||||
// cout << "clicked on lon = " << worldPos[0] << " and lat = " << worldPos[1] << endl;
|
||||
|
||||
vtkIdType id = points->InsertNextPoint(worldPos[0], worldPos[1], 0);
|
||||
data->SetPoints(points);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "../Program.h"
|
||||
|
||||
|
||||
// TODO: add getter/setters to attributes for customizability.
|
||||
TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {}
|
||||
|
||||
TimerCallbackCommand* TimerCallbackCommand::New(Program *program) {
|
||||
@@ -22,7 +23,6 @@ void TimerCallbackCommand::Execute(vtkObject* caller, unsigned long eventId, voi
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TimerCallbackCommand::setProgram(Program *program) {
|
||||
this->program = program;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user