-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_3.10_cone_2_command.cpp
50 lines (39 loc) · 1.29 KB
/
example_3.10_cone_2_command.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCommand.h>
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
class vtkMyCallback : public vtkCommand {
public:
static auto New() -> vtkMyCallback* {
return new vtkMyCallback();
}
void Execute(vtkObject* caller, unsigned long, void*) override {
const auto render = reinterpret_cast<vtkRenderer*>(caller);
const auto camera_pos = render->GetActiveCamera()->GetPosition();
std::cout << camera_pos[0] << " " << camera_pos[1] << " " << camera_pos[2]
<< std::endl;
}
};
auto main() -> int {
const auto cone_source = vtkConeSource::New();
cone_source->SetResolution(500);
const auto cone_mapper = vtkPolyDataMapper::New();
cone_mapper->SetInputConnection(cone_source->GetOutputPort());
const auto cone_actor = vtkActor::New();
cone_actor->SetMapper(cone_mapper);
const auto render = vtkRenderer::New();
render->AddActor(cone_actor);
const auto wind = vtkRenderWindow::New();
wind->AddRenderer(render);
const auto call_back = vtkMyCallback::New();
render->AddObserver(vtkCommand::StartEvent, call_back);
call_back->Delete();
for (int i = 0; i < 360; ++i) {
wind->Render();
render->GetActiveCamera()->Azimuth(1);
}
return 0;
}