PLEASE NOTE THE CODE IN THIS THREAD WILL NOT WORK IN CODEA 1.3.1
I’ve opened this thread up to everyone so people can examine and comment on the new 3D stuff
There is no documentation for this stuff yet. So this thread will serve as the beta documentation for now.
You can grab a sample 3D scene here: http://twolivesleft.com/Codea/Projects/3D_Test.codea
Source code on pastebin: http://pastebin.com/gJ6CxXD2
Basic Matrix Control
multMatrix( m )
Multiplies matrix m against the current model matrix.
modelMatrix() modelMatrix( m )
Called with no parameters, returns the current model matrix. When called with a matrix parameter modelMatrix sets the current model matrix to the specified matrix. Defaults to identity.
projectionMatrix() projectionMatrix( m )
Called with no parameters, returns the current projection matrix. When called with a matrix parameter projectionMatrix sets the current projection matrix to the specified matrix.
The default projection is an orthographic projection starting at the lower left of the screen and extending WIDTH, HEIGHT to the upper right corner of the screen.
viewMatrix() viewMatrix( m )
Called with no parameters, returns the current view matrix. When called with a matrix parameter viewMatrix sets the current view matrix to the specified matrix. Defaults to identity.
Represents a 4x4 matrix (column major). Supports the following operations:
m1 = matrix() -- creates an identity matrix m2 = matrix( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ) m = m1 * m2 -- matrix multiplication m = m1 * 5 -- scalar multiplication m = m1 / 5 -- scalar division m = m:rotate( angle, x, y, z ) m = m:translate( x, y, z ) m = m:scale( x, y, z ) print( m )
vec4 is new. vec3 now supports most common operations that vec2 supports.
perspective() perspective( fov, aspect, zNear, zFar )
This sets the projection matrix to the perspective projection defined by the given parameters. If called with no parameters it defaults to fov=45 degrees, aspect=WIDTH/HEIGHT, zNear=0.1, zFar=(HEIGHT/2) / tan( pi * 60 / 360 ) * 10.
ortho() ortho( left, right, bottom, top, near, far )
This sets the projection matrix to the orthographic projection defined by the given parameters. If called with no parameters it defaults to ortho( 0, WIDTH, 0, HEIGHT, -10, 10 )
camera() camera( eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ )
This sets up the view matrix to emulate a camera positioned eye and pointing at center, with an up-vector defined by up. Called without parameters it defaults to camera( 0, 0, -10, 0, 0, 0, 0, 1, 0 )