1
This commit is contained in:
parent
1d2b4a86f3
commit
5df93c0fc5
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <f8/udplog.h>
|
#include <f8/udplog.h>
|
||||||
|
|
||||||
|
#include <glm/gtx/intersect.hpp>
|
||||||
|
|
||||||
#include "DetourCommon.h"
|
#include "DetourCommon.h"
|
||||||
|
|
||||||
#include "mapinstance.h"
|
#include "mapinstance.h"
|
||||||
@ -16,6 +18,8 @@
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "entityfactory.h"
|
#include "entityfactory.h"
|
||||||
#include "creature.h"
|
#include "creature.h"
|
||||||
|
#include "glmhelper.h"
|
||||||
|
|
||||||
#include "mt/MetaMgr.h"
|
#include "mt/MetaMgr.h"
|
||||||
#include "mt/Param.h"
|
#include "mt/Param.h"
|
||||||
#include "mt/Map.h"
|
#include "mt/Map.h"
|
||||||
@ -886,15 +890,18 @@ bool MapInstance::SceneRaycast(const glm::vec3& orig,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
float nearest_distance = 0.0f;
|
float nearest_distance = 0.0f;
|
||||||
|
CellNode* nearest_node = nullptr;
|
||||||
glm::vec3 nearest_pt(0.0f, 0.0f, 0.0f);
|
glm::vec3 nearest_pt(0.0f, 0.0f, 0.0f);
|
||||||
int raycast_index = MapMgr::Instance()->IncCurrRaycastIndex();
|
int raycast_index = MapMgr::Instance()->IncCurrRaycastIndex();
|
||||||
float len = 0.0f;
|
float len = 0.0f;
|
||||||
|
bool result = false;
|
||||||
|
bool end = false;
|
||||||
do {
|
do {
|
||||||
glm::vec3 curr_pos = orig + dir * len;
|
glm::vec3 curr_pos = orig + dir * len;
|
||||||
len += 5.0f;
|
|
||||||
if (len > max_distance) {
|
if (len > max_distance) {
|
||||||
len = max_distance;
|
len = max_distance;
|
||||||
curr_pos = orig + dir * len;
|
curr_pos = orig + dir * len;
|
||||||
|
end = true;
|
||||||
}
|
}
|
||||||
int grid_id = map_service_->GetGridId(curr_pos.x, curr_pos.z);
|
int grid_id = map_service_->GetGridId(curr_pos.x, curr_pos.z);
|
||||||
list_head* grid_list[9];
|
list_head* grid_list[9];
|
||||||
@ -908,8 +915,43 @@ bool MapInstance::SceneRaycast(const glm::vec3& orig,
|
|||||||
|
|
||||||
CellNode *node, *tmp;
|
CellNode *node, *tmp;
|
||||||
list_for_each_entry_safe(node, tmp, head, entry) {
|
list_for_each_entry_safe(node, tmp, head, entry) {
|
||||||
|
if (node->tri->check_flag != raycast_index) {
|
||||||
|
glm::vec3 pos;
|
||||||
|
bool hited = glm::intersectLineTriangle
|
||||||
|
(orig,
|
||||||
|
dir,
|
||||||
|
node->tri->vert0,
|
||||||
|
node->tri->vert1,
|
||||||
|
node->tri->vert2,
|
||||||
|
pos
|
||||||
|
);
|
||||||
|
node->tri->check_flag = raycast_index;
|
||||||
|
if (hited) {
|
||||||
|
float distance = GlmHelper::Norm(pos - orig);
|
||||||
|
if (nearest_node) {
|
||||||
|
if (distance <= len || nearest_distance <= len) {
|
||||||
|
result = true;
|
||||||
|
end = true;
|
||||||
|
}
|
||||||
|
if (distance < nearest_distance) {
|
||||||
|
nearest_node = node;
|
||||||
|
nearest_distance = distance;
|
||||||
|
nearest_pt = pos;
|
||||||
|
}
|
||||||
|
} else if (distance <= max_distance) {
|
||||||
|
nearest_node = node;
|
||||||
|
nearest_distance = distance;
|
||||||
|
nearest_pt = pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (true);
|
len += 5.0f;
|
||||||
return false;
|
} while (!end);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
hit_pos = nearest_pt;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user