From f6f78eccbbdedc1bab4ae492cfd57888dbe01278 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 4 Dec 2020 18:52:20 -0800 Subject: [PATCH] different billboarding types --- Kav | 2 +- KavTest/Components/SpriteComponent.cs | 13 +++++++++++-- KavTest/Engines/Spawners/BillboardSpriteSpawner.cs | 8 ++++++-- KavTest/KavTestGame.cs | 5 +++-- KavTest/Messages/BillboardSpriteSpawnMessage.cs | 6 +++++- KavTest/Renderers/SceneRenderer.cs | 7 +++---- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Kav b/Kav index 665ff6d..ae445d9 160000 --- a/Kav +++ b/Kav @@ -1 +1 @@ -Subproject commit 665ff6dd44ac12b7e73e6d9c1998db4797d668a4 +Subproject commit ae445d94d3ad642cbda297ab97349f6f53090151 diff --git a/KavTest/Components/SpriteComponent.cs b/KavTest/Components/SpriteComponent.cs index b444b3a..bc0e419 100644 --- a/KavTest/Components/SpriteComponent.cs +++ b/KavTest/Components/SpriteComponent.cs @@ -1,4 +1,5 @@ using Encompass; +using Kav; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -8,11 +9,19 @@ namespace KavTest { public Texture2D Texture { get; } public Vector2 Origin { get; } + public float Rotation { get; } + public SpriteBillboardConstraint BillboardConstraint { get; } - public SpriteComponent(Texture2D texture, Vector2 origin) - { + public SpriteComponent( + Texture2D texture, + Vector2 origin, + float rotation, + SpriteBillboardConstraint billboardConstraint + ) { Texture = texture; Origin = origin; + Rotation = rotation; + BillboardConstraint = billboardConstraint; } } } diff --git a/KavTest/Engines/Spawners/BillboardSpriteSpawner.cs b/KavTest/Engines/Spawners/BillboardSpriteSpawner.cs index a6a47d4..449adc8 100644 --- a/KavTest/Engines/Spawners/BillboardSpriteSpawner.cs +++ b/KavTest/Engines/Spawners/BillboardSpriteSpawner.cs @@ -18,8 +18,12 @@ namespace KavTest.Spawners ); AddComponent(entity, new Transform3DComponent(transform)); - AddComponent(entity, new SpriteComponent(message.Texture, message.Origin)); - AddComponent(entity, new AngularVelocityComponent(new Vector3(2f, 0, 0))); + AddComponent(entity, new SpriteComponent( + message.Texture, + message.Origin, + message.Rotation, + message.BillboardConstraint + )); } } } diff --git a/KavTest/KavTestGame.cs b/KavTest/KavTestGame.cs index 3ae3145..488c7ab 100644 --- a/KavTest/KavTestGame.cs +++ b/KavTest/KavTestGame.cs @@ -247,8 +247,9 @@ namespace KavTest WorldBuilder.SendMessage(new BillboardSpriteSpawnMessage( mushroomGuyTexture, new Vector3(3, 1, 10), - 0, - Vector2.One + 1f, + Vector2.One, + Kav.SpriteBillboardConstraint.Horizontal )); // WorldBuilder.SendMessage(new StaticModelSpawnMessage( diff --git a/KavTest/Messages/BillboardSpriteSpawnMessage.cs b/KavTest/Messages/BillboardSpriteSpawnMessage.cs index cf3574a..ef396f9 100644 --- a/KavTest/Messages/BillboardSpriteSpawnMessage.cs +++ b/KavTest/Messages/BillboardSpriteSpawnMessage.cs @@ -1,4 +1,5 @@ using Encompass; +using Kav; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -11,18 +12,21 @@ namespace KavTest.Messages public Vector2 Origin { get; } public float Rotation { get; } public Vector2 Scale { get; } + public SpriteBillboardConstraint BillboardConstraint { get; } public BillboardSpriteSpawnMessage( Texture2D texture, Vector3 position, float rotation, - Vector2 scale + Vector2 scale, + SpriteBillboardConstraint billboardConstraint ) { Texture = texture; Origin = new Vector2(texture.Width / 2, texture.Height / 2); Position = position; Rotation = rotation; Scale = scale; + BillboardConstraint = billboardConstraint; } } } diff --git a/KavTest/Renderers/SceneRenderer.cs b/KavTest/Renderers/SceneRenderer.cs index 1f9c547..1f7be7c 100644 --- a/KavTest/Renderers/SceneRenderer.cs +++ b/KavTest/Renderers/SceneRenderer.cs @@ -98,17 +98,16 @@ namespace KavTest.Renderers var transformComponent = GetComponent(entity); var spriteComponent = GetComponent(entity); - var angles = transformComponent.Transform.Orientation.EulerAngles(); - yield return new Sprite( spriteComponent.Texture, transformComponent.Transform.Position, spriteComponent.Origin, - angles.X, + spriteComponent.Rotation, new Vector2( transformComponent.Transform.Scale.X, transformComponent.Transform.Scale.Y - ) + ), + spriteComponent.BillboardConstraint ); } }