Add pivot offset for rotations.

This commit is contained in:
2023-09-25 18:44:35 +02:00
parent ea2733f594
commit 8aab1132b6
8 changed files with 27 additions and 17 deletions

View File

@@ -1,12 +1,14 @@
using System.Numerics;
using DaggerFramework.Rendering;
namespace DaggerFramework.SceneGraph
{
public abstract class Drawable2d : Entity2d, IDrawable
{
public Vector2 PivotOffset { get; set; }
public void Draw(Renderer renderer)
{
renderer.SetTransform(Position);
renderer.SetTransform(Position, PivotOffset, Rotation);
OnDraw(renderer);
}

View File

@@ -5,5 +5,6 @@ namespace DaggerFramework.SceneGraph
public class Entity2d : Entity
{
public Vector2 Position { get; set; }
public float Rotation { get; set; }
}
}

View File

@@ -31,7 +31,7 @@ namespace DaggerFramework.SceneGraph
var scale = MathUtils.Lerp(_settings.ScaleEnd, _settings.ScaleBegin, t);
var color = MathUtils.LerpColor(_settings.ColorEnd, _settings.ColorBegin, t);
renderer.SetTransform(particle.Position, particle.Rotation);
renderer.SetTransform(particle.Position, Vector2.Zero, particle.Rotation);
renderer.DrawRectangle(Vector2.One * scale, color);
}
}

View File

@@ -9,6 +9,7 @@ public class RectangleShape2d : Drawable2d
public Color Color { get; set; } = Color.White;
public override void OnDraw(Renderer renderer)
{
PivotOffset = Size / 2;
renderer.DrawRectangle(Size, Color);
}
}