llphysicsmotion.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @file llphysicsmotion.h
  3. * @brief Implementation of LLPhysicsMotion class.
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. *
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLPHYSICSMOTIONCONTROLLER_H
  33. #define LL_LLPHYSICSMOTIONCONTROLLER_H
  34. //-----------------------------------------------------------------------------
  35. // Header files
  36. //-----------------------------------------------------------------------------
  37. #include "llmotion.h"
  38. #include "llframetimer.h"
  39. #define PHYSICS_MOTION_FADEIN_TIME 1.0f
  40. #define PHYSICS_MOTION_FADEOUT_TIME 1.0f
  41. class LLPhysicsMotion;
  42. //-----------------------------------------------------------------------------
  43. // class LLPhysicsMotion
  44. //-----------------------------------------------------------------------------
  45. class LLPhysicsMotionController : public LLMotion
  46. {
  47. protected:
  48. LOG_CLASS(LLPhysicsMotionController);
  49. public:
  50. // Constructor
  51. LLPhysicsMotionController(const LLUUID& id);
  52. // Destructor
  53. virtual ~LLPhysicsMotionController();
  54. public:
  55. //-------------------------------------------------------------------------
  56. // functions to support MotionController and MotionRegistry
  57. //-------------------------------------------------------------------------
  58. // static constructor
  59. // all subclasses must implement such a function and register it
  60. static LLMotion* create(const LLUUID& id) { return new LLPhysicsMotionController(id); }
  61. public:
  62. //-------------------------------------------------------------------------
  63. // animation callbacks to be implemented by subclasses
  64. //-------------------------------------------------------------------------
  65. // motions must specify whether or not they loop
  66. LL_INLINE virtual bool getLoop() { return true; }
  67. // motions must report their total duration
  68. LL_INLINE virtual F32 getDuration() { return 0.f; }
  69. // motions must report their "ease in" duration
  70. LL_INLINE virtual F32 getEaseInDuration() { return PHYSICS_MOTION_FADEIN_TIME; }
  71. // motions must report their "ease out" duration.
  72. LL_INLINE virtual F32 getEaseOutDuration() { return PHYSICS_MOTION_FADEOUT_TIME; }
  73. // called to determine when a motion should be activated/deactivated based
  74. // on avatar pixel coverage
  75. LL_INLINE virtual F32 getMinPixelArea();
  76. // motions must report their priority
  77. LL_INLINE virtual LLJoint::JointPriority getPriority() { return LLJoint::MEDIUM_PRIORITY; }
  78. LL_INLINE virtual LLMotionBlendType getBlendType() { return ADDITIVE_BLEND; }
  79. // run-time (post constructor) initialization, called after parameters have
  80. // been set must return true to indicate success and be available for
  81. // activation
  82. virtual LLMotionInitStatus onInitialize(LLCharacter *character);
  83. // called when a motion is activated. must return true to indicate success,
  84. // or else it will be deactivated.
  85. LL_INLINE virtual bool onActivate() { return true; }
  86. // called per time step
  87. // must return true while it is active, and
  88. // must return false when the motion is completed.
  89. virtual bool onUpdate(F32 time, U8* joint_mask);
  90. // called when a motion is deactivated
  91. LL_INLINE virtual void onDeactivate() {}
  92. LL_INLINE LLCharacter* getCharacter() { return mCharacter; }
  93. protected:
  94. void addMotion(LLPhysicsMotion* motion);
  95. private:
  96. LLCharacter* mCharacter;
  97. typedef std::vector<LLPhysicsMotion*> motion_vec_t;
  98. motion_vec_t mMotions;
  99. };
  100. #endif // LL_LLPHYSICSMOTION_H