corona
corona copied to clipboard
Custom objects, #4: z-coordinates
This is PR 4 as first described here.
The details:
Two of our display object makers have updated signatures: display.newPolygon( [parent, ]x, y, vertices[, hasZ] )
in the case of polygons, and display.newMesh()
can take hasZ = true
in its parameters table.
In either case, when we "have Z" the vertices
are read as ..., x, y, z, ...
rather than ..., x, y, ...
.
Arrays for the z-values (and possibly indices) are created on demand and maintained to pass these values around. For consistency the same is also done for other shapes, although at the moment no corresponding API support is provided.
No new native APIs have been added.
Some files were also part of PR 1 so various object factory bits resurface in the changes.
I tested using this plugin.
This introduces an object, following the ideas used by PR 2 for color masks, that turns on depth-testing and related states within a "scope". Some rects are also shown, both before and after this scope: 2D objects are still the norm.
A couple meshes are created, one from on-the-spot data and another from an .obj
file. A star polygon follows, based on the example in the Solar docs, but rather unrecognizable after being given random z
values. 😃
In PR 3 we made shell transforms that would let us bring in our vertices' z
components and use them for instancing purposes. Here we do likewise, but treat them as proper object-space z-coordinates.
Also, rather than use Solar's normal orthographic projection (appropriate to 2D), we put a model-view-projection setup in its place. For demo purposes this is done using a couple uniform userdata matrices.
The meshes and polygon employ the custom objects machinery, thus the plugin-based factories. The only real reason for this is CoronaObjectSetDummyStageBounds()
, which basically means "don't clip me": as with z
, we use the objects' x
and y
values in the obvious way, for local positions, but due to the 3D-ness, these have lost any real meaning in Solar's 2D hierarchy. Without the flag, objects will get clipped (or not) totally at random. :smile:
The cursor keys, buttons in the corner, and touch-and-drag can be used to advance, strafe, and rotate the camera, using a little dedicated module. OBJ parsing comes from Luapower, although it's since been modified quite a lot.
PR 5 would be some sort of texturing / buffers hodgepodge: stencils, floating-point, maybe compression, etc. I don't feel I have enough direction to see this through right now, so I'll hold off on it.
I've done these four PRs separately to let their changes be reviewed in smaller, cumulative chunks. However, a consolidated branch may be found here, which might be easier for the actual integration.