SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
cameraWindow.h
Go to the documentation of this file.
1#ifndef CAMERAWINDOW_H
2#define CAMERAWINDOW_H
3
4#include <imgui/imgui.h>
5#include <imgui/imgui_impl_glfw.h>
6#include <imgui/imgui_impl_opengl3.h>
7
8#ifdef WINDOWS
9#include <imgui/imgui_impl_win32.h>
10#endif
11
12#ifdef MACOS
13#include <imgui/imgui_impl_osx.h>
14#endif
15
16#include <camera.h>
17#include <commandLine.h>
18#include <atom.h>
19#include <helpMarker.h>
20
26{
27public:
28
30
39 void draw
40 (
41 CommandLine & options
42 )
43 {
44 ImGui::Begin("Camera");
45 ImGui::Text("Zoom ");
46 ImGui::SameLine();
47
48 ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
49 if (ImGui::ArrowButton("##zoomin", ImGuiDir_Up)) { zoomQueue--; }
50 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
51 if (ImGui::ArrowButton("##zoomout", ImGuiDir_Down)) { zoomQueue++; }
52 ImGui::PopItemFlag();
53 ImGui::SameLine(); HelpMarker("Zoom to and from the focus (W/S)");
54
55 ImGui::Text("Rotate ");
56 ImGui::SameLine();
57
58 ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
59 if (ImGui::ArrowButton("##rotatel", ImGuiDir_Left)) { rotateQueue--; }
60 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
61 if (ImGui::ArrowButton("##rotater", ImGuiDir_Right)) { rotateQueue++; }
62 ImGui::PopItemFlag();
63 ImGui::SameLine(); HelpMarker("Rotate around the focus (A/D)");
64
65 ImGui::Text("Incline ");
66 ImGui::SameLine();
67
68 ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
69 if (ImGui::ArrowButton("##inclineu", ImGuiDir_Up)) { inclineQueue--; }
70 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
71 if (ImGui::ArrowButton("##inclined", ImGuiDir_Down)) { inclineQueue++; }
72 ImGui::PopItemFlag();
73 ImGui::SameLine(); HelpMarker("Incline around the focus (Q/E)");
74
75 ImGui::Text("Pan x ");
76 ImGui::SameLine();
77
78 ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
79 if (ImGui::ArrowButton("##panx-", ImGuiDir_Left)) { panxQueue--; }
80 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
81 if (ImGui::ArrowButton("##panx+", ImGuiDir_Right)) { panxQueue++; }
82 ImGui::PopItemFlag();
83 ImGui::SameLine(); HelpMarker("Pan in x (Left/Right)");
84
85 ImGui::Text("Pan y ");
86 ImGui::SameLine();
87
88 ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
89 if (ImGui::ArrowButton("##pany-", ImGuiDir_Left)) { panyQueue--; }
90 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
91 if (ImGui::ArrowButton("##pany+", ImGuiDir_Right)) { panyQueue++; }
92 ImGui::PopItemFlag();
93 ImGui::SameLine(); HelpMarker("Pan in y (Up/Down)");
94
95 ImGui::Text("Pan z ");
96 ImGui::SameLine();
97
98 ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true);
99 if (ImGui::ArrowButton("##panz-", ImGuiDir_Left)) { panzQueue--; }
100 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
101 if (ImGui::ArrowButton("##panz+", ImGuiDir_Right)) { panzQueue++; }
102 ImGui::PopItemFlag();
103 ImGui::SameLine(); HelpMarker("Pan in z (.//)");
104
105 ImGui::PushItemWidth(200);
106 ImGui::InputFloat("Zoom speed: ", &options.cameraZoomSpeed.value, 0.01f, 1.0f, "%.2f");
107 ImGui::SameLine(); HelpMarker("Modify zoom rate (CTRL-CLICK for faster steps)");
108
109 ImGui::PushItemWidth(200);
110 ImGui::InputFloat("Rotate speed: ", &options.cameraRotateSpeed.value, 0.01f, 1.0f, "%.2f");
111 ImGui::SameLine(); HelpMarker("Modify rotate rate (CTRL-CLICK for faster steps)");
112
113 ImGui::PushItemWidth(200);
114 ImGui::InputFloat("Incline speed: ", &options.cameraInclineSpeed.value, 0.01f, 1.0f, "%.2f");
115 ImGui::SameLine(); HelpMarker("Modify inclination rate (CTRL-CLICK for faster steps)");
116
117 ImGui::PushItemWidth(200);
118 ImGui::InputFloat("Pan speed: ", &options.cameraPanSpeed.value, 0.01f, 1.0f, "%.2f");
119 ImGui::SameLine(); HelpMarker("Modify pan rate (CTRL-CLICK for faster steps)");
120
121 if (ImGui::Button("Reset Camera "))
122 {
123 resetCamera = true;
124 }
125
126 ImGui::End();
127 }
128
141 (
142 Camera & camera,
143 std::vector<Atom> & atoms,
144 bool & atomsMoved,
145 const CommandLine & options,
146 const float & dr,
147 const float & dtheta,
148 const float & dphi
149 )
150 {
151 if (zoomQueue != 0)
152 {
153 camera.zoom(dr*options.cameraZoomSpeed.value*zoomQueue);
154 zoomQueue = 0;
155 atomsMoved = true;
156 }
157
158 if (rotateQueue != 0)
159 {
160 camera.rotate(dtheta*options.cameraRotateSpeed.value*rotateQueue);
161 rotateQueue = 0;
162 atomsMoved = true;
163 }
164
165 if (inclineQueue != 0)
166 {
167 camera.incline(dphi*options.cameraInclineSpeed.value*inclineQueue);
168 inclineQueue = 0;
169 atomsMoved = true;
170 }
171
172 if (resetCamera)
173 {
174 if (!options.noCentering.value) { center(atoms); }
175 if (options.focus.value < atoms.size()) { centerOn(atoms, options.focus.value); }
176 camera.reset(atoms);
177 atomsMoved = true;
178 resetCamera = false;
179 }
180
181 if (panxQueue != 0)
182 {
183 translate(atoms, {dr*options.cameraPanSpeed.value*panxQueue, 0.0, 0.0});
184 panxQueue = 0;
185 atomsMoved = true;
186 }
187
188 if (panyQueue != 0)
189 {
190 translate(atoms, {0.0, dr*options.cameraPanSpeed.value*panyQueue, 0.0});
191 panyQueue = 0;
192 atomsMoved = true;
193 }
194
195 if (panzQueue != 0)
196 {
197 translate(atoms, {0.0, 0.0, dr*options.cameraPanSpeed.value*panzQueue});
198 panzQueue = 0;
199 atomsMoved = true;
200 }
201 }
202
203private:
204
205 inline static int zoomQueue = 0;
206 inline static int rotateQueue = 0;
207 inline static int inclineQueue = 0;
208 inline static int panxQueue = 0;
209 inline static int panyQueue = 0;
210 inline static int panzQueue = 0;
211 inline static bool resetCamera = false;
212
213};
214
215#endif /* CAMERAWINDOW_H */
void center(std::vector< Atom > &atoms)
Subtract the centre of mass of some Atoms.
Definition atom.h:121
void centerOn(std::vector< Atom > &atoms, uint64_t index)
Centre on a particular Atom.
Definition atom.h:136
void translate(std::vector< Atom > &atoms, glm::vec3 r)
Definition atom.h:146
The camera controls window.
Definition cameraWindow.h:26
CameraWindow()
Definition cameraWindow.h:29
void applyQueueActions(Camera &camera, std::vector< Atom > &atoms, bool &atomsMoved, const CommandLine &options, const float &dr, const float &dtheta, const float &dphi)
Apply queued actions from the UI.
Definition cameraWindow.h:141
void draw(CommandLine &options)
Draw the window with Imgui.
Definition cameraWindow.h:40
A 3D projective camera centered on a focus moving on a sphere.
Definition camera.h:30
void reset()
Set the default view.
Definition camera.h:62
void rotate(float increment)
Rotate about the y OpenGL axis.
Definition camera.h:137
void zoom(float increment)
Increment the zoom.
Definition camera.h:111
void incline(float increment)
Incline about the y OpenGL axis.
Definition camera.h:118
const float dr
Definition main.h:38
const float dphi
Definition main.h:40
const float dtheta
Definition main.h:39
T value
Definition commandLine.h:33
Extract command line arguments.
Definition commandLine.h:240
Argument< uint64_t > focus
Definition commandLine.h:358
Argument< float > cameraRotateSpeed
Definition commandLine.h:360
Argument< float > cameraZoomSpeed
Definition commandLine.h:359
Argument< float > cameraPanSpeed
Definition commandLine.h:362
Argument< bool > noCentering
Definition commandLine.h:381
Argument< float > cameraInclineSpeed
Definition commandLine.h:361