-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move nav mesh generation code to its own class. Start creating the nav mesh structure.
- Loading branch information
Showing
8 changed files
with
492 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "NavMesh.h" | ||
#include "GLFW/glfw3.h" | ||
#include "PolyOctree.h" | ||
#include "Clipper.h" | ||
|
||
NavMesh::NavMesh() { | ||
clear(); | ||
} | ||
|
||
void NavMesh::clear() { | ||
memset(nodes, 0, sizeof(NavPolyNode) * MAX_NAV_POLYS); | ||
|
||
for (int i = 0; i < MAX_NAV_POLYS; i++) { | ||
polys[i] = Polygon3D(); | ||
} | ||
} | ||
|
||
NavMesh::NavMesh(vector<Polygon3D> faces) { | ||
clear(); | ||
|
||
for (int i = 0; i < faces.size(); i++) { | ||
polys[i] = faces[i]; | ||
if (faces[i].verts.size() > MAX_NAV_POLY_VERTS) | ||
logf("Error: Face %d has %d verts (max is %d)\n", i, faces[i].verts.size(), MAX_NAV_POLY_VERTS); | ||
} | ||
numPolys = faces.size(); | ||
|
||
logf("Created nav mesh with %d polys (x%d = %d KB)\n", | ||
numPolys, sizeof(NavPolyNode), (sizeof(NavPolyNode)*numPolys) / 1024); | ||
|
||
logf("NavPolyNode = %d bytes, NavLink = %d bytes\n", | ||
sizeof(NavPolyNode), sizeof(NavLink)); | ||
} | ||
|
||
vector<Polygon3D> NavMesh::getPolys() { | ||
vector<Polygon3D> ret; | ||
|
||
for (int i = 0; i < numPolys; i++) { | ||
ret.push_back(polys[i]); | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
#include "Polygon3D.h" | ||
#include "PolyOctree.h" | ||
#include <set> | ||
#include "Bsp.h" | ||
|
||
#define MAX_NAV_POLYS 8192 | ||
#define MAX_NAV_POLY_VERTS 12 | ||
#define MAX_EDGE_LINKS 8 | ||
|
||
struct NavLink { | ||
uint16_t node; // which poly is linked to. 0 = end of links | ||
int16_t zDist; // minimum height difference between the connecting edges | ||
}; | ||
|
||
struct NavPolyNode { | ||
NavLink edges[MAX_NAV_POLY_VERTS][MAX_EDGE_LINKS]; | ||
uint32_t flags; | ||
}; | ||
|
||
|
||
class NavMesh { | ||
public: | ||
NavPolyNode nodes[MAX_NAV_POLYS]; | ||
Polygon3D polys[MAX_NAV_POLYS]; | ||
|
||
int numPolys; | ||
|
||
NavMesh(); | ||
|
||
NavMesh(vector<Polygon3D> polys); | ||
|
||
void clear(); | ||
|
||
vector<Polygon3D> getPolys(); | ||
|
||
private: | ||
}; |
Oops, something went wrong.