llviewerjointattachment.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @file llviewerjointattachment.h
  3. * @brief Implementation of LLViewerJointAttachment class
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, 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_LLVIEWERJOINTATTACHMENT_H
  33. #define LL_LLVIEWERJOINTATTACHMENT_H
  34. #include "llstring.h"
  35. #include "lluuid.h"
  36. #include "llviewerjoint.h"
  37. #include "llviewerobject.h"
  38. class LLDrawable;
  39. class LLViewerJointAttachment final : public LLViewerJoint
  40. {
  41. friend class LLVOAvatar;
  42. protected:
  43. LOG_CLASS(LLViewerJointAttachment);
  44. public:
  45. LLViewerJointAttachment();
  46. // Returns true if this object is transparent.
  47. // This is used to determine in which order to draw objects.
  48. LL_INLINE bool isTransparent() override { return false; }
  49. // Draws the shape attached to a joint.
  50. // Called by render().
  51. U32 drawShape(bool first_pass = true, bool is_dummy = false) override;
  52. bool updateLOD(F32 pixel_area, bool activate) override;
  53. LL_INLINE void setPieSlice(S32 pie_slice) { mPieSlice = pie_slice; }
  54. LL_INLINE void setVisibleInFirstPerson(bool b) { mVisibleInFirst = b; }
  55. LL_INLINE bool getVisibleInFirstPerson() const { return mVisibleInFirst; }
  56. LL_INLINE void setGroup(S32 group) { mGroup = group; }
  57. void setOriginalPosition(LLVector3 &position);
  58. void setAttachmentVisibility(bool visible);
  59. LL_INLINE void setIsHUDAttachment(bool is_hud) { mIsHUDAttachment = is_hud; }
  60. LL_INLINE bool getIsHUDAttachment() const { return mIsHUDAttachment; }
  61. LL_INLINE bool isAnimatable() const override { return false; }
  62. LL_INLINE S32 getGroup() const { return mGroup; }
  63. LL_INLINE S32 getPieSlice() const { return mPieSlice; }
  64. LL_INLINE S32 getNumObjects() const { return mAttachedObjects.size(); }
  65. S32 getNumAnimatedObjects() const;
  66. void clampObjectPosition();
  67. // Attachments operations
  68. bool isObjectAttached(const LLViewerObject* viewer_object) const;
  69. const LLViewerObject* getAttachedObject(const LLUUID& object_id) const;
  70. LLViewerObject* getAttachedObject(const LLUUID& object_id);
  71. LL_INLINE bool hasChanged(const LLVector3& pos,
  72. const LLQuaternion& rot) const
  73. {
  74. constexpr F32 SMALL_CHANGE_DIST2 = 0.05f * 0.05f;
  75. constexpr F32 SMALL_CHANGE_ANGL = 0.225f; // Just shy of 13 degrees
  76. // Angle choice and LLQuaternion::almost_equal: almost_equal uses the
  77. // Small Angle Approximation for cos. The approximation diverges more
  78. // than 1% at around 0.6620 radians. We are under this limit and to be
  79. // honest, an error of 1% in this case is acceptable.
  80. return (pos - mLastTrackedPos).lengthSquared() > SMALL_CHANGE_DIST2 ||
  81. !LLQuaternion::almost_equal(rot, mLastTrackedRot,
  82. SMALL_CHANGE_ANGL);
  83. }
  84. LL_INLINE void setLastTracked(const LLVector3& pos,
  85. const LLQuaternion& rot)
  86. {
  87. mLastTrackedPos = pos;
  88. mLastTrackedRot = rot;
  89. }
  90. protected:
  91. // Unique methods, used exclusively by LLVOAvatar
  92. bool addObject(LLViewerObject* object, bool is_self);
  93. void removeObject(LLViewerObject* object, bool is_self);
  94. void calcLOD();
  95. void setupDrawable(LLViewerObject* object);
  96. public:
  97. // List of attachments for this joint
  98. typedef std::vector<LLPointer<LLViewerObject> > attachedobjs_vec_t;
  99. attachedobjs_vec_t mAttachedObjects;
  100. protected:
  101. LLVector3 mOriginalPos;
  102. LLVector3 mLastTrackedPos;
  103. LLQuaternion mLastTrackedRot;
  104. S32 mGroup;
  105. S32 mPieSlice;
  106. bool mIsHUDAttachment;
  107. bool mVisibleInFirst;
  108. };
  109. #endif // LL_LLVIEWERJOINTATTACHMENT_H