1
This commit is contained in:
parent
89e9679631
commit
c4fb2256bd
@ -162,9 +162,33 @@ void MapService::AddTriangle(mc::Triangle* tri)
|
|||||||
aabb_verts[11] = world_y + cell_width_;
|
aabb_verts[11] = world_y + cell_width_;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
glm::vec3 a[3 * 2];
|
glm::vec3 t1[3] = {tri->vert0, tri->vert1, tri->vert2};
|
||||||
a[0] = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
|
glm::vec3 tmp_verts[4];
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
tmp_verts[i] = glm::vec3(aabb_verts[i * 3 + 0],
|
||||||
|
aabb_verts[i * 3 + 1],
|
||||||
|
aabb_verts[i * 3 + 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 t2[3] = {
|
||||||
|
tmp_verts[0],
|
||||||
|
tmp_verts[1],
|
||||||
|
tmp_verts[2]};
|
||||||
|
|
||||||
|
glm::vec3 t3[3] = {
|
||||||
|
tmp_verts[0],
|
||||||
|
tmp_verts[2],
|
||||||
|
tmp_verts[3]};
|
||||||
|
|
||||||
|
if (TriIntersect(t1, t2) || TriIntersect(t1, t3)) {
|
||||||
|
int grid_id = x + y * map_width_;
|
||||||
|
list_head* head = &map_cells_[grid_id];
|
||||||
|
CellNode* node = new CellNode();
|
||||||
|
node->tri = tri;
|
||||||
|
list_add_tail(&node->entry, head);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (dtOverlapPolyPoly2D(tri_verts, 3, aabb_verts, 4)) {
|
if (dtOverlapPolyPoly2D(tri_verts, 3, aabb_verts, 4)) {
|
||||||
@ -178,9 +202,11 @@ void MapService::AddTriangle(mc::Triangle* tri)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
if (!found) {
|
if (!found) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,8 +230,13 @@ void MapService::GetGridList(int grid_id, list_head* grid_list[9], int& grid_cou
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapService::TriIntersect(const glm::vec3 t1[3], const glm::vec3 t2[3])
|
bool MapService::TriIntersect(glm::vec3 t1[3], glm::vec3 t2[3])
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
t1[i].y = 0.0f;
|
||||||
|
t2[i].y = 0.0f;
|
||||||
|
}
|
||||||
glm::vec2 bary_position;
|
glm::vec2 bary_position;
|
||||||
float distance;
|
float distance;
|
||||||
for (int v = 0; v < 3; ++v) {
|
for (int v = 0; v < 3; ++v) {
|
||||||
|
@ -27,7 +27,7 @@ class MapService
|
|||||||
void AddTriangle(mc::Triangle* tri);
|
void AddTriangle(mc::Triangle* tri);
|
||||||
int GetGridId(float world_x, float world_y);
|
int GetGridId(float world_x, float world_y);
|
||||||
void GetGridList(int grid_id, list_head* grid_list[9], int& grid_count);
|
void GetGridList(int grid_id, list_head* grid_list[9], int& grid_count);
|
||||||
bool TriIntersect(const glm::vec3 t1[3], const glm::vec3 t2[3]);
|
bool TriIntersect(glm::vec3 t1[3], glm::vec3 t2[3]);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
list_head* map_cells_ = nullptr;
|
list_head* map_cells_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user