using Encompass;
using KavTest.Components;
using KavTest.Messages;
using Microsoft.Xna.Framework;

namespace KavTest.Engines
{
    [Reads(typeof(AngularVelocityComponent))]
    [Sends(typeof(LocalRotationMessage))]
    public class AngularVelocityEngine : Engine
    {
        public override void Update(double dt)
        {
            foreach (var entity in ReadEntities<AngularVelocityComponent>())
            {
                ref readonly var angularVelocityComponent = ref GetComponent<AngularVelocityComponent>(entity);
                var angularVelocity = angularVelocityComponent.AngularVelocity * (float)dt;

                SendMessage(new LocalRotationMessage(entity, Quaternion.CreateFromYawPitchRoll(angularVelocity.X, angularVelocity.Y, angularVelocity.Z)));
            }
        }
    }
}
