1
This commit is contained in:
parent
81457c38d8
commit
3f994216e1
@ -64,3 +64,10 @@ float GlmHelper::CalcAngle(const glm::vec3& v1, const glm::vec3& v2)
|
|||||||
#endif
|
#endif
|
||||||
return angle / 3.1415926f;
|
return angle / 3.1415926f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlmHelper::FillVert(const glm::vec3& v, float* vert)
|
||||||
|
{
|
||||||
|
vert[0] = v.x;
|
||||||
|
vert[1] = v.y;
|
||||||
|
vert[2] = v.z;
|
||||||
|
}
|
||||||
|
@ -15,4 +15,6 @@ class GlmHelper
|
|||||||
|
|
||||||
static float CalcAngle(const glm::vec3& v1, const glm::vec3& v2);
|
static float CalcAngle(const glm::vec3& v1, const glm::vec3& v2);
|
||||||
|
|
||||||
|
static void FillVert(const glm::vec3& v, float* vert);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
|
#include "DetourCommon.h"
|
||||||
|
|
||||||
#include "mapservice.h"
|
#include "mapservice.h"
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
#include "roomobstacle.h"
|
#include "roomobstacle.h"
|
||||||
@ -128,8 +130,35 @@ void MapService::AddTriangle(mc::Triangle* tri)
|
|||||||
if (max_grid_y >= map_height_) {
|
if (max_grid_y >= map_height_) {
|
||||||
max_grid_y = map_height_ - 1;
|
max_grid_y = map_height_ - 1;
|
||||||
}
|
}
|
||||||
|
float tri_verts[3 * 3];
|
||||||
|
float aabb_verts[3 * 4];
|
||||||
|
{
|
||||||
|
GlmHelper::FillVert(tri->vert0, tri_verts + 3 * 0);
|
||||||
|
GlmHelper::FillVert(tri->vert1, tri_verts + 3 * 1);
|
||||||
|
GlmHelper::FillVert(tri->vert2, tri_verts + 3 * 2);
|
||||||
|
}
|
||||||
for (int x = min_grid_x; x <= max_grid_x; ++x) {
|
for (int x = min_grid_x; x <= max_grid_x; ++x) {
|
||||||
for (int y = min_grid_y; y <= max_grid_y; ++y) {
|
for (int y = min_grid_y; y <= max_grid_y; ++y) {
|
||||||
|
float world_x = x * cell_width_;
|
||||||
|
float world_y = y * cell_width_;
|
||||||
|
{
|
||||||
|
aabb_verts[0] = world_x;
|
||||||
|
aabb_verts[1] = 0;
|
||||||
|
aabb_verts[2] = world_y;
|
||||||
|
|
||||||
|
aabb_verts[3] = world_x + cell_width_;
|
||||||
|
aabb_verts[4] = 0;
|
||||||
|
aabb_verts[5] = world_y;
|
||||||
|
|
||||||
|
aabb_verts[6] = world_x + cell_width_;
|
||||||
|
aabb_verts[7] = 0;
|
||||||
|
aabb_verts[8] = world_y + cell_width_;
|
||||||
|
|
||||||
|
aabb_verts[9] = world_x;
|
||||||
|
aabb_verts[10] = 0;
|
||||||
|
aabb_verts[11] = world_y + cell_width_;
|
||||||
|
}
|
||||||
|
if (dtOverlapPolyPoly2D(tri_verts, 3, aabb_verts, 4)) {
|
||||||
int grid_id = x + y * map_width_;
|
int grid_id = x + y * map_width_;
|
||||||
list_head* head = &map_cells_[grid_id];
|
list_head* head = &map_cells_[grid_id];
|
||||||
CellNode* node = new CellNode();
|
CellNode* node = new CellNode();
|
||||||
@ -139,6 +168,7 @@ void MapService::AddTriangle(mc::Triangle* tri)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int MapService::GetGridId(float world_x, float world_y)
|
int MapService::GetGridId(float world_x, float world_y)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user