root/cafu/trunk/CaWE/ToolMorph.hpp

Revision 457, 8.1 KB (checked in by Carsten, 4 months ago)

Using UltraEdit's multi-line search-and-replace-in-files feature, replaced


^#ifndef _(CAFU|CF|CFS|CA)_(.*)_$
^#define _\1_\2_$

with

#ifndef CAFU_\2_INCLUDED
#define CAFU_\2_INCLUDED

and


^#ifndef _(.*)_HPP_$
^#define _\1_HPP_$

with

#ifndef CAFU_\1_HPP_INCLUDED
#define CAFU_\1_HPP_INCLUDED

Closes #91.

Line 
1/*
2=================================================================================
3This file is part of Cafu, the open-source game engine and graphics engine
4for multiplayer, cross-platform, real-time 3D action.
5Copyright (C) 2002-2012 Carsten Fuchs Software.
6
7Cafu is free software: you can redistribute it and/or modify it under the terms
8of the GNU General Public License as published by the Free Software Foundation,
9either version 3 of the License, or (at your option) any later version.
10
11Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with Cafu. If not, see <http://www.gnu.org/licenses/>.
17
18For support and more information about Cafu, visit us at <http://www.cafu.de>.
19=================================================================================
20*/
21
22#ifndef CAFU_TOOL_MORPH_HPP_INCLUDED
23#define CAFU_TOOL_MORPH_HPP_INCLUDED
24
25#include "Tool.hpp"
26
27
28class  AxesInfoT;
29class  Renderer2DT;
30class  Renderer3DT;
31class  MorphPrimT;
32class  OptionsBar_EditVerticesToolT;
33struct MP_PartT;
34
35
36struct MorphHandleT
37{
38    /// The default constructor.
39    MorphHandleT() : MorphPrim(NULL), Part(NULL) { }
40
41    MorphPrimT* MorphPrim;
42    MP_PartT*   Part;
43};
44
45
46/// This class represents the "Edit Vertices" / "Morph" tool.
47class ToolMorphT : public ToolT, public ObserverT
48{
49    public:
50
51    ToolMorphT(MapDocumentT& MapDoc, ToolManagerT& ToolMan, wxWindow* ParentOptionsBar);
52
53    ~ToolMorphT();
54
55
56    void NoteEditModeChanged();     ///< This is called by the options bar whenever the edit mode has changed (edit vertices, edges, or both).
57    void InsertVertex();            ///< Called by the options bar when the user pressed the "Insert Vertex" button.
58
59
60    // Implementations/overrides of ToolT methods.
61    int       GetWxEventID() const { return ChildFrameT::ID_MENU_TOOLS_TOOL_EDITVERTICES; }
62    wxWindow* GetOptionsBar();
63    void      OnActivate(ToolT* OldTool);
64    void      OnDeactivate(ToolT* NewTool);
65    bool      CanDeactivate();
66
67    bool OnKeyDown2D   (ViewWindow2DT& ViewWindow, wxKeyEvent&   KE);
68    bool OnLMouseDown2D(ViewWindow2DT& ViewWindow, wxMouseEvent& ME);
69    bool OnMouseMove2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME);
70    bool OnLMouseUp2D  (ViewWindow2DT& ViewWindow, wxMouseEvent& ME);
71
72    bool OnKeyDown3D   (ViewWindow3DT& ViewWindow, wxKeyEvent&   KE);
73    bool OnLMouseDown3D(ViewWindow3DT& ViewWindow, wxMouseEvent& ME);
74    bool OnMouseMove3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME);
75    bool OnLMouseUp3D  (ViewWindow3DT& ViewWindow, wxMouseEvent& ME);
76
77    bool IsHiddenByTool(const MapElementT* Elem) const;
78    void RenderTool2D(Renderer2DT& Renderer) const;
79    void RenderTool3D(Renderer3DT& Renderer) const;
80
81    // ObserverT implementation.
82    void NotifySubjectChanged_Selection(SubjectT* Subject, const ArrayT<MapElementT*>& OldSelection, const ArrayT<MapElementT*>& NewSelection);
83    void NotifySubjectChanged_Deleted(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements);
84    void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail);
85    void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail, const ArrayT<BoundingBox3fT>& OldBounds);
86    void NotifySubjectDies(SubjectT* dyingSubject);
87
88    // The TypeSys related declarations for this class.
89    virtual const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
90    static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
91    static const cf::TypeSys::TypeInfoT TypeInfo;
92
93
94    private:
95
96    enum DragStateT { DragNothing, DragBoxSelection, DragMorphHandles };
97
98    /// Returns the handles of all objects that are currently being morphed.
99    ArrayT<MorphHandleT> GetHandles(bool SelectedOnly, bool Vertices=true, bool Edges=true) const;
100
101    /// Finds all morph handles that are in ViewWindow at Point.
102    /// Note that this may return a mix of vertex and edge handles (if the tool options bar is set to "edit both"), selected and unselected!
103    ///
104    /// @param ViewWindow   The window in which we should look at Point for handles.
105    /// @param Point        The coordinate of interest in ViewWindow, given in Tool(!) Space.
106    /// @returns the array of all morph handles "under" Point in ViewWindow.
107    ArrayT<MorphHandleT> GetMorphHandlesAt(ViewWindow2DT& ViewWindow, const wxPoint& Point) const;
108
109    /// Finds the morph handle that is in ViewWindow along the ray through Point.
110    /// @param ViewWindow   The window in which we should look along the ray through Point for handles.
111    /// @param Point        The coordinate through which the ray of interested is cast into the world, given in Window(!) Space.
112    /// @param FoundMH      If a morph handle was found, it is returned via this reference.
113    ///    If there is more than one morph handle along the ray through Point, the morph handle that is closest to the viewer is returned.
114    /// @returns true if a morph handle was found in ViewWindow along the ray through Point, false if no such handle exists.
115    bool GetMorphHandleAt(ViewWindow3DT& ViewWindow, const wxPoint& Point, MorphHandleT& FoundMH) const;
116
117    int  MorphPrims_Find(const MapElementT* Elem) const;        ///< Returns the array index number of the MorphPrimT for the given Elem, -1 if there is none.
118    void MorphPrims_SyncTo(const ArrayT<MapElementT*>& Elems);  ///< Sync's our m_MorphPrims to the given Elems, so that they correspond 1:1 to each other.
119    void MoveSelectedHandles(const Vector3fT& Delta);           ///< WARNING: This method *DESTROYS* all handle pointers into any of the m_MorphPrims!!
120    void NudgeSelectedHandles(const AxesInfoT& AxesInfo, const wxKeyEvent& KE);
121    void FinishDragMorphHandles();                              ///< Called from the 2D or 3D views, for morph-modified items, this function replaces the original primitives with the morphed ones in the map.
122    void OnEscape(ViewWindowT& ViewWindow);
123
124
125    // The crucial member variables that define the essential state of this tool are m_MorphPrims and m_DragState.
126    //
127    // A few general notes about dragging morph (vertex and edge) handles:
128    // a) At any time, any number of morph handles may be selected. The user then picks *one* to start dragging them *all*.
129    // b) During a drag, the original underlying MorphPrimT(s) can be entirely be re-created and re-formed, due to the nature of the convex-hull algorithm.
130    //    Therefore, it's quasi impossible to keep any pointer to anything "inside" the MorphPrimT(s) during the drag,
131    //    especially we can NOT keep a pointer to the handle (vertex or edge) that was used to start the drag!!
132    //    Fortunately, we don't need any such information, because we just duplicate the current position of
133    //    the handle that was chosen to start the drag in the m_DragHandleCurrentPos member.
134    ArrayT<MorphPrimT*> m_MorphPrims;               ///< List of primitives currently being morphed by this tool.
135    DragStateT          m_DragState;                ///< If we are currently dragging anything (LMB is down), and if so, what.
136    Vector3fT           m_DragHandleOrigPos;        ///< If m_DragState==DragMorphHandles, this was the original position of the handle when the drag started.      If m_DragState==DragBoxSelection, this is where dragging the new selection box began.
137    Vector3fT           m_DragHandleCurrentPos;     ///< If m_DragState==DragMorphHandles, this is the current position of the handle that was chosen for the drag. If m_DragState==DragBoxSelection, this the current position of the other corner of the selection box.
138    bool                m_IsRecursiveSelfNotify;    ///< Whether an observer message has been triggered by the tool itself.
139
140    OptionsBar_EditVerticesToolT* m_OptionsBar;   ///< The options bar for this tool.
141};
142
143#endif
Note: See TracBrowser for help on using the browser.