worked on grid-walking

worked on grid-generation
added helper library for nav-meshes
started working on nav meshes
This commit is contained in:
2018-01-08 20:55:50 +01:00
parent c346b7f222
commit ca6fed5371
33 changed files with 12991 additions and 1913 deletions

49
navMesh/NavMeshRandom.h Normal file
View File

@@ -0,0 +1,49 @@
#ifndef NAVMESHRANDOM_H
#define NAVMESHRANDOM_H
#include <random>
#include <vector>
#include "../math/DrawList.h"
#include "../geo/Point3.h"
template <typename Tria> class NavMeshRandom {
std::minstd_rand gen;
std::uniform_real_distribution<float> dOnTriangle = std::uniform_real_distribution<float>(0.0f, 1.0f);
const std::vector<Tria>& triangles;
DrawList<size_t> lst;
public:
struct Result {
Point3 pos;
size_t triaIdx;
Result(const Point3 pos, const size_t triaIdx) : pos(pos), triaIdx(triaIdx) {;}
};
/** ctor */
NavMeshRandom(const std::vector<Tria>& triangles) : triangles(triangles) {
for (size_t idx = 0; idx < triangles.size(); ++idx) {
lst.add(idx, triangles[idx].getArea());
}
}
/** draw a random point within the map */
Result draw() {
const size_t idx = lst.get();
const Tria& tria = triangles[idx];
while (true) {
const float u = dOnTriangle(gen);
const float v = dOnTriangle(gen);
if (u+v > 1) {continue;}
const Point3 pos = tria.getA() + (tria.getAB() * u) + (tria.getAC() * v);
return Result(pos, idx);
}
}
};
#endif // NAVMESHRANDOM_H