Last active
December 4, 2021 17:44
-
-
Save ogrew/2080140632152ee96b5efb9222eaee23 to your computer and use it in GitHub Desktop.
Perspective 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
# Perspective Projection | |
eps = 0.000001 | |
def onSetupParameters(scriptOp): | |
params = scriptOp.appendCustomPage('Parameters') | |
params.appendFloat('Size', label='Perspective Size') | |
params.appendFloat('Ratio', label='Aspect Ratio') | |
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 = n / (size + eps) | |
m11 = n / (size*ratio + eps) | |
m22 = -(f + n) / (f - n + eps) | |
m23 = -2 * f * n / (f - n + eps) | |
m32 = -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, m32, 0], 3) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment