small fix to camera focal points
This commit is contained in:
parent
0c32aaade1
commit
ab0916b9c7
|
|
@ -12,11 +12,17 @@ using std::string;
|
||||||
void CameraMoveCallback::Execute(vtkObject *caller, unsigned long evId,
|
void CameraMoveCallback::Execute(vtkObject *caller, unsigned long evId,
|
||||||
void *callData) {
|
void *callData) {
|
||||||
// Note the use of reinterpret_cast to cast the caller to the expected type.
|
// Note the use of reinterpret_cast to cast the caller to the expected type.
|
||||||
auto interactor = reinterpret_cast<vtkRenderWindowInteractor *>(caller);
|
auto intr = reinterpret_cast<vtkRenderWindowInteractor *>(caller);
|
||||||
|
|
||||||
switch (evId) {
|
switch (evId) {
|
||||||
case vtkCommand::KeyPressEvent:
|
case vtkCommand::KeyPressEvent:
|
||||||
pan(interactor->GetKeySym());
|
if (not strcmp("minus", intr->GetKeySym())) {
|
||||||
|
zoom(false);
|
||||||
|
} else if (not strcmp("equal", intr->GetKeySym())) {
|
||||||
|
zoom(true);
|
||||||
|
} else {
|
||||||
|
pan(intr->GetKeySym());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case vtkCommand::MouseWheelForwardEvent:
|
case vtkCommand::MouseWheelForwardEvent:
|
||||||
zoom(true);
|
zoom(true);
|
||||||
|
|
@ -27,18 +33,21 @@ void CameraMoveCallback::Execute(vtkObject *caller, unsigned long evId,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also calls the render function when the camera's position has not actually changed. This is a negligble inefficiency.
|
||||||
|
intr->GetRenderWindow()->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraMoveCallback::zoom(const bool in) {
|
void CameraMoveCallback::zoom(const bool in) {
|
||||||
double pos[3];
|
double scale = this->cam->GetParallelScale();
|
||||||
this->cam->GetPosition(pos);
|
|
||||||
|
|
||||||
if (in) {
|
if (in) {
|
||||||
pos[2] -= 50;
|
scale -= 1;
|
||||||
} else {
|
} else {
|
||||||
pos[2] += 50;
|
scale += 1;
|
||||||
}
|
}
|
||||||
this->cam->SetPosition(pos);
|
|
||||||
|
this->cam->SetParallelScale(scale);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,17 +57,16 @@ void CameraMoveCallback::pan(const string dir) {
|
||||||
|
|
||||||
if (dir == "Left" or dir == "h") {
|
if (dir == "Left" or dir == "h") {
|
||||||
pos[0] -= 1;
|
pos[0] -= 1;
|
||||||
this->cam->SetPosition(pos);
|
|
||||||
} else if (dir == "Up" or dir == "j" ) {
|
} else if (dir == "Up" or dir == "j" ) {
|
||||||
pos[1] += 1;
|
pos[1] += 1;
|
||||||
this->cam->SetPosition(pos);
|
|
||||||
} else if (dir == "Right" or dir == "k" ) {
|
} else if (dir == "Right" or dir == "k" ) {
|
||||||
pos[0] += 1;
|
pos[0] += 1;
|
||||||
this->cam->SetPosition(pos);
|
|
||||||
} else if (dir == "Down" or dir == "l" ) {
|
} else if (dir == "Down" or dir == "l" ) {
|
||||||
pos[1] -= 1;
|
pos[1] -= 1;
|
||||||
this->cam->SetPosition(pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->cam->SetPosition(pos);
|
||||||
|
this->cam->SetFocalPoint(pos[0], pos[1], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {}
|
CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue