llflexibleobject.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * @file llflexibleobject.h
  3. * @author JJ Ventrella, Andrew Meadows, Tom Yedwab
  4. * @brief Flexible object definition
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewergpl$
  7. *
  8. * Copyright (c) 2006-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. // This is for specifying objects in the world that are animated and rendered
  34. // viewer-side. Flexible Objects are linear arrays of positions, which stay at
  35. // a fixed distance from each other. One position is fixed as an "anchor" and
  36. // is attached to some other object in the world, determined by the server. All
  37. // the other positions are updated according to local physics.
  38. #ifndef LL_LLFLEXIBLEOBJECT_H
  39. #define LL_LLFLEXIBLEOBJECT_H
  40. #include "llvovolume.h"
  41. // 10 ms for the whole thing !
  42. constexpr F32 FLEXIBLE_OBJECT_TIMESLICE = 0.003f;
  43. constexpr U32 FLEXIBLE_OBJECT_MAX_LOD = 10;
  44. // See llprimitive.h for LLFlexibleObjectData and DEFAULT/MIN/MAX values
  45. struct LLFlexibleObjectSection
  46. {
  47. // Input parameters
  48. LLVector2 mScale;
  49. LLQuaternion mAxisRotation;
  50. // Simulated state
  51. LLVector3 mPosition;
  52. LLVector3 mVelocity;
  53. LLVector3 mDirection;
  54. LLQuaternion mRotation;
  55. // Derivatives (Not all currently used, will come back with LLVolume
  56. // changes to automagically generate normals)
  57. LLVector3 mdPosition;
  58. //LLMatrix4 mRotScale;
  59. //LLMatrix4 mdRotScale;
  60. };
  61. class LLVolumeImplFlexible final : public LLVolumeInterface
  62. {
  63. protected:
  64. LOG_CLASS(LLVolumeImplFlexible);
  65. public:
  66. static void initClass();
  67. static void updateClass();
  68. static void dumpStats();
  69. LLVolumeImplFlexible(LLViewerObject* volumep,
  70. LLFlexibleObjectData* attributesp);
  71. ~LLVolumeImplFlexible() override;
  72. // LLVolumeInterface overrides
  73. LL_INLINE LLVolumeInterfaceType getInterfaceType() const override
  74. {
  75. return INTERFACE_FLEXIBLE;
  76. }
  77. void doIdleUpdate() override;
  78. bool doUpdateGeometry(LLDrawable* drawablep) override;
  79. LLVector3 getPivotPosition() const override;
  80. LL_INLINE void onSetVolume(const LLVolumeParams&, S32) override
  81. {
  82. }
  83. void onSetScale(const LLVector3& scale, bool damped) override;
  84. void onParameterChanged(U16 param_type, LLNetworkData* datap, bool in_use,
  85. bool local_origin) override;
  86. void onShift(const LLVector4a& shift_vector) override;
  87. LL_INLINE bool isVolumeUnique() const override { return true; }
  88. LL_INLINE bool isVolumeGlobal() const override { return true; }
  89. LL_INLINE bool isActive() const override { return true; }
  90. const LLMatrix4& getWorldMatrix(LLXformMatrix* xformp) const override;
  91. void updateRelativeXform(bool force_identity = false) override;
  92. LL_INLINE U32 getID() const override { return mID; }
  93. void preRebuild() override;
  94. LLVector3 getFramePosition() const;
  95. LLQuaternion getFrameRotation() const;
  96. // New methods
  97. void updateRenderRes();
  98. void doFlexibleUpdate(); // Called to update the simulation
  99. // Called to rebuild the geometry:
  100. void doFlexibleRebuild(bool rebuild_volume);
  101. void setParentPositionAndRotationDirectly(LLVector3 p, LLQuaternion r);
  102. LL_INLINE void setCollisionSphere(LLVector3 position, F32 radius)
  103. {
  104. mCollisionSpherePosition = position;
  105. mCollisionSphereRadius = radius;
  106. }
  107. LLVector3 getEndPosition();
  108. LLQuaternion getEndRotation();
  109. LLVector3 getNodePosition(S32 node_idx);
  110. LLVector3 getAnchorPosition() const;
  111. private:
  112. void setAttributesOfAllSections (LLVector3* in_scalep = NULL);
  113. void remapSections(LLFlexibleObjectSection* srcp, S32 source_sections,
  114. LLFlexibleObjectSection* dstp, S32 dest_sections);
  115. private:
  116. // Backlink only; do not make this an LLPointer.
  117. LLViewerObject* mVO;
  118. LLTimer mTimer;
  119. LLVector3 mAnchorPosition;
  120. LLVector3 mParentPosition;
  121. LLQuaternion mParentRotation;
  122. LLQuaternion mLastFrameRotation;
  123. LLQuaternion mLastSegmentRotation;
  124. LLFlexibleObjectData* mAttributes;
  125. LLFlexibleObjectSection mSection[(1 << FLEXIBLE_OBJECT_MAX_SECTIONS) + 1];
  126. S32 mInitializedRes;
  127. S32 mSimulateRes;
  128. S32 mRenderRes;
  129. U64 mLastFrameNum;
  130. U32 mLastUpdatePeriod;
  131. LLVector3 mCollisionSpherePosition;
  132. F32 mCollisionSphereRadius;
  133. U32 mID;
  134. bool mInitialized;
  135. bool mUpdated;
  136. S32 mInstanceIndex;
  137. typedef std::vector<LLVolumeImplFlexible*> instances_list_t;
  138. static instances_list_t sInstanceList;
  139. public:
  140. // Global setting for update rate
  141. static F32 sUpdateFactor;
  142. };
  143. #endif // LL_LLFLEXIBLEOBJECT_H