This commit is contained in:
aozhiwei 2024-08-18 17:42:42 +08:00
parent 6cb4d307b5
commit 5065b63475

View File

@ -2,6 +2,7 @@
#include <random> #include <random>
#include <glm/glm.hpp>
#include <a8/mutable_xobject.h> #include <a8/mutable_xobject.h>
#include <f8/app.h> #include <f8/app.h>
@ -14,6 +15,7 @@
#include "httpproxy.h" #include "httpproxy.h"
#include "jsondatamgr.h" #include "jsondatamgr.h"
#include "player.h" #include "player.h"
#include "mapinstance.h"
#include "mt/MapMode.h" #include "mt/MapMode.h"
#include "mt/Hero.h" #include "mt/Hero.h"
@ -56,8 +58,35 @@ void BoxDrop::Drop(int num, const glm::vec3& center)
for (int i = 0; i < num; ++i) { for (int i = 0; i < num; ++i) {
glm::vec3 dir = GlmHelper::UP; glm::vec3 dir = GlmHelper::UP;
GlmHelper::RotateY(dir, a8::RandAngle()); GlmHelper::RotateY(dir, a8::RandAngle());
const glm::vec3 pos = center + dir * (25.0f + rand() % 50);
room_->CreateObstacle(BOX_ID, pos.x, pos.y, pos.z); glm::vec3 born_pos = center;
GlmHelper::Normalize(dir);
glm::vec3 start = born_pos;
room_->map_instance->Scale(start);
glm::vec3 real_pos = born_pos;
float distance = 25.0f + rand() % 50;
for (int i = 0; i < 4; ++i) {
glm::vec3 end = born_pos + dir * distance;
glm::vec3 hit_point;
bool hit_result = false;
room_->map_instance->Scale(end);
if (room_->map_instance->Raycast(start,
end,
hit_point,
hit_result,
room_->map_instance->GetMoveIncludeFlags(),
room_->map_instance->GetMoveExcludeFlags())) {
room_->map_instance->UnScale(hit_point);
if (GlmHelper::Norm2D(hit_point - born_pos) > 5) {
real_pos = hit_point;
break;
}
}
GlmHelper::RotateY(dir, glm::radians(90.0f));
}
room_->CreateObstacle(BOX_ID, real_pos.x, real_pos.y, real_pos.z);
} }
} }