Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TransformOperation] Added ignoreAspectRatio and anchorTopLeft support #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions framework/Source/Operations/TransformOperation.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)]
}