NAP
orthocontroller.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External Includes
8 #include <component.h>
9 #include <componentptr.h>
10 #include <inputcomponent.h>
11 #include <orthocameracomponent.h>
12 #include <glm/glm.hpp>
13 
14 namespace nap
15 {
16  class OrthoControllerInstance;
17  class PointerPressEvent;
18  class PointerMoveEvent;
19  class PointerReleaseEvent;
20  class TransformComponentInstance;
21  class TransformComponent;
22 
30  class NAPAPI OrthoController : public Component
31  {
32  RTTI_ENABLE(Component)
33  DECLARE_COMPONENT(OrthoController, OrthoControllerInstance)
34  public:
38  virtual void getDependentComponents(std::vector<rtti::TypeInfo>& components) const override;
39 
40  float mMovementSpeed = 1.0f;
41  float mZoomSpeed = 0.005f;
43  };
44 
45 
54  {
55  RTTI_ENABLE(ComponentInstance)
56  public:
58 
62  virtual bool init(utility::ErrorState& errorState) override;
63 
69  void enable(const glm::vec3& cameraPos, const glm::quat& cameraRotate);
70 
74  void disable() { mEnabled = false; }
75 
79  CameraComponentInstance& getCameraComponent();
80 
81  private:
82 
86  void onMouseDown(const PointerPressEvent& pointerPressEvent);
87 
91  void onMouseUp(const PointerReleaseEvent& pointerReleaseEvent);
92 
96  void onMouseMove(const PointerMoveEvent& pointerMoveEvent);
97 
101  void updateCameraProperties();
102 
103  private:
104  enum EMode
105  {
106  None,
107  Pan, // Currently panning
108  Zoom // Currently zooming
109  };
110 
111  ComponentInstancePtr<OrthoCameraComponent> mOrthoCameraComponent = { this, &OrthoController::mOrthoCameraComponent };
112 
113  TransformComponentInstance* mTransformComponent = nullptr; // The transform component used to move the entity
114  bool mEnabled = true; // Set if enabled for input
115  float mCameraScale = 1.0f; // Current scale, selects the width of the space you can see
116  float mCameraScaleAtClick = 0.0f; // Scale that was set when clicking with the mouse button
117  EMode mMode = EMode::None; // Pan/Zoom mode
118  glm::vec2 mMousePosAtClick; // Mouse position that was set when clicking with the mouse button
119  glm::vec2 mMousePosNow; // Mouse position
120  glm::vec3 mTranslateAtClick; // Camera translation that was set when clicking with the mouse button
121  };
122 
123 }
nap::ECameraMode::None
@ None
nap::OrthoController
Definition: orthocontroller.h:30
nap::CameraComponentInstance
Definition: cameracomponent.h:38
nap::utility::ErrorState
Definition: errorstate.h:19
nap::PointerReleaseEvent
Definition: inputevent.h:189
nap::EntityInstance
Definition: entity.h:34
nap::ComponentInstance
Definition: component.h:43
nap::Component
Definition: component.h:151
nap::OrthoControllerInstance
Definition: orthocontroller.h:53
nap::PointerMoveEvent
Definition: inputevent.h:202
nap
Definition: templateapp.h:17
nap::ComponentPtr
Definition: component.h:31
nap::PointerPressEvent
Definition: inputevent.h:176
nap::OrthoController::mOrthoCameraComponent
ComponentPtr< OrthoCameraComponent > mOrthoCameraComponent
Property: "OrthoCameraComponent" Camera that we're controlling.
Definition: orthocontroller.h:42
nap::OrthoControllerInstance::disable
void disable()
Definition: orthocontroller.h:74