16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 01:59:19 +02:00
Files
maszyna/entitysystem/systems/LODSystem.cpp
2026-05-24 21:48:05 +02:00

34 lines
1.1 KiB
C++

#include "stdafx.h"
#include "LODSystem.h"
#include "entitysystem/ECWorld.h"
#include "entitysystem/components/BasicComponents.h"
#include "entitysystem/components/RenderComponents.h"
#include "utilities/Globals.h"
#include "model/AnimModel.h"
void LODSystem::Update(ECWorld& world, float dt)
{
const glm::dvec3 camPos{
Global.pCamera.Pos.x,
Global.pCamera.Pos.y,
Global.pCamera.Pos.z
};
world.Each<ECSComponent::LODController, ECSComponent::Transform>(
entt::exclude<ECSComponent::Disabled>,
[&](entt::entity entity,
ECSComponent::LODController& lod,
ECSComponent::Transform& transform)
{
double dist = glm::length(camPos - transform.Position);
bool inRange = (dist >= lod.RangeMin) && (dist <= lod.RangeMax);
if (auto* mesh = world.GetComponent<ECSComponent::MeshRenderer>(entity)) {
mesh->visible = inRange;
if (mesh->modelInstance)
mesh->modelInstance->visible(inRange);
}
});
}