psychopy.tools.viewtools
¶Tools for working with view projections for 2- and 3-D rendering.
computeFrustum (scrWidth, scrAspect, scrDist) |
Calculate frustum parameters. |
generalizedPerspectiveProjection (…[, …]) |
Generalized derivation of projection and view matrices based on the physical configuration of the display system. |
orthoProjectionMatrix (left, right, bottom, …) |
Compute an orthographic projection matrix with provided frustum parameters. |
perspectiveProjectionMatrix (left, right, …) |
Compute an perspective projection matrix with provided frustum parameters. |
lookAt (eyePos, centerPos, upVec) |
Create a transformation matrix to orient towards some point. |
psychopy.tools.viewtools.
computeFrustum
(scrWidth, scrAspect, scrDist, convergeOffset=0.0, eyeOffset=0.0, nearClip=0.01, farClip=100.0)¶Calculate frustum parameters. If an eye offset is provided, an asymmetric frustum is returned which can be used for stereoscopic rendering.
Parameters: |
|
---|---|
Returns: | Namedtuple with frustum parameters. Can be directly passed to glFrustum (e.g. glFrustum(*f)). |
Return type: | Frustum |
Notes
The view point must be transformed for objects to appear correctly. Offsets in the X-direction must be applied +/- eyeOffset to account for inter-ocular separation. A transformation in the Z-direction must be applied to account for screen distance. These offsets MUST be applied to the MODELVIEW matrix, not the PROJECTION matrix! Doing so may break lighting calculations.
psychopy.tools.viewtools.
generalizedPerspectiveProjection
(posBottomLeft, posBottomRight, posTopLeft, eyePos, nearClip=0.01, farClip=100.0)¶Generalized derivation of projection and view matrices based on the physical configuration of the display system.
This implementation is based on Robert Kooima’s ‘Generalized Perspective Projection’ (see http://csc.lsu.edu/~kooima/articles/genperspective/) method.
Parameters: |
|
---|---|
Returns: | The 4x4 projection and view matrix. |
Return type: |
Notes
The resulting projection frustums are off-axis relative to the center of the display. The returned matrices are row-major. Values are floats with 32-bits of precision stored as a contiguous (C-order) array.
psychopy.tools.viewtools.
orthoProjectionMatrix
(left, right, bottom, top, nearClip, farClip)¶Compute an orthographic projection matrix with provided frustum parameters.
Parameters: |
|
---|---|
Returns: | 4x4 projection matrix |
Return type: | ndarray |
Notes
The returned matrix is row-major. Values are floats with 32-bits of precision stored as a contiguous (C-order) array.
psychopy.tools.viewtools.
perspectiveProjectionMatrix
(left, right, bottom, top, nearClip, farClip)¶Compute an perspective projection matrix with provided frustum parameters. The frustum can be asymmetric.
Parameters: |
|
---|---|
Returns: | 4x4 projection matrix |
Return type: | ndarray |
Notes
The returned matrix is row-major. Values are floats with 32-bits of precision stored as a contiguous (C-order) array.
psychopy.tools.viewtools.
lookAt
(eyePos, centerPos, upVec)¶Create a transformation matrix to orient towards some point. Based on the same algorithm as ‘gluLookAt’. This does not generate a projection matrix, but rather the matrix to transform the observer’s view in the scene.
For more information see: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml
Parameters: |
|
---|---|
Returns: | 4x4 view matrix |
Return type: | ndarray |
Notes
The returned matrix is row-major. Values are floats with 32-bits of precision stored as a contiguous (C-order) array.