mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 04:19:19 +02:00
WIP
This commit is contained in:
30
entitysystem/systems/VehicleSyncSystem.cpp
Normal file
30
entitysystem/systems/VehicleSyncSystem.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "stdafx.h"
|
||||
#include "VehicleSyncSystem.h"
|
||||
|
||||
#include "entitysystem/ECWorld.h"
|
||||
#include "entitysystem/components/BasicComponents.h"
|
||||
#include "vehicle/DynObj.h"
|
||||
|
||||
void VehicleSyncSystem::Update(ECWorld& world, float dt)
|
||||
{
|
||||
world.Each<ECSComponent::VehicleRef, ECSComponent::Transform>(
|
||||
entt::exclude<ECSComponent::Disabled>,
|
||||
[](entt::entity,
|
||||
ECSComponent::VehicleRef& ref,
|
||||
ECSComponent::Transform& transform)
|
||||
{
|
||||
if (!ref.vehicle) return;
|
||||
|
||||
auto const &pos = ref.vehicle->GetPosition();
|
||||
transform.Position = glm::dvec3(pos.x, pos.y, pos.z);
|
||||
|
||||
// Extract rotation from the vehicle's render matrix (column vectors = basis)
|
||||
auto const *m = ref.vehicle->mMatrix.getArray();
|
||||
// mMatrix is column-major 4x4; extract upper-left 3x3 into glm
|
||||
glm::mat3 rot(
|
||||
m[0], m[1], m[2],
|
||||
m[4], m[5], m[6],
|
||||
m[8], m[9], m[10]);
|
||||
transform.Rotation = glm::quat_cast(rot);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user