curve.h

Go to the documentation of this file.
00001 
00002 //**************************************************************************/
00003 // Copyright (c) 2008 Autodesk, Inc.
00004 // All rights reserved.
00005 //
00006 // Use of this software is subject to the terms of the Autodesk license
00007 // agreement provided at the time of installation or download, or which
00008 // otherwise accompanies this software in either electronic or hard copy form.
00009 //
00010 //**************************************************************************/
00011 // DESCRIPTION:
00012 // CREATED: September 2011
00013 //**************************************************************************/
00014 
00015 namespace mudbox {
00016 
00017 class NURBSCurve;
00019 
00020 class MBDLL_DECL CurveBase : public GroupNode
00021 {
00022     DECLARE_CLASS;
00023 
00024 public:
00025 
00027     CurveBase();
00029     virtual ~CurveBase();
00030 
00032     virtual void Render();
00033 
00035     virtual void Serialize(Stream &s);
00036 
00038     void SetSelected(bool bTOrF) { m_bSelected = bTOrF; }
00039     bool Selected() { return m_bSelected; }
00040 
00042     virtual void SetClosed(bool bTOrF) { m_bClosed = bTOrF; }
00043     bool Closed() { return m_bClosed; }
00044 
00048     virtual void SetGeometry(mudbox::Geometry *pGeom);
00049     mudbox::Geometry *Geometry() const;
00050 
00052     virtual const AxisAlignedBoundingBox &BoundingBox() { return m_AABB; }
00053 
00055     virtual void CopyTo( Node *pNode) const;
00056 
00059     virtual float Length() const;
00060 
00061 protected:
00062 
00063     abool m_bSelected;
00064     abool m_bClosed;
00065 
00067     aptr<mudbox::Geometry> m_pGeometry;
00068 
00071 
00072     AxisAlignedBoundingBox m_AABB;
00073     bool m_bRefreshBoundingBox;
00074 };
00075 
00076 struct MBDLL_DECL CurvePoint
00077 {
00078     CurvePoint();
00079 
00080     Vector WorldPosition;
00081 
00082     // Surface point contains all of the above info
00083     mudbox::SurfacePoint SurfacePt;
00084 };
00085 
00086 class MBDLL_DECL MudboxCurve : public CurveBase
00087 {
00088     DECLARE_CLASS;
00089 public:
00090     MudboxCurve();
00091     virtual ~MudboxCurve();
00092 
00095     virtual int AddPoint(const CurvePoint &pt);
00096 
00099     virtual bool SetPoint(int index, const CurvePoint &pt);
00100 
00103     virtual bool SetPoint(int index, const Vector &pt);
00104 
00107     virtual const CurvePoint &Point(int index) const;
00108 
00110     virtual Vector WorldPosition(int iIndex) const;
00111                
00113     virtual int PointCount() const;
00114 
00117     virtual bool Point(int index, CurvePoint &point);
00118 
00120     virtual const QList<CurvePoint> &Points();
00121 
00124     virtual bool InsertPoint(int before, const CurvePoint &pt);
00125 
00128     virtual bool RemovePoint(int index);
00129 
00131     virtual void Serialize(Stream &s);
00132 
00134     virtual const AxisAlignedBoundingBox &BoundingBox();
00135 
00137     virtual void CopyTo(Node *pNode) const;
00138 
00140     virtual bool IsConstrainedToSurface( void ) const;
00141     
00143     virtual void CreateSpline( float fSmoothness );
00144 
00147     virtual void BeginEdit();
00148 
00150     virtual void EndEdit();
00151     
00155     virtual NURBSCurve *Spline() const;
00156 
00158     virtual bool IsSpline( void ) const;
00159 
00161     virtual void ProjectPoint( const Vector &vPoint, Vector &vResult ) const;
00162 
00164     enum CurveType
00165     {
00166         CT_3D = 0,
00167         CT_2D,
00168     };
00169 
00171     virtual void SetCurveType(enum CurveType ct);
00172 
00174     virtual enum CurveType CurveType() const;
00175 
00177     virtual NURBSCurve *FalloffCurve();
00178 protected:
00179 
00182     QList<CurvePoint> m_vPoints;
00183     enum CurveType m_eCurveType;     
00184 };
00185 
00188 Vector MBDLL_DECL WindowPositionNormalized(const MudboxCurve *pCurve, int iIndex) ;
00189 
00192 Vector MBDLL_DECL WindowPosition(const MudboxCurve *pCurve, int iIndex) ;
00193  
00194 class MBDLL_DECL CurvePicker {
00195 public:
00196     struct MBDLL_DECL CurveHit
00197     {
00198         CurveHit(MudboxCurve *pCurve, int iPointIndex, Vector point3D, Vector point2D, float distanceToMouse)
00199         { Curve = pCurve; PointIndex = iPointIndex; Point3D = point3D; Point2D = point2D; DistanceToMouse = distanceToMouse; }
00200 
00201         CurveHit();
00202 
00203         MudboxCurve *Curve;
00204         int PointIndex;
00205         Vector Point3D;
00206         Vector Point2D;
00207         float DistanceToMouse;
00208     };
00209 
00210     enum CurveTestPoints
00211     {
00212         CTP_NONE = 0,
00213         CTP_START,
00214         CTP_END,
00215         CTP_START_END,
00216         CTP_ALL,
00217     };
00218 
00219 public:
00220     static void hitTestCurves(float fMouseX, float fMouseY, float distanceTolerance, QVector<CurveHit> &hitCurves, CurveTestPoints ctp = CTP_START_END, bool bTestLockedCurves = false);
00221     // Returns the nearest point to the mouse position. Returns -1 if no point is inside the distance tolerance.
00222     // On CTP_ALL mode, the curveHit will always be set to the nearest curve point, even it's out of distance tolerance.
00223     static int hitTestCurvePoints(float fMouseX, float fMouseY, float distanceTolerance, MudboxCurve *pCurve, CurveHit &curveHit, CurveTestPoints ctp = CTP_START_END);
00224     static float projectPointToCurve(float fMouseX, float fMouseY, MudboxCurve * pCurve, int iPointIndex, Vector &vProjection);
00225     static bool snapMouse(float fMouseX, float fMouseY, float fSnappingDistance, MudboxCurve *pCurve, float &fNewMouseX, float &fNewMouseY);
00226 };
00227 
00228 
00230 class MBDLL_DECL CurveOperator : public Node
00231 {
00232     DECLARE_CLASS;
00233 
00234 public:
00235     CurveOperator( MudboxCurve *pC = 0 );
00236 
00237     void Close( bool bMerge = false );
00238     
00239 private:
00240     MudboxCurve *m_pCurve;
00241 };
00242 
00243 
00244 }; // end of namespace mudbox