SmoothedTransform.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. /// \file
  4. #pragma once
  5. #include "../Scene/Component.h"
  6. namespace Urho3D
  7. {
  8. enum SmoothingType : unsigned
  9. {
  10. /// No ongoing smoothing.
  11. SMOOTH_NONE = 0,
  12. /// Ongoing position smoothing.
  13. SMOOTH_POSITION = 1,
  14. /// Ongoing rotation smoothing.
  15. SMOOTH_ROTATION = 2,
  16. };
  17. URHO3D_FLAGSET(SmoothingType, SmoothingTypeFlags);
  18. /// Transform smoothing component for network updates.
  19. class URHO3D_API SmoothedTransform : public Component
  20. {
  21. URHO3D_OBJECT(SmoothedTransform, Component);
  22. public:
  23. /// Construct.
  24. explicit SmoothedTransform(Context* context);
  25. /// Destruct.
  26. ~SmoothedTransform() override;
  27. /// Register object factory.
  28. /// @nobind
  29. static void RegisterObject(Context* context);
  30. /// Update smoothing.
  31. void Update(float constant, float squaredSnapThreshold);
  32. /// Set target position in parent space.
  33. /// @property
  34. void SetTargetPosition(const Vector3& position);
  35. /// Set target rotation in parent space.
  36. /// @property
  37. void SetTargetRotation(const Quaternion& rotation);
  38. /// Set target position in world space.
  39. /// @property
  40. void SetTargetWorldPosition(const Vector3& position);
  41. /// Set target rotation in world space.
  42. /// @property
  43. void SetTargetWorldRotation(const Quaternion& rotation);
  44. /// Return target position in parent space.
  45. /// @property
  46. const Vector3& GetTargetPosition() const { return targetPosition_; }
  47. /// Return target rotation in parent space.
  48. /// @property
  49. const Quaternion& GetTargetRotation() const { return targetRotation_; }
  50. /// Return target position in world space.
  51. /// @property
  52. Vector3 GetTargetWorldPosition() const;
  53. /// Return target rotation in world space.
  54. /// @property
  55. Quaternion GetTargetWorldRotation() const;
  56. /// Return whether smoothing is in progress.
  57. /// @property
  58. bool IsInProgress() const { return smoothingMask_ != SMOOTH_NONE; }
  59. protected:
  60. /// Handle scene node being assigned at creation.
  61. void OnNodeSet(Node* node) override;
  62. private:
  63. /// Handle smoothing update event.
  64. void HandleUpdateSmoothing(StringHash eventType, VariantMap& eventData);
  65. /// Target position.
  66. Vector3 targetPosition_;
  67. /// Target rotation.
  68. Quaternion targetRotation_;
  69. /// Active smoothing operations bitmask.
  70. SmoothingTypeFlags smoothingMask_;
  71. /// Subscribed to smoothing update event flag.
  72. bool subscribed_;
  73. };
  74. }