gwnavruntime/collision/collisionworld.h Source File

collisionworld.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
14 
15 namespace Kaim
16 {
17 
18 class ColCellPosInfo
19 {
20 public:
21  Collection<Ptr<CollisionData> > m_colDatas;
22 };
23 
29 
30 class CollisionWorld : public RefCountBaseV<CollisionWorld, MemStat_WorldFwk>
31 {
33 public:
34  CollisionWorld() : m_cellSize(100.f), m_invCellSize(1.f / m_cellSize), m_bufferOfColCellPosInfo(nullptr), m_sizeOfCellBuffer(0) {}
35  ~CollisionWorld() { Clear(); }
36 
37  void RemoveAllCollisionData();
38  void Clear();
39 
40  void SetCollisionInterface(Ptr<ICollisionInterface> visInterface) { m_collisionInterface = visInterface; }
41 
42  void AddCollisionData(Ptr<CollisionData> colData);
43  void RemoveCollisionData(Ptr<CollisionData> colData);
44 
45  CollisionRayCastResult RayCast(const Vec3f& a, const Vec3f& b) const;
46 
47  bool IsWorldEmpty() const { return m_colData.GetCount() == 0; }
48 
49 private:
50  void GetIntersectingHeightFields(const Vec3f& a, const Vec3f& b, KyArray<CollisionData*>& results) const;
51  void EnlargeGrid(const CellBox& oldCellBox);
52 
53  KyResult GetStartCellFromRay(const Vec3f& a, const Vec3f& b, CellPos& startCellPos) const;
54 
55  KY_INLINE CellPos GetCellPosFromVec2f_Floor(const Vec2f& pos) const
56  {
57  return CellPos((KyInt32)floorf(pos.x * m_invCellSize), (KyInt32)floorf(pos.y * m_invCellSize));
58  }
59 
60  KY_INLINE CellPos GetCellPosFromVec2f_Ceil(const Vec2f& pos) const
61  {
62  return CellPos((KyInt32)ceilf(pos.x * m_invCellSize), (KyInt32)ceilf(pos.y * m_invCellSize));
63  }
64 
65  KY_INLINE CellPos GetCellPosFromVec2f(const Vec2f& pos) const
66  {
67  return CellPos((KyInt32)(pos.x * m_invCellSize), (KyInt32)(pos.y * m_invCellSize));
68  }
69 
70  KY_INLINE CellBox GetCellBoxFromBox2f(const Box2f& box2F) const
71  {
72  const CellPos cellPosMin = GetCellPosFromVec2f_Floor(box2F.m_min);
73  const CellPos cellPosMax = GetCellPosFromVec2f_Ceil(box2F.m_max);
74  return CellBox(cellPosMin, cellPosMax);
75  }
76 
77  KY_INLINE Vec2f GetPosFromCellPos(const CellPos& cellPos) const
78  {
79  return Vec2f(cellPos.x * m_cellSize, cellPos.y * m_cellSize);
80  }
81 
82  KY_INLINE Box2f GetAABB2D() const
83  {
84  return Box2f(GetPosFromCellPos(m_cellBox.m_min), GetPosFromCellPos(m_cellBox.m_max));
85  }
86 
87  TrackedCollection<Ptr<CollisionData>, MemStat_WorldFwk> m_colData;
88  Ptr<ICollisionInterface> m_collisionInterface;
89 
90  CellBox m_cellBox;
91  KyFloat32 m_cellSize;
92  KyFloat32 m_invCellSize;
93  ColCellPosInfo* m_bufferOfColCellPosInfo;
94  KyUInt32 m_sizeOfCellBuffer;
95 };
96 
97 }
98 
2d axis aligned box of 32bits floating points
Definition: box2f.h:15
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:162
TrackedCollection is a class which is a "Collection" of T=C* or T = Ptr< c="" /> (not sorted...
Definition: collection.h:77
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
2d vector using KyFloat32.
Definition: vec2f.h:18
Navigation return code class.
Definition: types.h:108
2d vector using KyInt32
Definition: vec2i.h:18
CollisionRayCastResult
CollisionRayCastResult.
Definition: collisiontypes.h:15
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
This class is a runtime container for all CollisionData that represents the world.
Definition: collisionworld.h:30
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16