From d62568185414e0b1b11565d8e128c7daecfa6ae2 Mon Sep 17 00:00:00 2001 From: Josh Bernfeld Date: Mon, 2 Apr 2018 17:34:30 -0700 Subject: [PATCH] [TransformOperation] Added ignoreAspectRatio and anchorTopLeft support --- .../Operations/TransformOperation.swift | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) mode change 100644 => 100755 framework/Source/Operations/TransformOperation.swift diff --git a/framework/Source/Operations/TransformOperation.swift b/framework/Source/Operations/TransformOperation.swift old mode 100644 new mode 100755 index 6b87a377..0d6b72d0 --- a/framework/Source/Operations/TransformOperation.swift +++ b/framework/Source/Operations/TransformOperation.swift @@ -14,6 +14,8 @@ public class TransformOperation: BasicOperation { public var transform:Matrix4x4 = Matrix4x4.identity { didSet { uniformSettings["transformMatrix"] = transform } } + public var anchorTopLeft = false + public var ignoreAspectRatio = false var normalizedImageVertices:[GLfloat]! public init() { @@ -29,14 +31,25 @@ public class TransformOperation: BasicOperation { override func configureFramebufferSpecificUniforms(_ inputFramebuffer:Framebuffer) { let outputRotation = overriddenOutputRotation ?? inputFramebuffer.orientation.rotationNeededForOrientation(.portrait) - let aspectRatio = inputFramebuffer.aspectRatioForRotation(outputRotation) - let orthoMatrix = orthographicMatrix(-1.0, right:1.0, bottom:-1.0 * aspectRatio, top:1.0 * aspectRatio, near:-1.0, far:1.0) + var aspectRatio = inputFramebuffer.aspectRatioForRotation(outputRotation) + if(ignoreAspectRatio) { + aspectRatio = 1 + } + let orthoMatrix = orthographicMatrix(-1.0, right:1.0, bottom:-1.0 * aspectRatio, top:1.0 * aspectRatio, near:-1.0, far:1.0, anchorTopLeft:anchorTopLeft) normalizedImageVertices = normalizedImageVerticesForAspectRatio(aspectRatio) uniformSettings["orthographicMatrix"] = orthoMatrix } + + func normalizedImageVerticesForAspectRatio(_ aspectRatio:Float) -> [GLfloat] { + // [TopLeft.x, TopLeft.y, TopRight.x, TopRight.y, BottomLeft.x, BottomLeft.y, BottomRight.x, BottomRight.y] + if(anchorTopLeft) { + return [0.0, 0.0, 1.0, 0.0, 0.0, GLfloat(aspectRatio), 1.0, GLfloat(aspectRatio)] + } + else { + return [-1.0, GLfloat(-aspectRatio), 1.0, GLfloat(-aspectRatio), -1.0, GLfloat(aspectRatio), 1.0, GLfloat(aspectRatio)] + } + } } -func normalizedImageVerticesForAspectRatio(_ aspectRatio:Float) -> [GLfloat] { - return [-1.0, GLfloat(-aspectRatio), 1.0, GLfloat(-aspectRatio), -1.0, GLfloat(aspectRatio), 1.0, GLfloat(aspectRatio)] -} +