From 6e1c8c755832de5788570bf156a2b7dad469b5b3 Mon Sep 17 00:00:00 2001 From: Maddy Thorson Date: Mon, 8 Feb 2021 22:43:25 -0800 Subject: [PATCH] Image scale/rotation works --- src/Components/Drawing/Image.bf | 4 ++-- src/PlatformLayer/Batcher.bf | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Components/Drawing/Image.bf b/src/Components/Drawing/Image.bf index 4749d0a..91ce458 100644 --- a/src/Components/Drawing/Image.bf +++ b/src/Components/Drawing/Image.bf @@ -15,12 +15,12 @@ namespace Strawberry Offset = offset; } - public Point DrawPosition => Entity.Position + Offset - Origin; + public Point DrawPosition => Entity.Position + Offset; public void Draw() { if (Texture != null) - Game.Batcher.Tex(Texture, DrawPosition); + Game.Batcher.Tex(Texture, DrawPosition, Origin, Scale, Rotation); } } } diff --git a/src/PlatformLayer/Batcher.bf b/src/PlatformLayer/Batcher.bf index 1185a8b..920e094 100644 --- a/src/PlatformLayer/Batcher.bf +++ b/src/PlatformLayer/Batcher.bf @@ -102,12 +102,16 @@ namespace Strawberry public void Tex(Texture texture, Vector pos, Vector origin, Vector scale, float rotation) { - //TODO! + Mat3x2 mat = Mat3x2.CreateTranslation(-origin) + * Mat3x2.CreateScale(scale) + * Mat3x2.CreateRotation(rotation) + * Mat3x2.CreateTranslation(pos); + PushQuad(.TextureTint, texture, - .Tex(.(pos.X, pos.Y), .(0, 0), Color.White), - .Tex(.(pos.X + texture.Width, pos.Y), .(1, 0), Color.White), - .Tex(.(pos.X + texture.Width, pos.Y + texture.Height), .(1, 1), Color.White), - .Tex(.(pos.X, pos.Y + texture.Height), .(0, 1), Color.White)); + .Tex(.(0, 0) * mat, .(0, 0), Color.White), + .Tex(.(texture.Width, 0) * mat, .(1, 0), Color.White), + .Tex(.(texture.Width, texture.Height) * mat, .(1, 1), Color.White), + .Tex(.(0, texture.Height) * mat, .(0, 1), Color.White)); } } }