NAP
rotatecomponent.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 // Local includes
8 #include "component.h"
9 
10 // External includes
11 #include <utility/dllexport.h>
12 
13 // Local includes
14 #include "transformcomponent.h"
15 
16 #include <glm/glm.hpp>
17 
18 namespace nap
19 {
23  struct NAPAPI RotateProperties
24  {
25  glm::vec3 mAxis = {0.0f, 1.0f, 0.0f};
26  float mSpeed = 1.0f;
27  float mOffset = 0.0f;
28  };
29 
31 
33 
41  class NAPAPI RotateComponent : public Component
42  {
43  RTTI_ENABLE(Component)
44  DECLARE_COMPONENT(RotateComponent, RotateComponentInstance)
45  public:
49  void getDependentComponents(std::vector<rtti::TypeInfo>& components) const override
50  {
51  components.push_back(RTTI_OF(TransformComponent));
52  }
53 
54  public:
56  bool mEnabled = true;
57  };
58 
60 
69  {
70  RTTI_ENABLE(ComponentInstance)
71  public:
72  RotateComponentInstance(EntityInstance& entity, Component& resource) : ComponentInstance(entity, resource) { }
73 
79  virtual bool init(utility::ErrorState& errorState) override;
80 
85  virtual void update(double deltaTime) override;
86 
90  void reset();
91 
95  void enable(bool enable) { mEnabled = enable; }
96 
100  bool isEnabled() const { return mEnabled; }
101 
102  /*
103  * Sets the rotation speed
104  * @param speed rotation speed in seconds
105  */
106  void setSpeed(float speed) { mProperties.mSpeed = speed; }
107 
111  float getSpeed() const { return mProperties.mSpeed; }
112 
117  void setAxis(const glm::vec3& axis) { mProperties.mAxis = axis; }
118 
122  glm::vec3 getAxis() const { return mProperties.mAxis; }
123 
124  // Rotation properties
126 
127  private:
128  // Store pointer to transform, set during init
129  nap::TransformComponentInstance* mTransform = nullptr;
130 
131  // Local elapsed time
132  double mElapsedTime = 0.0;
133 
134  // Enable flag
135  bool mEnabled = true;
136 
137  // Initial Rotation value
138  glm::quat mInitialRotate = glm::quat();
139  };
140 }
nap::RotateComponentInstance::setAxis
void setAxis(const glm::vec3 &axis)
Definition: rotatecomponent.h:117
nap::RotateComponentInstance::setSpeed
void setSpeed(float speed)
Definition: rotatecomponent.h:106
nap::RotateComponentInstance::getSpeed
float getSpeed() const
Definition: rotatecomponent.h:111
nap::RotateComponentInstance::getAxis
glm::vec3 getAxis() const
Definition: rotatecomponent.h:122
nap::RotateComponentInstance::enable
void enable(bool enable)
Definition: rotatecomponent.h:95
nap::RotateComponentInstance::RotateComponentInstance
RotateComponentInstance(EntityInstance &entity, Component &resource)
Definition: rotatecomponent.h:72
nap::utility::ErrorState
Definition: errorstate.h:19
nap::RotateComponentInstance
Definition: rotatecomponent.h:68
nap::RotateComponentInstance::mProperties
RotateProperties mProperties
Definition: rotatecomponent.h:125
nap::RotateComponent::mProperties
RotateProperties mProperties
Property: 'Properties' Rotation settings.
Definition: rotatecomponent.h:55
nap::EntityInstance
Definition: entity.h:34
nap::ComponentInstance
Definition: component.h:43
nap::Component
Definition: component.h:151
nap::TransformComponent
Definition: transformcomponent.h:57
nap::RotateComponentInstance::isEnabled
bool isEnabled() const
Definition: rotatecomponent.h:100
nap::RotateComponent::getDependentComponents
void getDependentComponents(std::vector< rtti::TypeInfo > &components) const override
Definition: rotatecomponent.h:49
nap::RotateComponent
Definition: rotatecomponent.h:41
nap
Definition: templateapp.h:17
nap::RotateProperties
Definition: rotatecomponent.h:23
nap::TransformComponentInstance
Definition: transformcomponent.h:73