gwnavruntime/collision/collisionworld.h Source File

collisionworld.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 // primary contact: JAPA - secondary contact: GUAL
8 #ifndef Navigation_CollisionWorld_H
9 #define Navigation_CollisionWorld_H
10 
16 
17 namespace Kaim
18 {
19 
20 class ColCellPosInfo
21 {
22 public:
23  Collection<Ptr<CollisionData> > m_colDatas;
24 };
25 
31 
32 class CollisionWorld : public RefCountBaseV<CollisionWorld, MemStat_WorldFwk>
33 {
34  KY_CLASS_WITHOUT_COPY(CollisionWorld)
35 public:
36  CollisionWorld() : m_cellSize(100.f), m_invCellSize(1.f / m_cellSize), m_bufferOfColCellPosInfo(KY_NULL), m_sizeOfCellBuffer(0) {}
37  ~CollisionWorld() { Clear(); }
38 
39  void RemoveAllCollisionData();
40  void Clear();
41 
42  void SetCollisionInterface(Ptr<ICollisionInterface> visInterface) { m_collisionInterface = visInterface; }
43 
44  void AddCollisionData(Ptr<CollisionData> colData);
45  void RemoveCollisionData(Ptr<CollisionData> colData);
46 
47  CollisionRayCastResult RayCast(const Vec3f& a, const Vec3f& b) const;
48 
49  bool IsWorldEmpty() const { return m_colData.GetCount() == 0; }
50 
51 private:
52  void GetIntersectingHeightFields(const Vec3f& a, const Vec3f& b, KyArray<CollisionData*>& results) const;
53  void EnlargeGrid(const CellBox& oldCellBox);
54 
55  KyResult GetStartCellFromRay(const Vec3f& a, const Vec3f& b, CellPos& startCellPos) const;
56 
57  KY_INLINE CellPos GetCellPosFromVec2f_Floor(const Vec2f& pos) const
58  {
59  return CellPos((KyInt32)floorf(pos.x * m_invCellSize), (KyInt32)floorf(pos.y * m_invCellSize));
60  }
61 
62  KY_INLINE CellPos GetCellPosFromVec2f_Ceil(const Vec2f& pos) const
63  {
64  return CellPos((KyInt32)ceilf(pos.x * m_invCellSize), (KyInt32)ceilf(pos.y * m_invCellSize));
65  }
66 
67  KY_INLINE CellPos GetCellPosFromVec2f(const Vec2f& pos) const
68  {
69  return CellPos((KyInt32)(pos.x * m_invCellSize), (KyInt32)(pos.y * m_invCellSize));
70  }
71 
72  KY_INLINE CellBox GetCellBoxFromBox2f(const Box2f& box2F) const
73  {
74  const CellPos cellPosMin = GetCellPosFromVec2f_Floor(box2F.m_min);
75  const CellPos cellPosMax = GetCellPosFromVec2f_Ceil(box2F.m_max);
76  return CellBox(cellPosMin, cellPosMax);
77  }
78 
79  KY_INLINE Vec2f GetPosFromCellPos(const CellPos& cellPos) const
80  {
81  return Vec2f(cellPos.x * m_cellSize, cellPos.y * m_cellSize);
82  }
83 
84  KY_INLINE Box2f GetAABB2D() const
85  {
86  return Box2f(GetPosFromCellPos(m_cellBox.m_min), GetPosFromCellPos(m_cellBox.m_max));
87  }
88 
89  TrackedCollection<Ptr<CollisionData>, MemStat_WorldFwk> m_colData;
90  Ptr<ICollisionInterface> m_collisionInterface;
91 
92  CellBox m_cellBox;
93  KyFloat32 m_cellSize;
94  KyFloat32 m_invCellSize;
95  ColCellPosInfo* m_bufferOfColCellPosInfo;
96  KyUInt32 m_sizeOfCellBuffer;
97 };
98 
99 }
100 
101 #endif // Navigation_CollisionWorld_H
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
This class is a runtime container for all CollisionData that represents the world.
Definition: collisionworld.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43