DebugMoveScript.h 2.2 KB

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