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)] -} +