1
This commit is contained in:
parent
4500704f0f
commit
36f148af67
@ -46,6 +46,13 @@ float GlmHelper::Norm(const glm::vec3& v)
|
||||
return glm::length(v);
|
||||
}
|
||||
|
||||
float GlmHelper::Norm2D(const glm::vec3& v)
|
||||
{
|
||||
glm::vec3 v2 = v;
|
||||
v2.y = 0.0f;
|
||||
return glm::length(v2);
|
||||
}
|
||||
|
||||
bool GlmHelper::IsZero(const glm::vec3& v)
|
||||
{
|
||||
return fabs(v.x) < 0.00001f && fabs(v.y) < 0.00001f && fabs(v.z) < 0.00001f;
|
||||
|
@ -11,6 +11,7 @@ class GlmHelper
|
||||
static void RotateY(glm::vec3& v, float angle);
|
||||
static void Normalize(glm::vec3& v);
|
||||
static float Norm(const glm::vec3& v);
|
||||
static float Norm2D(const glm::vec3& v);
|
||||
static bool IsZero(const glm::vec3& v);
|
||||
|
||||
static bool IsEqual2D(const glm::vec3& v1, const glm::vec3& v2);
|
||||
|
@ -608,11 +608,30 @@ int Room::CreateLootEx(int equip_id, const glm::vec3& born_pos, const glm::vec3&
|
||||
{
|
||||
glm::vec3 real_pos = pos;
|
||||
if (!no_adjust) {
|
||||
real_pos = born_pos;
|
||||
glm::vec3 dir = pos - born_pos;
|
||||
dir.y = 0;
|
||||
float distance = GlmHelper::Norm(dir);
|
||||
float distance = GlmHelper::Norm2D(dir);
|
||||
if (distance > 10) {
|
||||
|
||||
GlmHelper::Normalize(dir);
|
||||
glm::vec3 start = born_pos;
|
||||
map_instance->Scale(start);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
glm::vec3 end = born_pos + dir * distance;
|
||||
glm::vec3 hit_point;
|
||||
bool hit_result = false;
|
||||
map_instance->Scale(end);
|
||||
bool need_adjust = true;
|
||||
if (map_instance->Raycast(start, end, hit_point, hit_result)) {
|
||||
map_instance->UnScale(hit_point);
|
||||
if (GlmHelper::Norm2D(hit_point - born_pos) > 5) {
|
||||
real_pos = hit_point;
|
||||
need_adjust = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
GlmHelper::RotateY(dir, glm::radians(90.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
const mt::Equip* equip_meta = mt::Equip::GetById(equip_id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user