일단 충돌 구현...?
This commit is contained in:
@@ -5,37 +5,27 @@
|
||||
|
||||
namespace veng {
|
||||
void Physics::invokeOnColisionEvent(
|
||||
gsl::not_null<utils::ThreadPool*> thread_pool, std::vector<std::shared_ptr<Model>> models) {
|
||||
gsl::not_null<utils::ThreadPool*> thread_pool,
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>>& models) {
|
||||
constexpr std::float_t EPSILON = std::numeric_limits<std::float_t>::epsilon();
|
||||
|
||||
for (int first = 0; first < models.size(); first++) {
|
||||
auto first_model = models[first];
|
||||
if (first_model != nullptr || !first_model->colision) continue;
|
||||
for (int second = first + 1; second < models.size(); second++) {
|
||||
auto second_model = models[second];
|
||||
if (second_model != nullptr || !second_model->colision) continue;
|
||||
for (std::unordered_map<std::string, std::shared_ptr<Model>>::iterator
|
||||
iter_A = models.begin();
|
||||
iter_A != models.end(); iter_A++) {
|
||||
auto model_A = iter_A->second;
|
||||
if (!model_A->colision) continue;
|
||||
for (auto iter_B = std::next(iter_A); iter_B != models.end(); iter_B++) {
|
||||
auto model_B = iter_B->second;
|
||||
if (!model_B->colision) continue;
|
||||
std::float_t distance =
|
||||
glm::distance(first_model->position, second_model->position);
|
||||
std::float_t model1_radius = first_model->radius * first_model->scale.x;
|
||||
std::float_t model2_radius = second_model->radius * second_model->scale.x;
|
||||
if (distance <= model1_radius + model2_radius) {
|
||||
if (first_model->OnColision != nullptr)
|
||||
thread_pool->enqueueJob(
|
||||
[OnColision = first_model->OnColision](
|
||||
utils::ThreadPool* thread_pool, std::shared_ptr<Model> self,
|
||||
std::shared_ptr<Model> other) {
|
||||
OnColision(self, other);
|
||||
},
|
||||
first_model, second_model);
|
||||
if (second_model->OnColision != nullptr)
|
||||
thread_pool->enqueueJob(
|
||||
[OnColision = second_model->OnColision](
|
||||
utils::ThreadPool* thread_pool, std::shared_ptr<Model> self,
|
||||
std::shared_ptr<Model> other) {
|
||||
OnColision(self, other);
|
||||
},
|
||||
first_model, second_model);
|
||||
break;
|
||||
glm::distance(model_A->position, model_B->position);
|
||||
std::float_t modelA_radius = model_A->radius * model_A->scale.x;
|
||||
std::float_t modelB_radius = model_B->radius * model_B->scale.x;
|
||||
if (distance <= modelA_radius + modelB_radius) {
|
||||
if (model_A->OnColision)
|
||||
thread_pool->enqueueJob(model_A->OnColision, model_A, model_B);
|
||||
if (model_B->OnColision)
|
||||
thread_pool->enqueueJob(model_B->OnColision, model_A, model_B);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user