DebugRotateScript.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "BaseScriptObject.h"
  3. // Provides bare object rotation functionality for debugging purposes (like making a spotlight rotate)
  4. class DebugRotateScript : public BaseScriptObject
  5. {
  6. friend class ScriptingScene;
  7. public:
  8. DebugRotateScript(SystemScene *p_systemScene, std::string p_name)
  9. : BaseScriptObject(p_systemScene, p_name, Properties::DebugRotateScript)
  10. {
  11. m_speed = 10.0f;
  12. m_axis = Math::normalize(Math::Vec3f(1.0f, 0.0f, 1.0f));
  13. m_rotation = Math::normalize(Math::Vec3f(1.0f, 0.0f, 1.0f));
  14. }
  15. ~DebugRotateScript() { }
  16. virtual ErrorCode init()
  17. {
  18. return ErrorCode::Success;
  19. }
  20. void loadToMemory()
  21. {
  22. }
  23. // Exports all the data of the object as a PropertySet
  24. virtual PropertySet exportObject()
  25. {
  26. // Create the root property set
  27. PropertySet propertySet(Properties::ArrayEntry);
  28. // Add variables
  29. propertySet.addProperty(Properties::Type, Properties::DebugRotateScript);
  30. propertySet.addProperty(Properties::Name, m_name);
  31. propertySet.addProperty(Properties::Axis, m_axis);
  32. propertySet.addProperty(Properties::LocalRotationQuaternion, m_rotation);
  33. propertySet.addProperty(Properties::Speed, m_speed);
  34. return propertySet;
  35. }
  36. virtual void update(const float p_deltaTime)
  37. {
  38. m_rotation.rotate(m_speed * p_deltaTime, m_axis);
  39. m_rotation.normalize();
  40. //postChanges(Systems::Changes::Spatial::Rotation);
  41. }
  42. const virtual Math::Vec3f &getVec3(const Observer *p_observer, BitMask p_changedBits) const
  43. {
  44. /*switch (p_changedBits)
  45. {
  46. case Systems::Changes::Spatial::Rotation:
  47. return m_rotation;
  48. break;
  49. }*/
  50. return ObservedSubject::getVec3(p_observer, p_changedBits);
  51. }
  52. // Setters
  53. inline void setMovementSpeed(float p_speed) { m_speed = p_speed; }
  54. inline void setRotation(Math::Vec3f p_rotation) { m_rotation = p_rotation; }
  55. inline void setRotationAxis(Math::Vec3f p_axis) { m_axis = p_axis; }
  56. protected:
  57. float m_speed;
  58. Math::Mat4f m_modelMatrix;
  59. Math::Vec3f m_rotation,
  60. m_axis;
  61. };