spinning
							parent
							
								
									f966da5b93
								
							
						
					
					
						commit
						7556ebd84c
					
				|  | @ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -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)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -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))); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue