| 157 | } |
| 158 | |
| 159 | void FreeCamera::input_event(const InputEvent &input_event) |
| 160 | { |
| 161 | if (input_event.get_source() == EventSource::Keyboard) |
| 162 | { |
| 163 | const auto &key_event = static_cast<const KeyInputEvent &>(input_event); |
| 164 | |
| 165 | if (key_event.get_action() == KeyAction::Down || |
| 166 | key_event.get_action() == KeyAction::Repeat) |
| 167 | { |
| 168 | key_pressed[key_event.get_code()] = true; |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | key_pressed[key_event.get_code()] = false; |
| 173 | } |
| 174 | } |
| 175 | else if (input_event.get_source() == EventSource::Mouse) |
| 176 | { |
| 177 | const auto &mouse_button = static_cast<const MouseButtonInputEvent &>(input_event); |
| 178 | |
| 179 | glm::vec2 mouse_pos{std::floor(mouse_button.get_pos_x()), std::floor(mouse_button.get_pos_y())}; |
| 180 | |
| 181 | if (mouse_button.get_action() == MouseAction::Down) |
| 182 | { |
| 183 | mouse_button_pressed[mouse_button.get_button()] = true; |
| 184 | } |
| 185 | |
| 186 | if (mouse_button.get_action() == MouseAction::Up) |
| 187 | { |
| 188 | mouse_button_pressed[mouse_button.get_button()] = false; |
| 189 | } |
| 190 | |
| 191 | if (mouse_button.get_action() == MouseAction::Move) |
| 192 | { |
| 193 | mouse_move_delta = mouse_pos - mouse_last_pos; |
| 194 | |
| 195 | mouse_last_pos = mouse_pos; |
| 196 | } |
| 197 | } |
| 198 | else if (input_event.get_source() == EventSource::Touchscreen) |
| 199 | { |
| 200 | const auto &touch_event = static_cast<const TouchInputEvent &>(input_event); |
| 201 | |
| 202 | glm::vec2 touch_pos{std::floor(touch_event.get_pos_x()), std::floor(touch_event.get_pos_y())}; |
| 203 | |
| 204 | if (touch_event.get_action() == TouchAction::Down) |
| 205 | { |
| 206 | touch_pointer_pressed[touch_event.get_pointer_id()] = true; |
| 207 | |
| 208 | touch_last_pos = touch_pos; |
| 209 | } |
| 210 | |
| 211 | if (touch_event.get_action() == TouchAction::Up) |
| 212 | { |
| 213 | touch_pointer_pressed[touch_event.get_pointer_id()] = false; |
| 214 | |
| 215 | touch_pointer_time = 0.0f; |
| 216 | } |
nothing calls this directly
no test coverage detected