-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathscene.cpp
96 lines (77 loc) · 2.47 KB
/
scene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "scene.h"
#include "agent.h"
#include "detour.h"
#include "filter.h"
#include <DetourTileCache.h>
namespace NavMeshScene {
Scene::Scene(bool bStatic)
: AOISceneType()
, mDetour(new Detour(bStatic, 16))
, mDefaultFilter(new Filter())
{
}
Scene::~Scene() {
}
int Scene::Load(const char* path) {
int retCode = mDetour->Load(path);
if (!retCode)
{
float* bmin = mDetour->GetBoundsMin();
float* bmax = mDetour->GetBoundsMax();
printf("bounds min:(%f, %f, %f)\n", bmin[0], bmin[1], bmin[2]);
printf("bounds max:(%f, %f, %f)\n", bmax[0], bmax[1], bmax[2]);
SetBounds(aoi::Rect(bmin[0], bmax[0], bmin[2], bmax[2]));
}
return retCode;
}
void Scene::Simulation(float delta) {
if (mDetour->GetTileCache()) {
mDetour->GetTileCache()->update(delta, mDetour->GetMesh());
}
for (auto it = mAgents.begin(); it != mAgents.end(); it++) {
auto &agent = it->second;
agent->Update(delta);
}
}
void Scene::AddAgent(uint64_t id, const std::shared_ptr<Agent>& agent) {
if (id && agent) {
agent->SetId(id);
mAgents[id] = agent;
agent->SetScene(this);
}
}
void Scene::RemoveAgent(uint64_t id) {
auto it = mAgents.find(id);
if (it != mAgents.end()) {
Remove(it->second.get());
mAgents.erase(it);
}
}
float* Scene::GetBoundsMin()
{
return mDetour->GetBoundsMin();
}
float* Scene::GetBoundsMax()
{
return mDetour->GetBoundsMax();
}
DynamicScene::DynamicScene(int heightMode)
: Scene(false)
{
mDetour->SetHeightMode(heightMode);
}
DynamicScene::~DynamicScene() {
}
unsigned int DynamicScene::AddCapsuleObstacle(const float pos[3], const float radius, const float height) {
return mDetour->AddCapsuleObstacle(pos, radius, height);
}
unsigned int DynamicScene::AddBoxObstacle(const float bmin[3], const float bmax[3]) {
return mDetour->AddBoxObstacle(bmin, bmax);
}
unsigned int DynamicScene::AddBoxObstacle(const float center[3], const float halfExtents[3], const float yRadians) {
return mDetour->AddBoxObstacle(center, halfExtents, yRadians);
}
void DynamicScene::RemoveObstacle(unsigned int obstacleId) {
mDetour->RemoveObstacle(obstacleId);
}
}