VPathEditor.h

Engine/source/Verve/VPath/VPathEditor.h

More...

Classes:

Namespaces:

namespace

Public Typedefs

VPathEditorMode 

Public Functions

Detailed Description

Public Typedefs

typedef VPathEditor::EditMode VPathEditorMode 

Public Functions

DefineEnumType(VPathEditorMode )

  1
  2//-----------------------------------------------------------------------------
  3// Verve
  4// Copyright (C) 2014 - Violent Tulip
  5//
  6// Permission is hereby granted, free of charge, to any person obtaining a copy
  7// of this software and associated documentation files (the "Software"), to
  8// deal in the Software without restriction, including without limitation the
  9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10// sell copies of the Software, and to permit persons to whom the Software is
 11// furnished to do so, subject to the following conditions:
 12//
 13// The above copyright notice and this permission notice shall be included in
 14// all copies or substantial portions of the Software.
 15//
 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 22// IN THE SOFTWARE.
 23//-----------------------------------------------------------------------------
 24#ifndef _VT_VPATHEDITOR_H_
 25#define _VT_VPATHEDITOR_H_
 26
 27#ifndef _EDITTSCTRL_H_
 28#include "gui/worldEditor/editTSCtrl.h"
 29#endif
 30
 31#ifndef _VT_VPATH_H_
 32#include "VPath.h"
 33#endif
 34
 35#ifndef _UNDO_H_
 36#include "util/undo.h"
 37#endif
 38
 39//-----------------------------------------------------------------------------
 40
 41class VPathEditor : public EditTSCtrl
 42{
 43    typedef EditTSCtrl Parent;
 44
 45public:
 46
 47    enum RenderType
 48    {
 49        k_RenderSegments,
 50        k_RenderNodes,
 51    };
 52
 53    enum EditMode
 54    {
 55        k_Gizmo,
 56        k_AddNode,
 57        k_DeleteNode
 58    };
 59
 60    struct Selection
 61    {
 62        Selection( void ) :
 63                Path( NULL ),
 64                Node( -1 )
 65        {
 66            TangentHandle[0].zero();
 67            TangentHandle[1].zero();
 68        };
 69
 70        VPath     *Path;
 71        S32        Node;
 72        Point3F    TangentHandle[2];
 73    };
 74
 75    struct PathEditAction
 76    {
 77        PathEditAction( void ) :
 78                Dirty( false ),
 79                Transform( true )
 80        {
 81            // Void.
 82        };
 83
 84        bool        Dirty;
 85        MatrixF     Transform;
 86    };
 87
 88    struct NodeEditAction
 89    {
 90        NodeEditAction( void ) :
 91                Dirty( false ),
 92                Position( 0.f, 0.f, 0.f ),
 93                Rotation( 0.f, 0.f, 0.f, 0.f ),
 94                Weight( 0.f )
 95        {
 96            // Void.
 97        };
 98
 99        bool        Dirty;
100        Point3F     Position;
101        QuatF       Rotation;
102        F32         Weight;
103    };
104
105    bool                mIsDirty;
106    EditMode            mEditMode;
107
108    Selection           mSelection;
109    PathEditAction      mPathEdit;
110    NodeEditAction      mNodeEdit;
111
112    bool                mEditWeight;
113    S32                 mEditWeightHandle;
114
115    GFXStateBlockRef    mStateBlock;
116
117public:
118
119    VPathEditor( void );
120
121    virtual bool    onAdd( void );
122    virtual bool    onWake( void );
123
124    static  void    initPersistFields( void );
125
126    // Gui Events.
127
128    virtual void    on3DMouseDown( const Gui3DMouseEvent &pEvent );
129    virtual void    on3DMouseUp( const Gui3DMouseEvent &pEvent );
130    virtual void    on3DMouseMove( const Gui3DMouseEvent &pEvent );
131    virtual void    on3DMouseDragged( const Gui3DMouseEvent &pEvent );
132
133    // Render Methods.
134
135    virtual void    setStateBlock( void );
136    virtual void    renderScene( const RectI &pUpdateRect );
137    void            renderPaths( const RenderType &pRenderType );
138
139    void            renderPath( const RenderType &pRenderType, VPath *pPath, const ColorI &pColor );
140    void            renderLinearPath( VPath *pPath, const ColorI &pColor );
141    void            renderBezierPath( VPath *pPath, const ColorI &pColor );
142
143    DECLARE_CONOBJECT( VPathEditor );
144
145public:
146
147    // Reference Methods.
148
149    VPath          *getClientPath( VPath *pPath );
150
151    // Selection Methods.
152
153    inline bool     isValidSelection( void ) { return ( mSelection.Path != NULL && mSelection.Node != -1 ); };
154
155    bool            updateSelection( const Gui3DMouseEvent &pEvent );
156    void            updateSelection( VPath *pPathObject, const S32 &pNodeIndex );
157    void            updateSelection( void );
158
159    // Weight Editing.
160
161    bool            isEditingWeight( const Gui3DMouseEvent &pEvent );
162    inline bool     isEditingWeight( void ) { return mEditWeight; };
163
164    void            updateWeight( const Gui3DMouseEvent &pEvent );
165
166    // Path Editor.
167
168    bool            getPointOnPath( VPath *pPath, const Gui3DMouseEvent &pEvent, S32 &pNode, MatrixF &pTransform );
169    bool            getPointOnLinearPath( VPath *pPath, const Gui3DMouseEvent &pEvent, S32 &pNode, MatrixF &pTransform );
170    bool            getPointOnBezierPath( VPath *pPath, const Gui3DMouseEvent &pEvent, S32 &pNode, MatrixF &pTransform );
171
172    void            setPathPosition( const Point3F &pPosition );
173    void            setPathRotation( const QuatF &pRotation );
174    void            setPathTransform( const MatrixF &pTransform );
175    void            setPathScale( const VectorF &pScale );
176
177    // Node Editing.
178
179    void            addNode( const Gui3DMouseEvent &pEvent );
180    void            deleteNode( const S32 &pNodeIndex );
181
182    void            setNodePosition( const S32 &pNodeIndex, const Point3F &pPosition );
183    void            setNodeRotation( const S32 &pNodeIndex, const QuatF &pRotation );
184    void            setNodeWeight( const S32 &pNodeIndex, const F32 &pWeight );
185    void            setNodeOrientationMode( const S32 &pNodeIndex, const VPathNode::eOrientationType &pType );
186    void            setNodeOrientationMode( const S32 &pNodeIndex, const VPathNode::eOrientationType &pType, const Point3F &pPoint );
187
188    void            pushPathEdit( void );
189    void            popPathEdit( void );
190
191    void            pushNodeEdit( void );
192    void            popNodeEdit( void );
193
194    void            setWorldEditorDirty( void );
195
196private:
197
198    class VPathEditorEditPathAction : public UndoAction
199    {
200    public:
201
202        VPathEditorEditPathAction( const UTF8 *pName = "" ) :
203                UndoAction( pName ), mEditor(NULL), mPath(NULL)
204        {
205            // Void.
206        };
207
208        VPathEditor               *mEditor;
209
210        VPath                     *mPath;
211        MatrixF                    mTransform;
212
213        virtual void    undo( void );
214        virtual void    redo( void );
215    };
216
217    class VPathEditorEditNodeAction : public UndoAction
218    {
219    public:
220
221        VPathEditorEditNodeAction( const UTF8 *pName = "" ) :
222                UndoAction( pName ), mEditor(NULL), mPath(NULL), mNodeIndex(0), mNodeWeight(0.0f)
223        {
224            // Void.
225           mNodeOrientation.Type = VPathNode::k_OrientationFree;
226           mNodeOrientation.Point = Point3F(0.0f, 0.0f, 0.0f);
227        };
228
229        VPathEditor               *mEditor;
230
231        VPath                     *mPath;
232        S32                        mNodeIndex;
233
234        Point3F                    mNodePosition;
235        QuatF                      mNodeRotation;
236        F32                        mNodeWeight;
237
238        VPathNode::sOrientation    mNodeOrientation;
239
240        virtual void    undo( void );
241        virtual void    redo( void );
242    };
243
244    class VPathEditorAddNodeAction : public VPathEditorEditNodeAction
245    {
246    public:
247
248        VPathEditorAddNodeAction( const UTF8 *pName = "" ) :
249                VPathEditorEditNodeAction( "Add Node" )
250        {
251            // Void.
252        };
253
254        virtual void    undo( void );
255        virtual void    redo( void );
256    };
257
258    class VPathEditorDeleteNodeAction : public VPathEditorEditNodeAction
259    {
260    public:
261
262        VPathEditorDeleteNodeAction( const UTF8 *pName = "" ) :
263                VPathEditorEditNodeAction( "Delete Node" )
264        {
265            // Void.
266        };
267
268        virtual void    undo( void );
269        virtual void    redo( void );
270    };
271};
272
273//-----------------------------------------------------------------------------
274
275// Define Types.
276typedef VPathEditor::EditMode VPathEditorMode;
277
278// Declare Enum Types.
279DefineEnumType( VPathEditorMode );
280
281//-----------------------------------------------------------------------------
282
283namespace Utility
284{
285    bool            FindNearestDistanceBetweenLines( const Point3F &pA0, const Point3F &pA1, const Point3F &pB0, const Point3F &pB1, Point3F *pOutA, Point3F *pOutB, F32 *pDist );
286
287    bool            IntersectLineSegment( const Point3F &pA0, const Point3F &pA1, const Point3F &pB0, const Point3F &pB1, const bool pSnap, Point3F *pX );
288    bool            FindNearestPointOnLine( const Point3F &pSrcPosition, const Point3F &pA0, const Point3F &pA1, Point3F *pDstPosition );
289
290    F32             GetPitch( const VectorF &pVec );
291    F32             GetYaw( const VectorF &pVec );
292};
293
294//-----------------------------------------------------------------------------
295
296#endif // _VT_VPATHEDITOR_H_
297