修正地图问题

This commit is contained in:
aozhiwei 2023-04-10 13:39:57 +08:00
parent 18fccc5fd6
commit 95d4c99416
4 changed files with 104 additions and 6 deletions

View File

@ -155,8 +155,19 @@ namespace mc
dirs.push_back(glm::vec3(-extends.x, -extends.y, -extends.z));
dirs.push_back(glm::vec3(-extends.x, -extends.y, extends.z));
for (const glm::vec3& dir : dirs) {
points.push_back(center + dir);
points.push_back(center + quat * dir);
}
}
std::string ColliderNode::GetPath()
{
std::string path = name;
ColliderNode* node = this;
while (node && node->parent) {
path = node->parent->name + "/" + path;
node = node->parent;
}
return path;
}
}

View File

@ -104,6 +104,7 @@ namespace mc
std::map<std::string, ColliderNode*> childs;
void Read(std::shared_ptr<a8::XObject> xobj);
std::string GetPath();
};
void RotateBounds(const glm::vec3& center,

View File

@ -1079,10 +1079,10 @@ bool MapInstance::SceneRaycast(const glm::vec3& orig,
} while (!end);
if (result) {
#ifdef DEBUG1
#ifdef DEBUG
if (DebugCmd::Enable()) {
a8::XPrintf("nearest_node:%s tri_count:%d nearest_distance:%f\n",
{nearest_node->tri->node->name,
{nearest_node->tri->node->GetPath(),
tri_count,
nearest_distance});
}

View File

@ -83,6 +83,11 @@ bool MapService::CanAdd(const glm::vec3& pos, int rad)
void MapService::AddTriangle(mc::Triangle* tri)
{
#if 0
if (tri->node->name == "water03") {
return;
}
#endif
glm::vec3* verts[3] = {&tri->vert0, &tri->vert1, &tri->vert2};
float min_x = verts[0]->x;
float max_x = verts[0]->x;
@ -107,6 +112,9 @@ void MapService::AddTriangle(mc::Triangle* tri)
max_x += 1.0f;
min_y -= 1.0f;
max_y += 1.0f;
min_x = std::max(min_x, 0.0f);
min_y = std::max(min_y, 0.0f);
}
{
@ -114,22 +122,81 @@ void MapService::AddTriangle(mc::Triangle* tri)
int min_grid_y = floor(min_y / cell_width_);
int max_grid_x = ceil(max_x / cell_width_);
int max_grid_y = ceil(max_y / cell_width_);
#if 1
if (min_grid_x < 0) {
a8::XPrintf("error1 name:%s tri:%f,%f,%f %f,%f,%f\n",
{
tri->node->GetPath(),
tri->vert0.x,
tri->vert0.y,
tri->vert0.z,
tri->vert1.x,
tri->vert1.y,
tri->vert1.z,
tri->vert2.x,
tri->vert2.y,
tri->vert2.z,
}
);
return;
min_grid_x = 0;
}
#endif
if (min_grid_x < 0) {
A8_ABORT();
}
if (max_grid_x >= map_width_) {
#if 1
a8::XPrintf("error4 name:%s tri:%f,%f,%f %f,%f,%f\n",
{
tri->node->GetPath(),
tri->vert0.x,
tri->vert0.y,
tri->vert0.z,
tri->vert1.x,
tri->vert1.y,
tri->vert1.z,
tri->vert2.x,
tri->vert2.y,
tri->vert2.z,
}
);
#endif
return;
A8_ABORT();
max_grid_x = map_width_ - 1;
}
#if 1
if (min_grid_y < 0) {
a8::XPrintf("error2 name:%s tri:%f,%f,%f %f,%f,%f\n",
{
tri->node->GetPath(),
tri->vert0.x,
tri->vert0.y,
tri->vert0.z,
tri->vert1.x,
tri->vert1.y,
tri->vert1.z,
tri->vert2.x,
tri->vert2.y,
tri->vert2.z,
}
);
return;
min_grid_y = 0;
}
#endif
if (min_grid_y < 0) {
A8_ABORT();
//A8_ABORT();
}
if (max_grid_y >= map_height_) {
A8_ABORT();
max_grid_y = map_height_ - 1;
}
float tri_verts[3 * 3];
@ -190,7 +257,7 @@ void MapService::AddTriangle(mc::Triangle* tri)
found = true;
}
}
#if 0
#if 1
if (dtOverlapPolyPoly2D(tri_verts, 3, aabb_verts, 4)) {
int grid_id = x + y * map_width_;
list_head* head = &map_cells_[grid_id];
@ -202,9 +269,28 @@ void MapService::AddTriangle(mc::Triangle* tri)
#endif
}
}
#if 0
#if 1
if (!found) {
a8::XPrintf("error3 name:%s tri:%f,%f,%f %f,%f,%f\n",
{
tri->node->GetPath(),
tri->vert0.x,
tri->vert0.y,
tri->vert0.z,
tri->vert1.x,
tri->vert1.y,
tri->vert1.z,
tri->vert2.x,
tri->vert2.y,
tri->vert2.z,
}
);
#if 0
AddTriangle(tri);
abort();
#endif
}
#endif
}