From 1de48570b220acc1ca7063e2a9cda1e89178c0f9 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 6 Jan 2023 10:26:43 -0500 Subject: bad shape positioning --- src/prenderer.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'src/prenderer.cpp') diff --git a/src/prenderer.cpp b/src/prenderer.cpp index 54b19cf..fc6edd4 100644 --- a/src/prenderer.cpp +++ b/src/prenderer.cpp @@ -1,3 +1,23 @@ +static v2 +T_CompPosToLayerPos(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, real32 X, real32 Y) +{ + real32 Rad = (T.rotation* (PI / 180)); + v2 XAxis = (SourceWidth * T.scale)*V2(cos(Rad), sin(Rad)); + v2 YAxis = (SourceHeight * -T.scale)*V2(sin(Rad), -cos(Rad)); + + v2 Pos = {T.x, T.y}; + v2 Origin = Pos - (XAxis * T.ax) - (YAxis * T.ay); + + v2 XAxisPerp = (1.0f / LengthSq(XAxis))*XAxis; + v2 YAxisPerp = (1.0f / LengthSq(YAxis))*YAxis; + + real32 StartVectorX = X - Origin.x; + real32 StartVectorY = Y - Origin.y; + real32 LayerU = (StartVectorX * XAxisPerp.x) + (StartVectorY * XAxisPerp.y); + real32 LayerV = (StartVectorX * YAxisPerp.x) + (StartVectorY * YAxisPerp.y); + return V2(LayerU * SourceWidth, LayerV * SourceHeight); +} + static v2 T_CompUVToLayerUV(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, v2 CompUV) { @@ -37,20 +57,6 @@ Transform_ScreenSpaceToLocal(layer_transforms T, uint32 FileWidth, uint32 FileHe return V2(LayerUV.x * SourceWidth, LayerUV.y * SourceHeight); } -static void -Layer_GetDimensions(memory *Memory, block_layer *Layer, int *Width, int *Height) -{ - if (!Layer->IsPrecomp) { - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - *Width = Source->Width; - *Height = Source->Height; - } else { - block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); - *Width = Comp->Width; - *Height = Comp->Height; - } -} - // Transform given data based on state's Interact data. static void Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32 *OutputY, real32 *OutputRotation, real32 *OutputScale) @@ -220,6 +226,7 @@ Interact_Transform_Begin(project_data *File, memory *Memory, project_state *Stat */ } + static v2 TransformPoint(layer_transforms T, real32 Width, real32 Height, v2 Point) { @@ -230,6 +237,17 @@ TransformPoint(layer_transforms T, real32 Width, real32 Height, v2 Point) return V2(T.x + LocalPoint.x, T.y + LocalPoint.y); } +static layer_transforms +Transform_Inverse(layer_transforms T) +{ + T.x = -T.x; + T.y = -T.y; + T.ax = -T.ax; + T.ay = -T.ay; + T.rotation = T.rotation; + T.scale = 1.0f; + return T; +} static ImVec2 Layer_LocalToScreenSpace(project_state *State, memory *Memory, block_layer *Layer, ui *UI, uint32 PrincipalCompIndex, v2 Point) -- cgit v1.2.3