00001
00032 #ifndef LL_MANIPSCALE_H
00033 #define LL_MANIPSCALE_H
00034
00035
00036
00037
00038
00039
00040 #include "lltool.h"
00041 #include "v3math.h"
00042 #include "v4math.h"
00043 #include "llmanip.h"
00044 #include "llviewerobject.h"
00045 #include "llbbox.h"
00046
00047 class LLToolComposite;
00048 class LLColor4;
00049
00050 typedef enum e_scale_manipulator_type
00051 {
00052 SCALE_MANIP_CORNER,
00053 SCALE_MANIP_FACE
00054 } EScaleManipulatorType;
00055
00056
00057 class LLManipScale : public LLManip
00058 {
00059 public:
00060 class ManipulatorHandle
00061 {
00062 public:
00063 LLVector3 mPosition;
00064 EManipPart mManipID;
00065 EScaleManipulatorType mType;
00066
00067 ManipulatorHandle(LLVector3 pos, EManipPart id, EScaleManipulatorType type):mPosition(pos), mManipID(id), mType(type){}
00068 };
00069
00070
00071 LLManipScale( LLToolComposite* composite );
00072 ~LLManipScale();
00073
00074 virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00075 virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask );
00076 virtual BOOL handleHover( S32 x, S32 y, MASK mask );
00077 virtual void render();
00078 virtual void handleSelect();
00079 virtual void handleDeselect();
00080
00081 virtual BOOL handleMouseDownOnPart(S32 x, S32 y, MASK mask);
00082 virtual void highlightManipulators(S32 x, S32 y);
00083 virtual BOOL canAffectSelection();
00084
00085 static void setUniform( BOOL b );
00086 static BOOL getUniform();
00087 static void setStretchTextures( BOOL b );
00088 static BOOL getStretchTextures();
00089 static void setShowAxes( BOOL b );
00090 static BOOL getShowAxes();
00091
00092 private:
00093 void renderCorners( const LLBBox& local_bbox );
00094 void renderFaces( const LLBBox& local_bbox );
00095 void renderEdges( const LLBBox& local_bbox );
00096 void renderBoxHandle( F32 x, F32 y, F32 z );
00097 void renderAxisHandle( const LLVector3& start, const LLVector3& end );
00098 void renderGuidelinesPart( const LLBBox& local_bbox );
00099 void renderSnapGuides( const LLBBox& local_bbox );
00100
00101 void revert();
00102
00103 inline void conditionalHighlight( U32 part, const LLColor4* highlight = NULL, const LLColor4* normal = NULL );
00104
00105 void drag( S32 x, S32 y );
00106 void dragFace( S32 x, S32 y );
00107 void dragCorner( S32 x, S32 y );
00108
00109 void sendUpdates( BOOL send_position_update, BOOL send_scale_update, BOOL corner = FALSE);
00110
00111 LLVector3 faceToUnitVector( S32 part ) const;
00112 LLVector3 cornerToUnitVector( S32 part ) const;
00113 LLVector3 edgeToUnitVector( S32 part ) const;
00114 LLVector3 partToUnitVector( S32 part ) const;
00115 LLVector3 unitVectorToLocalBBoxExtent( const LLVector3& v, const LLBBox& bbox ) const;
00116 F32 partToMaxScale( S32 part, const LLBBox& bbox ) const;
00117 F32 partToMinScale( S32 part, const LLBBox& bbox ) const;
00118 LLVector3 nearestAxis( const LLVector3& v ) const;
00119
00120 void stretchFace( const LLVector3& drag_start_agent, const LLVector3& drag_delta_agent);
00121
00122 void adjustTextureRepeats();
00123
00124 void updateSnapGuides(const LLBBox& bbox);
00125 private:
00126
00127 struct compare_manipulators
00128 {
00129 bool operator() (const ManipulatorHandle* const a, const ManipulatorHandle* const b) const
00130 {
00131 if (a->mType != b->mType)
00132 return a->mType < b->mType;
00133 else if (a->mPosition.mV[VZ] != b->mPosition.mV[VZ])
00134 return a->mPosition.mV[VZ] < b->mPosition.mV[VZ];
00135 else
00136 return a->mManipID < b->mManipID;
00137 }
00138 };
00139
00140
00141 F32 mBoxHandleSize;
00142 F32 mScaledBoxHandleSize;
00143 EManipPart mManipPart;
00144 LLVector3d mDragStartPointGlobal;
00145 LLVector3d mDragStartCenterGlobal;
00146 LLVector3d mDragPointGlobal;
00147 LLVector3d mDragFarHitGlobal;
00148 S32 mLastMouseX;
00149 S32 mLastMouseY;
00150 BOOL mSendUpdateOnMouseUp;
00151 U32 mLastUpdateFlags;
00152 typedef std::set<ManipulatorHandle*, compare_manipulators> minpulator_list_t;
00153 minpulator_list_t mProjectedManipulators;
00154 LLVector4 mManipulatorVertices[14];
00155 F32 mScaleSnapUnit1;
00156 F32 mScaleSnapUnit2;
00157 LLVector3 mScalePlaneNormal1;
00158 LLVector3 mScalePlaneNormal2;
00159 LLVector3 mSnapGuideDir1;
00160 LLVector3 mSnapGuideDir2;
00161 LLVector3 mSnapDir1;
00162 LLVector3 mSnapDir2;
00163 F32 mSnapRegimeOffset;
00164 F32 mSnapGuideLength;
00165 LLVector3 mScaleCenter;
00166 LLVector3 mScaleDir;
00167 F32 mScaleSnapValue;
00168 BOOL mInSnapRegime;
00169 F32* mManipulatorScales;
00170 };
00171
00172 #endif // LL_MANIPSCALE_H