SmoothedTransform.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Scene/Component.h"
  24. namespace Atomic
  25. {
  26. /// No ongoing smoothing.
  27. static const unsigned SMOOTH_NONE = 0;
  28. /// Ongoing position smoothing.
  29. static const unsigned SMOOTH_POSITION = 1;
  30. /// Ongoing rotation smoothing.
  31. static const unsigned SMOOTH_ROTATION = 2;
  32. /// Transform smoothing component for network updates.
  33. class ATOMIC_API SmoothedTransform : public Component
  34. {
  35. ATOMIC_OBJECT(SmoothedTransform, Component);
  36. public:
  37. /// Construct.
  38. SmoothedTransform(Context* context);
  39. /// Destruct.
  40. ~SmoothedTransform();
  41. /// Register object factory.
  42. static void RegisterObject(Context* context);
  43. /// Update smoothing.
  44. void Update(float constant, float squaredSnapThreshold);
  45. /// Set target position in parent space.
  46. void SetTargetPosition(const Vector3& position);
  47. /// Set target rotation in parent space.
  48. void SetTargetRotation(const Quaternion& rotation);
  49. /// Set target position in world space.
  50. void SetTargetWorldPosition(const Vector3& position);
  51. /// Set target rotation in world space.
  52. void SetTargetWorldRotation(const Quaternion& rotation);
  53. /// Return target position in parent space.
  54. const Vector3& GetTargetPosition() const { return targetPosition_; }
  55. /// Return target rotation in parent space.
  56. const Quaternion& GetTargetRotation() const { return targetRotation_; }
  57. /// Return target position in world space.
  58. Vector3 GetTargetWorldPosition() const;
  59. /// Return target rotation in world space.
  60. Quaternion GetTargetWorldRotation() const;
  61. /// Return whether smoothing is in progress.
  62. bool IsInProgress() const { return smoothingMask_ != 0; }
  63. protected:
  64. /// Handle scene node being assigned at creation.
  65. virtual void OnNodeSet(Node* node);
  66. private:
  67. /// Handle smoothing update event.
  68. void HandleUpdateSmoothing(StringHash eventType, VariantMap& eventData);
  69. /// Target position.
  70. Vector3 targetPosition_;
  71. /// Target rotation.
  72. Quaternion targetRotation_;
  73. /// Active smoothing operations bitmask.
  74. unsigned char smoothingMask_;
  75. /// Subscribed to smoothing update event flag.
  76. bool subscribed_;
  77. };
  78. }