Number5
Visualisierung 2 Project - Florian Schober (0828151, f.schober@live.com), Andreas Walch (0926780, walch.andreas89@gmail.com)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Picker.cpp
Go to the documentation of this file.
1 #include "Application.hpp"
2 
3 
4 
6  : m_app(app)
7  , m_hasFocusId(false)
8  , m_focusId(0)
9  , m_quadTree(app, uvec2(m_app->getConfig().pickerMaxDistance()*2), m_app->getConfig().pickerMaxDistance())
10  , m_focusDistance(0)
11  , m_highlightEffect(app)
12  , m_mode(m_app->getConfig().pickerMode())
13  , m_modeHasChanged(true)
14 {
16 }
17 
19 {
20  m_mode = mode;
21  switch (m_mode)
22  {
25  break;
27  m_quadTree.resize(uvec2(2*maxDistance()));
28  default:
29  break;
30  }
31 
32  m_modeHasChanged = true;
33 }
34 void Picker::maxDistance(uint const distance)
35 {
37  m_quadTree.resize(uvec2(2*distance));
38 
39  m_quadTree.maxDistance(distance);
40 }
41 
42 void Picker::update(double time, double timeDelta)
43 {
44  auto& wnd = m_app->getWindow();
45  auto& wndSize = wnd.getSize();
46  auto& camera = m_app->getCamera();
47  auto& cursor = uvec2(wnd.getClippedCursor().x, wndSize.y - wnd.getClippedCursor().y);
48  auto& scene = m_app->getSceneGraph();
49 
50  int max = (int)glm::max(wndSize.x, wndSize.y);
51  bool tenthSecondPassed = (int)((time - timeDelta) * 10) != (int)(time * 10);
52 
53  if (wnd.keyDown(GLFW_KEY_PAGE_UP) && tenthSecondPassed)
54  maxDistance(glm::clamp((int)maxDistance() + (int)(5.0), 0, max));
55  else if (wnd.keyDown(GLFW_KEY_PAGE_DOWN) && tenthSecondPassed)
56  maxDistance(glm::clamp((int)maxDistance() - (int)(5.0), 0, max));
57 
58  vec2 queryPoint;
59 
60  switch (m_mode)
61  {
63  {
64  if (scene.hasSceneChanged() || camera.hasViewChanged() || wnd.hasProjChanged() || m_modeHasChanged)
65  {
67  }
68 
69  queryPoint = cursor;
70  break;
71  }
73  default:
74  {
75  m_quadTree.fill(bind(&SceneFBO::readIds, &(m_app->getSceneFBO()), _1, uvec2((uint)cursor.x, (uint)cursor.y), maxDistance()));
76 
77  queryPoint = vec2(float(maxDistance()));
78  break;
79  }
80  }
81 
82  uvec2 pos;
83  if (!(m_hasFocusId = m_quadTree.findNear(queryPoint, OUT m_focusId, OUT pos, OUT m_focusDistance)))
84  {
85  m_focusId = 0;
86  m_focusDistance = (float)maxDistance() + 1.0f;
87  }
88 
89  m_modeHasChanged = false;
90 }
91 
92 void Picker::onWindowSizeChanged(vec2 const & size)
93 {
95 
97  m_quadTree.resize(size);
98 }
99 void Picker::onKeyStateChanged(int key, bool pressed)
100 {
101  if (!pressed) return;
102 
103  if (key == GLFW_KEY_F1)
105 }
106 void Picker::draw(double time, double timeDelta)
107 {
108  m_highlightEffect.draw(time, timeDelta);
109 }
uint maxDistance() const
Definition: Picker.hpp:54
void draw(double time, double timeDelta)
SceneFBO & getSceneFBO()
Definition: Application.hpp:61
void resize(uvec2 const &size)
Definition: QuadTree.cpp:14
float m_focusDistance
Definition: Picker.hpp:27
bool m_hasFocusId
Definition: Picker.hpp:26
PickerUpdateMode updateMode()
Definition: Picker.hpp:74
id_t m_focusId
Definition: Picker.hpp:25
void onKeyStateChanged(int key, bool pressed)
Definition: Picker.cpp:99
void onWindowSizeChanged(vec2 const &size)
Definition: Picker.cpp:92
Camera & getCamera()
Definition: Application.hpp:76
void maxDistance(uint const distance)
Definition: QuadTree.cpp:159
bool m_modeHasChanged
Definition: Picker.hpp:32
PickerUpdateMode
Definition: Picker.hpp:10
Application * m_app
Definition: Picker.hpp:28
SceneGraph & getSceneGraph()
Definition: Application.hpp:56
void update(double time, double timeDelta)
Definition: Picker.cpp:42
Window & getWindow()
Definition: Application.hpp:41
void readAllIds(OUT id_t *target)
Definition: SceneFBO.cpp:140
void resize(vec2 const &size)
PickerUpdateMode m_mode
Definition: Picker.hpp:31
vec2 const & getSize() const
Definition: Window.hpp:45
QuadTree m_quadTree
Definition: Picker.hpp:29
Picker(Application *app)
Definition: Picker.cpp:5
void fill(tFnc readIds)
Definition: QuadTree.hpp:138
void draw(double time, double timeDelta)
Definition: Picker.cpp:106
void readIds(OUT id_t *target, uvec2 const center, uint const distance)
Definition: SceneFBO.cpp:107
HighlightTargetEffect m_highlightEffect
Definition: Picker.hpp:30
bool findNear(uvec2 const &pos, OUT id_t &foundId, OUT uvec2 &foundPos, OUT float &foundDistance)
Definition: QuadTree.cpp:35