NAP
cameracontroller.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 #include <component.h>
8 #include <entityptr.h>
9 #include "orbitcontroller.h"
10 #include "firstpersoncontroller.h"
11 #include "orthocontroller.h"
12 
13 namespace nap
14 {
15  class CameraControllerInstance;
16  class KeyReleaseEvent;
17 
21  enum class ECameraMode : uint8_t
22  {
23  None = 0x00,
24  FirstPerson = 0x01, // Perspective free camera
25  Orbit = 0x02, // Perspective orbit camera
26  OrthographicTop = 0x04, // Orthographic camera (top-view)
27  OrthographicBottom = 0x08, // Orthographic camera (bottom-view)
28  OrthographicLeft = 0x10, // Orthographic camera (left-view)
29  OrthographicRight = 0x20, // Orthographic camera (right-view)
30  OrthographicFront = 0x40, // Orthographic camera (front-view)
31  OrthographicBack = 0x80, // Orthographic camera (back-view)
34  };
35 
36  inline ECameraMode operator&(ECameraMode a, ECameraMode b) { return static_cast<ECameraMode>(static_cast<uint8_t>(a) & static_cast<uint8_t>(b)); }
37  inline ECameraMode operator|(ECameraMode a, ECameraMode b) { return static_cast<ECameraMode>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b)); }
38 
39 
46  class NAPAPI CameraController : public Component
47  {
48  RTTI_ENABLE(Component)
49  DECLARE_COMPONENT(CameraController, CameraControllerInstance)
50  public:
55  virtual void getDependentComponents(std::vector<rtti::TypeInfo>& components) const override;
56 
58  };
59 
60 
68  {
69  RTTI_ENABLE(ComponentInstance)
70  public:
72 
76  virtual bool init(utility::ErrorState& errorState) override;
77 
82  CameraComponentInstance& getCameraComponent();
83 
84  private:
85  void onKeyRelease(const KeyReleaseEvent& keyReleaseEvent);
86  void onKeyPress(const KeyPressEvent& keyReleaseEvent);
87  void storeLastPerspTransform();
88  void switchMode(ECameraMode targetMode);
89 
90  private:
91  EntityInstancePtr mLookAtTarget = { this, &CameraController::mLookAtTarget };
93  OrbitControllerInstance* mOrbitComponent = nullptr;
94  FirstPersonControllerInstance* mFirstPersonComponent = nullptr;
95  OrthoControllerInstance* mOrthoComponent = nullptr;
96  glm::vec3 mLastPerspPos;
97  glm::quat mLastPerspRotate;
98  };
99 
100 }
nap::EntityInstancePtr
Definition: entityptr.h:107
nap::ECameraMode::OrthographicFront
@ OrthographicFront
nap::ECameraMode::None
@ None
nap::EntityPtr
Definition: entityptr.h:15
nap::CameraController::mLookAtTarget
nap::EntityPtr mLookAtTarget
Property: 'LookAtTarget' Object to look at, used by the orbit and ortho controller.
Definition: cameracontroller.h:57
nap::ECameraMode::OrthographicBack
@ OrthographicBack
nap::ECameraMode::Perspective
@ Perspective
nap::CameraControllerInstance
Definition: cameracontroller.h:67
nap::CameraComponentInstance
Definition: cameracomponent.h:38
nap::CameraController
Definition: cameracontroller.h:46
nap::KeyPressEvent
Definition: inputevent.h:70
nap::utility::ErrorState
Definition: errorstate.h:19
nap::operator&
ECameraMode operator&(ECameraMode a, ECameraMode b)
Definition: cameracontroller.h:36
nap::ECameraMode::OrthographicTop
@ OrthographicTop
nap::KeyReleaseEvent
Definition: inputevent.h:83
nap::ECameraMode::OrthographicLeft
@ OrthographicLeft
nap::operator|
ECameraMode operator|(ECameraMode a, ECameraMode b)
Definition: cameracontroller.h:37
nap::ECameraMode
ECameraMode
Definition: cameracontroller.h:21
nap::FirstPersonControllerInstance
Definition: firstpersoncontroller.h:54
nap::OrbitControllerInstance
Definition: orbitcontroller.h:57
nap::ECameraMode::Orbit
@ Orbit
nap::EntityInstance
Definition: entity.h:34
nap::ECameraMode::FirstPerson
@ FirstPerson
nap::ECameraMode::OrthographicBottom
@ OrthographicBottom
nap::ComponentInstance
Definition: component.h:43
nap::Component
Definition: component.h:151
nap::OrthoControllerInstance
Definition: orthocontroller.h:53
nap::ECameraMode::Orthographic
@ Orthographic
nap
Definition: templateapp.h:17
nap::ECameraMode::OrthographicRight
@ OrthographicRight