Last active
December 4, 2021 17:44
-
-
Save ogrew/5bfd9437e8074d84772f4b30f5e7ec23 to your computer and use it in GitHub Desktop.
Orthographic Camera in TouchDesigner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Orthographic projection | |
eps = 0.000001 | |
def onSetupParameters(scriptOp): | |
params = scriptOp.appendCustomPage('Parameters') | |
params.appendFloat('Ratio', label='Aspect Ratio') | |
params.appendFloat('Size', label='Orthographic Size') | |
params.appendFloat('N', label='Near') | |
params.appendFloat('F', label='Far') | |
return | |
def onCook(scriptOp): | |
scriptOp.clear() | |
size = scriptOp.par.Size | |
ratio = scriptOp.par.Ratio | |
n = scriptOp.par.N | |
f = scriptOp.par.F | |
m00 = 1 / (size + eps) | |
m11 = 1 / (size*ratio + eps) | |
m22 = -2 / (f - n + eps) | |
m23 = -(f + n) / (f - n + eps) | |
m33 = 1 | |
scriptOp.insertRow([m00, 0, 0, 0], 0) | |
scriptOp.insertRow([0, m11, 0, 0], 1) | |
scriptOp.insertRow([0, 0, m22, m23], 2) | |
scriptOp.insertRow([0, 0, 0, m33], 3) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment