15 #ifndef SCENE_LAB_EDITOR_CONTROLLER_H_
16 #define SCENE_LAB_EDITOR_CONTROLLER_H_
18 #include "fplbase/input.h"
19 #include "mathfu/constants.h"
20 #include "mathfu/glsl_mappings.h"
21 #include "scene_lab/entity_system_adapter.h"
22 #include "scene_lab_config_generated.h"
33 static const int kNumButtons = 10;
37 fplbase::InputSystem* input_system)
39 input_system_(input_system),
41 facing_current_(mathfu::kZeros3f),
42 facing_previous_(mathfu::kZeros3f),
43 pointer_current_(mathfu::kZeros2f),
44 pointer_previous_(mathfu::kZeros2f) {
45 for (
int i = 0; i < kNumButtons; i++) {
46 buttons_previous_[i] = buttons_current_[i] =
false;
57 return buttons_current_[button] && !buttons_previous_[button];
62 return buttons_previous_[button] && !buttons_current_[button];
65 bool ButtonIsDown(
int button)
const {
return buttons_current_[button]; }
68 bool ButtonIsUp(
int button)
const {
return !buttons_current_[button]; }
73 return input_system_->GetButton(key).went_down();
78 return input_system_->GetButton(key).went_up();
82 return input_system_->GetButton(key).is_down();
86 bool KeyIsUp(fplbase::FPL_Keycode key)
const {
87 return !input_system_->GetButton(key).is_down();
92 const mathfu::vec3&
GetFacing()
const {
return facing_current_; }
96 facing_current_ = facing_previous_ = facing;
101 const mathfu::vec2&
GetPointer()
const {
return pointer_current_; }
105 return pointer_current_ - pointer_previous_;
111 mouse_locked_ =
true;
112 input_system_->SetRelativeMouseMode(
true);
118 mouse_locked_ =
false;
119 input_system_->SetRelativeMouseMode(
false);
125 const ViewportSettings& viewport,
126 const mathfu::vec2& screen_point,
127 const mathfu::vec2i& screen_size,
128 mathfu::vec3* near, mathfu::vec3* dir)
const;
134 MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
137 const SceneLabConfig* config_;
138 fplbase::InputSystem* input_system_;
142 mathfu::vec3 facing_current_;
143 mathfu::vec3 facing_previous_;
145 mathfu::vec2 pointer_current_;
146 mathfu::vec2 pointer_previous_;
148 bool buttons_current_[kNumButtons];
149 bool buttons_previous_[kNumButtons];
154 #endif // SCENE_LAB_EDITOR_CONTROLLER_H_
bool ButtonWentUp(int button) const
ButtonWentUp() returns true only on the first frame the given button has stopped being pressed...
Definition: editor_controller.h:61
void SetFacing(const mathfu::vec3 &facing)
Set the current facing to a specific value.
Definition: editor_controller.h:95
bool mouse_locked() const
Is the mouse locked? If so, moving the mouse changes our facing.
Definition: editor_controller.h:132
void LockMouse()
Lock the mouse into the middle of the screen, which will start updating facing.
Definition: editor_controller.h:110
bool ButtonIsDown(int button) const
ButtonIsDown() returns true while the given button is being held down.
Definition: editor_controller.h:65
void Update()
Call this every frame to update the *WentDown() functions.
bool ScreenPointToWorldRay(const GenericCamera &camera, const ViewportSettings &viewport, const mathfu::vec2 &screen_point, const mathfu::vec2i &screen_size, mathfu::vec3 *near, mathfu::vec3 *dir) const
Get the position of a screen point in the world, as a ray from the camera position with a direction...
bool ButtonWentDown(int button) const
ButtonWentDown() returns true only on the first frame the given button is being pressed.
Definition: editor_controller.h:56
bool KeyWentUp(fplbase::FPL_Keycode key) const
KeyWentUp() returns true on the first frame after a given key has stopped being pressed.
Definition: editor_controller.h:77
bool KeyIsUp(fplbase::FPL_Keycode key) const
KeyIsUp() returns true while the given key is not being held down.
Definition: editor_controller.h:86
const mathfu::vec2 & GetPointer() const
Get the on-screen pointer position.
Definition: editor_controller.h:101
void UnlockMouse()
Stop locking the mouse to the middle of the screen; it will no longer update facing, but will update pointer location instead.
Definition: editor_controller.h:117
mathfu::vec2 GetPointerDelta() const
Get the delta in on-screen pointer position from the previous update.
Definition: editor_controller.h:104
bool KeyIsDown(fplbase::FPL_Keycode key) const
KeyIsDown() returns true while the given key is being held down.
Definition: editor_controller.h:81
bool KeyWentDown(fplbase::FPL_Keycode key) const
KeyWentDown() returns true on the first frame a given key is being pressed.
Definition: editor_controller.h:72
Definition: editor_controller.h:31
const mathfu::vec3 & GetFacing() const
Get the direction we are facing.
Definition: editor_controller.h:92
bool ButtonIsUp(int button) const
ButtonIsUp() returns true while the given button is not being held down.
Definition: editor_controller.h:68
EditorController(const SceneLabConfig *config, fplbase::InputSystem *input_system)
Initialize the controller.
Definition: editor_controller.h:36