pull/1/head
Evan Hemsley 2020-08-05 13:57:15 -07:00
parent f966da5b93
commit 7556ebd84c
4 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,15 @@
using Encompass;
using Microsoft.Xna.Framework;
namespace KavTest.Components
{
public struct AngularVelocityComponent : IComponent
{
public Vector3 AngularVelocity { get; }
public AngularVelocityComponent(Vector3 angularVelocity)
{
AngularVelocity = angularVelocity;
}
}
}

View File

@ -0,0 +1,29 @@
using Encompass;
using KavTest.Components;
using Microsoft.Xna.Framework;
namespace KavTest.Engines
{
[Reads(typeof(TransformComponent), typeof(AngularVelocityComponent))]
[Writes(typeof(TransformComponent))]
public class RotationEngine : Engine
{
public override void Update(double dt)
{
foreach (var entity in ReadEntities<AngularVelocityComponent>())
{
if (HasComponent<TransformComponent>(entity))
{
ref readonly var angularVelocityComponent = ref GetComponent<AngularVelocityComponent>(entity);
ref readonly var transformComponent = ref GetComponent<TransformComponent>(entity);
var angularVelocity = angularVelocityComponent.AngularVelocity * (float)dt;
var transform = transformComponent.Transform;
var newTransform = Matrix.Transform(transform, Quaternion.CreateFromYawPitchRoll(angularVelocity.X, angularVelocity.Y, angularVelocity.Z));
SetComponent(entity, new TransformComponent(newTransform));
}
}
}
}
}

View File

@ -20,6 +20,7 @@ namespace KavTest.Spawners
AddComponent(entity, new TransformComponent(message.Transform));
AddComponent(entity, new ModelComponent(RustyBallModel));
AddComponent(entity, new AngularVelocityComponent(new Microsoft.Xna.Framework.Vector3(5, -2, 1)));
}
}
}

View File

@ -1,6 +1,7 @@
using System.IO;
using Encompass;
using KavTest.Components;
using KavTest.Engines;
using KavTest.Messages;
using KavTest.Renderers;
using KavTest.Spawners;
@ -35,6 +36,7 @@ namespace KavTest
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/cube.glb"))
);
WorldBuilder.AddEngine(new RotationEngine());
WorldBuilder.AddEngine(new RustyBallSpawner(rustyBallModel));
WorldBuilder.AddEngine(new LightBulbSpawner());
WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0);