llmanipscale.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /**
  2. * @file llmanipscale.h
  3. * @brief LLManipScale class definition
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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_MANIPSCALE_H
  33. #define LL_MANIPSCALE_H
  34. #include "llbbox.h"
  35. #include "llvector3.h"
  36. #include "llvector4.h"
  37. #include "llmanip.h"
  38. #include "lltool.h"
  39. #include "llviewerobject.h"
  40. class LLToolComposite;
  41. class LLColor4;
  42. typedef enum e_scale_manipulator_type
  43. {
  44. SCALE_MANIP_CORNER,
  45. SCALE_MANIP_FACE
  46. } EScaleManipulatorType;
  47. // Treatead as a bitmask.
  48. typedef enum e_snap_regimes
  49. {
  50. // The cursor is not in either of the snap regimes.
  51. SNAP_REGIME_NONE = 0x0,
  52. // The cursor is, non-exclusively, in the first of the snap regimes.
  53. SNAP_REGIME_UPPER = 0x1,
  54. // The cursor is, non-exclusively, in the second of the snap regimes.
  55. SNAP_REGIME_LOWER = 0x2
  56. } ESnapRegimes;
  57. class LLManipScale : public LLManip
  58. {
  59. protected:
  60. LOG_CLASS(LLManipScale);
  61. public:
  62. class ManipulatorHandle
  63. {
  64. public:
  65. LLVector3 mPosition;
  66. EManipPart mManipID;
  67. EScaleManipulatorType mType;
  68. ManipulatorHandle(LLVector3 pos, EManipPart id,
  69. EScaleManipulatorType type)
  70. : mPosition(pos),
  71. mManipID(id),
  72. mType(type)
  73. {
  74. }
  75. };
  76. LLManipScale(LLToolComposite* composite);
  77. ~LLManipScale() override;
  78. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  79. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  80. bool handleHover(S32 x, S32 y, MASK mask) override;
  81. void render() override;
  82. void handleSelect() override;
  83. bool handleMouseDownOnPart(S32 x, S32 y, MASK mask) override;
  84. // Decides which manipulator, if any, should be highlighted by mouse hover:
  85. void highlightManipulators(S32 x, S32 y) override;
  86. bool canAffectSelection() override;
  87. static F32 maxPrimScale(bool is_flora = false);
  88. static F32 minPrimScale(bool is_flora = false);
  89. static void setUniform(bool b);
  90. static bool getUniform();
  91. static void setStretchTextures(bool b);
  92. static bool getStretchTextures();
  93. static void setShowAxes(bool b);
  94. static bool getShowAxes();
  95. static bool getSnapEnabled();
  96. private:
  97. void renderCorners(const LLBBox& local_bbox);
  98. void renderFaces(const LLBBox& local_bbox);
  99. void renderBoxHandle(F32 x, F32 y, F32 z);
  100. void renderAxisHandle(const LLVector3& start, const LLVector3& end);
  101. void renderGuidelinesPart(const LLBBox& local_bbox);
  102. void renderSnapGuides(const LLBBox& local_bbox);
  103. void revert();
  104. LL_INLINE void conditionalHighlight(U32 part,
  105. const LLColor4* highlight = NULL,
  106. const LLColor4* normal = NULL);
  107. void drag(S32 x, S32 y);
  108. void dragFace(S32 x, S32 y);
  109. void dragCorner(S32 x, S32 y);
  110. void sendUpdates(bool send_position_update, bool send_scale_update,
  111. bool corner = false);
  112. LLVector3 faceToUnitVector(S32 part) const;
  113. LLVector3 cornerToUnitVector(S32 part) const;
  114. LLVector3 edgeToUnitVector(S32 part) const;
  115. LLVector3 partToUnitVector(S32 part) const;
  116. LLVector3 unitVectorToLocalBBoxExtent(const LLVector3& v,
  117. const LLBBox& bbox) const;
  118. F32 partToMaxScale(S32 part, const LLBBox& bbox) const;
  119. F32 partToMinScale(S32 part, const LLBBox& bbox) const;
  120. LLVector3 nearestAxis(const LLVector3& v) const;
  121. void stretchFace(const LLVector3& drag_start_agent,
  122. const LLVector3& drag_delta_agent);
  123. // Adjusts texture coords based on mSavedScale and current scale, only
  124. // works for boxes
  125. void adjustTextureRepeats();
  126. void updateSnapGuides(const LLBBox& bbox);
  127. private:
  128. struct compare_manipulators
  129. {
  130. LL_INLINE bool operator()(const ManipulatorHandle* const a,
  131. const ManipulatorHandle* const b) const
  132. {
  133. if (a->mType != b->mType)
  134. {
  135. return a->mType < b->mType;
  136. }
  137. else if (a->mPosition.mV[VZ] != b->mPosition.mV[VZ])
  138. {
  139. return a->mPosition.mV[VZ] < b->mPosition.mV[VZ];
  140. }
  141. else
  142. {
  143. return a->mManipID < b->mManipID;
  144. }
  145. }
  146. };
  147. private:
  148. // The size of the handles at the corners of the bounding box
  149. F32 mBoxHandleSize;
  150. // Handle size after scaling for selection feedback
  151. F32 mScaledBoxHandleSize;
  152. LLVector3d mDragStartPointGlobal;
  153. // The center of the bounding box of all selected objects at time of drag
  154. // start
  155. LLVector3d mDragStartCenterGlobal;
  156. LLVector3d mDragPointGlobal;
  157. LLVector3d mDragFarHitGlobal;
  158. S32 mLastMouseX;
  159. S32 mLastMouseY;
  160. U32 mLastUpdateFlags;
  161. typedef std::set<ManipulatorHandle*,
  162. compare_manipulators> manipulator_list_t;
  163. manipulator_list_t mProjectedManipulators;
  164. LLVector4 mManipulatorVertices[14];
  165. F32 mScaleSnapUnit1; // size of snap multiples for axis 1
  166. F32 mScaleSnapUnit2; // size of snap multiples for axis 2
  167. // Normal of plane in which scale occurs that most faces camera
  168. LLVector3 mScalePlaneNormal1;
  169. // Normal of plane in which scale occurs that most faces camera
  170. LLVector3 mScalePlaneNormal2;
  171. // The direction in which the upper snap guide tick marks face.
  172. LLVector3 mSnapGuideDir1;
  173. // The direction in which the lower snap guide tick marks face.
  174. LLVector3 mSnapGuideDir2;
  175. // The direction in which the upper snap guides face.
  176. LLVector3 mSnapDir1;
  177. // The direction in which the lower snap guides face.
  178. LLVector3 mSnapDir2;
  179. // How far off the scale axis centerline the mouse can be before it
  180. // exits/enters the snap regime.
  181. F32 mSnapRegimeOffset;
  182. // The pixel spacing between snap guide tick marks for the upper scale.
  183. F32 mTickPixelSpacing1;
  184. // The pixel spacing between snap guide tick marks for the lower scale.
  185. F32 mTickPixelSpacing2;
  186. F32 mSnapGuideLength;
  187. // The location of the origin of the scaling operation.
  188. LLVector3 mScaleCenter;
  189. // The direction of the scaling action. In face-dragging this is aligned
  190. // with one of the cardinal axis relative to the prim, but in
  191. // corner-dragging this is along the diagonal.
  192. LLVector3 mScaleDir;
  193. // The distance of the current position nearest the mouse location,
  194. // measured along mScaleDir. Is measured either from the center or from the
  195. // far face/corner depending upon whether uniform scaling is true or false
  196. // respectively.
  197. F32 mScaleSnappedValue;
  198. // Which, if any, snap regime the cursor is currently residing in:
  199. ESnapRegimes mSnapRegime;
  200. F32* mManipulatorScales;
  201. };
  202. #endif // LL_MANIPSCALE_H