gwnavruntime/navmesh/dynamicnavfloor.h Source File

dynamicnavfloor.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // Primary contact: JUBA - secondary contact: LASI
9 #ifndef Navigation_DynamicNavFloor_H
10 #define Navigation_DynamicNavFloor_H
11 
16 
17 
18 namespace Kaim
19 {
20 
21 // ----------------------------
22 // ----- DynamicNavVertex -----
23 // ----------------------------
24 class DynamicNavVertex
25 {
26  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
27 
28 public:
29  DynamicNavVertex() :
30  m_pixelPos(InvalidPixelCoord, InvalidPixelCoord),
31  m_altitude(KyFloat32MAXVAL),
32  m_first(KyUInt32MAXVAL)
33  {}
34 
35  DynamicNavVertex(const PixelPos& pixelPos, KyFloat32 alt) :
36  m_pixelPos(pixelPos),
37  m_altitude(alt),
38  m_first(KyUInt32MAXVAL)
39  {}
40 
41  bool operator==(const DynamicNavVertex& other) const
42  {
43  return m_pixelPos == other.m_pixelPos && m_altitude == other.m_altitude;
44  }
45  bool operator!=(const DynamicNavVertex& other) const
46  {
47  return !operator==(other);
48  }
49 public:
50  PixelPos m_pixelPos;
51  KyFloat32 m_altitude;
52  KyUInt32 m_first; // first outgoing edge
53 };
54 
55 // ------------------------------
56 // ----- DynamicNavTriangle -----
57 // ------------------------------
58 class DynamicNavTriangle
59 {
60 public:
61  DynamicNavTriangle() : m_edge(KyUInt32MAXVAL) {}
62  DynamicNavTriangle(KyUInt32 edge) : m_edge(edge) {}
63 
64 public:
65  KyUInt32 m_edge; // one edge around the face
66 };
67 
68 // --------------------------
69 // ----- DynamicNavHalfEdge -----
70 // --------------------------
71 
72 enum DynamicNavHalfEdgeType
73 {
74  DynamicNavHalfEdgeType_Normal = 0,
75  DynamicNavHalfEdgeType_Wall = 1,
76  DynamicNavHalfEdgeType_Hole = 2,
77  DynamicNavHalfEdgeType_FloorBoundary = 3,
78  DynamicNavHalfEdgeType_CellBoundary = 4,
79 
80  DynamicNavHalfEdgeType_Invalid = 0xFFFFFFFF
81 };
82 
83 class DynamicNavHalfEdge
84 {
85 public:
86  DynamicNavHalfEdge()
87  : m_idx(KyUInt32MAXVAL)
88  , m_start(KyUInt32MAXVAL)
89  , m_end(KyUInt32MAXVAL)
90  , m_face(KyUInt32MAXVAL)
91  , m_next(KyUInt32MAXVAL)
92  , m_type(DynamicNavHalfEdgeType_Invalid)
93  , m_pair(KyUInt32MAXVAL)
94  , m_cardinalDir(CardinalDir_INVALID)
95  , m_stitch1To1EdgeIdx(KyUInt32MAXVAL) {}
96 public:
97  KyUInt32 m_idx;
98  KyUInt32 m_start; // start vertex
99  KyUInt32 m_end; // end vertex (added by LS for dynamicFloorBuilder)
100  KyUInt32 m_face; // the adjacent face
101  KyUInt32 m_next; // next edge
102  DynamicNavHalfEdgeType m_type; // 0 = normal, 1 = wall, 2 = hole, 3 = Floor boundary, 4 = cell boundary
103 
104  // if m_type == Normal : pair edge idx in the same floor
105  // if m_type == FloorBoundary || m_type == CellBoundary, UNUSED
106  KyUInt32 m_pair;
107 
108  CardinalDir m_cardinalDir; // use for edge of type == 3 (cell boundary) only. The cardinal dir of the side of the cell
109 
110  mutable KyUInt32 m_stitch1To1EdgeIdx;
111 };
112 
113 // --------------------------
114 // ----- DynamicNavFloor -----
115 // --------------------------
116 class DynamicNavFloor
117 {
118  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
119 public:
120  enum PixelPosRelativeCoordSystem
121  {
122  PIXELPOS_ABSOLUTE,
123  PIXELPOS_RELATIVE_TO_CELL
124  };
125 
126 public:
127  DynamicNavFloor();
128  DynamicNavFloor(MemoryHeap* memoryHeap);
129 
130  void Clear();
131 
132  KyUInt32 AddIntVertex(const Vec2i& position, KyFloat32 altitude);
133  KyUInt32 AddIntVertex(const Vec2i& position); // Do not forget to call ComputeAltitudeRange() once the altitude has been set for each vertex
134  // for legacy. Create a vertex a position but without pixel pos.
135  KyUInt32 AddVertex3f(const Vec3f& position);
136 
137  KyUInt32 AddTriangle(KyUInt32 idxV1, KyUInt32 idxV2, KyUInt32 idxV3);
138  KyUInt32 AddHalfEdge(KyUInt32 start, KyUInt32 end, KyUInt32 face, DynamicNavHalfEdgeType type = DynamicNavHalfEdgeType_Normal);
139  KyResult MakeEdgesOpposite(KyUInt32 idxEdge1, KyUInt32 idxEdge2);
140 
141  // ---- Edge -----
142  KyUInt32 GetNextEdgeIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_next; }
143  KyUInt32 GetPrevEdgeIdx(KyUInt32 edgeIdx) const { return GetNextEdgeIdx(GetNextEdgeIdx(edgeIdx)); }
144  KyUInt32 GetOppositeEdgeIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_pair; }
145  KyUInt32 GetStartVertexIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_start; }
146  KyUInt32 GetFaceIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_face; }
147 
148  // ---- Face -----
149  KyUInt32 GetEdgeIdx(KyUInt32 triangleIdx) const { return m_triangles[triangleIdx].m_edge; }
150 
151  // ---- Vertex -----
152  KyUInt32 GetFirstEdgeIdx(KyUInt32 vertexIdx) const { return m_vertices[vertexIdx].m_first; }
153 
154  const DynamicNavVertex& GetNavVertex(KyUInt32 vertexIdx) const { return m_vertices[vertexIdx]; }
155 
156  KyUInt32 ComputeNextBorderEdgeIdx(KyUInt32 edgeIdx) const;
157  KyUInt32 GetNumberOfFloorBoundaryEdges() const;
158 
159  bool AreIndexesWithinBounds() const;
160  // search m_navTagArray for Navtag.
161  // If this particular navtag is not present, It will be added.
162  // returns the index in m_navTagArray where tag was found or added.
163  KyUInt32 FindOrAddNavtag(const NavTag* tag);
164 
165  void ComputeAltitudeRange();
166 
167 public:
168  KyUInt32 m_idx;
169 
170  KyArrayDH<DynamicNavTriangle> m_triangles;
171  KyArrayDH_POD<DynamicNavVertex> m_vertices;
172  KyArrayDH_POD<DynamicNavHalfEdge> m_edges;
173  KyArrayDH_POD<KyUInt32> m_navTagIndexes;
174  KyArrayDH_POD<const NavTag*> m_navTagArray;
175 
176  FloorAltitudeRange m_altitudeRange;
177 };
178 
179 KY_INLINE DynamicNavFloor::DynamicNavFloor() :
180  m_idx(KyUInt32MAXVAL),
181  m_triangles(KY_NULL),
182  m_vertices(KY_NULL),
183  m_edges(KY_NULL),
184  m_navTagIndexes(KY_NULL),
185  m_navTagArray(KY_NULL)
186 {
187  Clear();
188 }
189 
190 KY_INLINE DynamicNavFloor::DynamicNavFloor(MemoryHeap* memoryHeap) :
191  m_idx(KyUInt32MAXVAL),
192  m_triangles(memoryHeap),
193  m_vertices(memoryHeap),
194  m_edges(memoryHeap),
195  m_navTagIndexes(memoryHeap),
196  m_navTagArray(memoryHeap)
197 {
198  Clear();
199 }
200 
201 KY_INLINE void DynamicNavFloor::Clear()
202 {
203  m_vertices.Clear();
204  m_triangles.Clear();
205  m_edges.Clear();
206  m_navTagIndexes.Clear();
207  m_navTagArray.Clear();
208  m_altitudeRange.Clear();
209 }
210 
211 } // namespace Kaim
212 
213 
214 #endif //Navigation_DynamicNavFloor_H
215 
#define KyFloat32MAXVAL
The maximum value that can be stored in the KyFloat32 variable type.
Definition: types.h:227
static const KyInt32 InvalidPixelCoord
Represents an invalidPixelCoord object.
Definition: navmeshtypes.h:30
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
#define KY_NULL
Null value.
Definition: types.h:247
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:23
static const CardinalDir CardinalDir_INVALID
Identifies an invalid cardinal direction.
Definition: cardinaldir.h:29
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43