mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 18:09:18 +02:00
WIP
This commit is contained in:
33
entitysystem/systems/LODSystem.cpp
Normal file
33
entitysystem/systems/LODSystem.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user