Add pivot offset for rotations.
This commit is contained in:
@@ -78,9 +78,10 @@ namespace DaggerFramework.Rendering
|
||||
Raylib.DrawCircle((int)_position.X, (int)_position.Y, radius, DaggerColorToRaylibColor(color));
|
||||
}
|
||||
|
||||
public override void SetTransform(Vector2 position, float rotation)
|
||||
public override void SetTransform(Vector2 position, Vector2 offset, float rotation = 0)
|
||||
{
|
||||
_position = position;
|
||||
_offset = offset;
|
||||
_rotation = rotation;
|
||||
}
|
||||
|
||||
@@ -153,7 +154,7 @@ namespace DaggerFramework.Rendering
|
||||
y = _position.Y,
|
||||
width = size.X,
|
||||
height = size.Y
|
||||
}, Vector2.Zero, _rotation, DaggerColorToRaylibColor(color));
|
||||
}, _offset, _rotation, DaggerColorToRaylibColor(color));
|
||||
}
|
||||
|
||||
public override void DrawDebugText(string text, int fontSize, Color color)
|
||||
@@ -203,7 +204,7 @@ namespace DaggerFramework.Rendering
|
||||
|
||||
private List<Texture2D> _texturePool = new();
|
||||
private List<Raylib_cs.Font> _fontPool = new();
|
||||
private Vector2 _position;
|
||||
private Vector2 _position, _offset;
|
||||
private float _rotation;
|
||||
private Vector2 _windowSize;
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ namespace DaggerFramework.Rendering
|
||||
/// Sets transforms for the next draw operation.
|
||||
/// </summary>
|
||||
/// <param name="position">Global transform position.</param>
|
||||
/// <param name="offset">Local offset point around which shapes will rotate.</param>
|
||||
/// <param name="rotation">Rotation.</param>
|
||||
public abstract void SetTransform(Vector2 position, float rotation = 0.0f);
|
||||
public abstract void SetTransform(Vector2 position, Vector2 offset, float rotation = 0.0f);
|
||||
/// <summary>
|
||||
/// Sets the transform for the next draw operation.
|
||||
/// </summary>
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace DaggerFramework.Rendering
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetTransform(Vector2 position, float rotation = 0)
|
||||
public override void SetTransform(Vector2 position, Vector2 offset, float rotation = 0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,5 +5,6 @@ namespace DaggerFramework.SceneGraph
|
||||
public class Entity2d : Entity
|
||||
{
|
||||
public Vector2 Position { get; set; }
|
||||
public float Rotation { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user