Rotator.cpp 866 B

12345678910111213141516171819202122232425262728
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include <Urho3D/Scene/Scene.h>
  4. #include "Rotator.h"
  5. #include <Urho3D/DebugNew.h>
  6. Rotator::Rotator(Context* context) :
  7. LogicComponent(context),
  8. rotationSpeed_(Vector3::ZERO)
  9. {
  10. // Only the scene update event is needed: unsubscribe from the rest for optimization
  11. SetUpdateEventMask(LogicComponentEvents::Update);
  12. }
  13. void Rotator::SetRotationSpeed(const Vector3& speed)
  14. {
  15. rotationSpeed_ = speed;
  16. }
  17. void Rotator::Update(float timeStep)
  18. {
  19. // Components have their scene node as a member variable for convenient access. Rotate the scene node now: construct a
  20. // rotation quaternion from Euler angles, scale rotation speed with the scene update time step
  21. node_->Rotate(Quaternion(rotationSpeed_.x_ * timeStep, rotationSpeed_.y_ * timeStep, rotationSpeed_.z_ * timeStep));
  22. }