root/cafu/trunk/CaWE/MorphPrim.hpp

Revision 457, 5.6 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_MORPH_PRIMITIVE_HPP_INCLUDED
23#define CAFU_MORPH_PRIMITIVE_HPP_INCLUDED
24
25#include "Math3D/Vector3.hpp"
26#include "Templates/Array.hpp"
27
28
29class MapBezierPatchT;
30class MapBrushT;
31class MapPrimitiveT;
32class Renderer2DT;
33class Renderer3DT;
34class wxPoint;
35class MP_FaceT;
36
37
38struct MP_PartT
39{
40    enum TypeT
41    {
42        TYPE_VERTEX,
43        TYPE_EDGE
44    };
45
46
47    MP_PartT() : m_Selected(false)
48    {
49    }
50
51    virtual TypeT     GetType() const=0;
52    virtual Vector3fT GetPos()  const=0;
53
54    bool m_Selected;   ///< Is this part/handle selected by the user?
55};
56
57
58class MP_VertexT : public MP_PartT
59{
60    public:
61
62    TypeT     GetType() const { return TYPE_VERTEX; }
63    Vector3fT GetPos()  const { return pos; }
64
65    Vector3fT pos;
66};
67
68
69class MP_EdgeT : public MP_PartT
70{
71    public:
72
73    MP_EdgeT();
74
75    TypeT     GetType() const { return TYPE_EDGE; }
76    Vector3fT GetPos()  const { return (Vertices[0]->pos + Vertices[1]->pos)*0.5f; }
77
78    MP_VertexT* Vertices[2];    ///< The vertices of this edge (pointing into the MorphPrimT::m_Vertices array).
79    MP_FaceT*   Faces[2];       ///< The faces this edge belongs to (pointing into the MorphPrimT::m_Faces array).
80};
81
82
83class MP_FaceT
84{
85    public:
86
87    ArrayT<MP_EdgeT*> Edges;    ///< The edges of this face (pointing into the MorphPrimT::m_Edges array).
88};
89
90
91/// This is a helper class for the ToolMorphT ("edit vertices") tool.
92/// It represents a map primitive (a brush or a bezier patch) that is currently being morphed by the tool.
93///
94/// This class is considered a \emph{helper} class, because the user code (i.e. the morph tool)
95/// (currently) needs knowledge about the implementation of this class whenever it keeps pointers to
96/// parts (vertices, edges) of the object that this class represents. Such pointers into the internal
97/// structures may become invalidated by certain methods, and thus great care is required.
98class MorphPrimT
99{
100    public:
101
102    /// The constructor.
103    /// @param MapPrim   The original brush or bezier patch that this MorphPrimT is associated with / attached to.
104    /// Note that this MorphPrimT does not become the "owner" of the MapPrim pointer, e.g. it does not attempt to delete it in its dtor.
105    /// That also means that this MorphPrimT should not live longer than the MapPrim object.
106    MorphPrimT(const MapPrimitiveT* MapPrim);
107
108    ~MorphPrimT();
109
110    const MapPrimitiveT* GetMapPrim() const { return m_MapPrim; }
111    bool                 IsModified() const { return m_Modified; }
112
113    /// Returns a newly created instance matching the morphed map primitive, or NULL if reconstruction was not possible.
114    /// It does not reset the modified-flag.
115    MapPrimitiveT* GetMorphedMapPrim() const;
116
117    /// Moves the selected handles by Delta.
118    void MoveSelectedHandles(const Vector3fT& Delta);
119
120    void Render(Renderer2DT& Renderer, bool RenderVertexHandles, bool RenderEdgeHandles) const;
121    void Render(Renderer3DT& Renderer, bool RenderVertexHandles, bool RenderEdgeHandles) const;
122
123
124    // Must store MP_VertexT*, not MP_VertexT, or else array growing renders all external pointers obsolete...
125    ArrayT<MP_VertexT*> m_Vertices;
126    ArrayT<MP_EdgeT*  > m_Edges;
127    ArrayT<MP_FaceT*  > m_Faces;
128
129
130    private:
131
132    MorphPrimT(const MorphPrimT&);          ///< Use of the Copy Constructor    is not allowed.
133    void operator = (const MorphPrimT&);    ///< Use of the Assignment Operator is not allowed.
134
135    /// After a change of (or in) the m_Vertices array, this method computes the convex hull over them
136    /// and updates (or rather, recomputes) all other member variables (the m_Edges and m_Faces).
137    /// This method should only be called if the m_MapPrim member is of type MapBrushT,
138    /// because it also modifies the m_Vertices array, which is not desired for the MapBezierPatchT type.
139    void UpdateBrushFromVertices();
140    void UpdatePatch();
141
142    MP_VertexT* FindClosestVertex(const Vector3fT& Point) const;
143    MP_EdgeT*   FindEdge(const MP_VertexT* v1, const MP_VertexT* v2) const;
144
145    MP_VertexT* GetConnectionVertex(MP_EdgeT* Edge1, MP_EdgeT* Edge2) const;
146    void RenderHandle(Renderer3DT& Renderer, const wxPoint& ClientPos, const float* color) const;
147
148
149    const MapPrimitiveT* m_MapPrim;     ///< The "attached" source/reference map brush / bezier patch.
150    bool                 m_Modified;    ///< Whether the MorphPrimT contains any modifications to the "attached" map brush/bezier patch.
151    MapBezierPatchT*     m_RenderBP;    ///< If m_MapPrim is a Bezier patch, this is the current morphed clone that we use for rendering.
152};
153
154#endif
Note: See TracBrowser for help on using the browser.