summaryrefslogtreecommitdiff
path: root/src/prenderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/prenderer.cpp')
-rw-r--r--src/prenderer.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/prenderer.cpp b/src/prenderer.cpp
index 54b19cf..fc6edd4 100644
--- a/src/prenderer.cpp
+++ b/src/prenderer.cpp
@@ -1,4 +1,24 @@
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)
{
real32 X = CompUV.x*FileWidth;
@@ -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)