One of the most powerful objects in the jitter library is jit.gl.multiple. It allows you to quickly create and manage arrays of OpenGL objects by manipulating matrix data to control the GL parameters, with results that would be incredibly tedious and difficult if done by hand. For the expert in jit.expr, it seems like anything is possible, but for beginning users the barrier to entry can feel really high. Over the years I’ve seen a lot of people get hung up trying to get started with it and wanted to provide an example of how easy it can be to use.
In this patch we leverage the matrixoutput attribute of jit.gl.gridshape to generate interesting and organized position data to feed our jit.gl.multiple. In this case, we use ‘@matrixoutput 2’, which not only gives us access to the basic shapes that jit.gl.gridshape provides in the desired float32 type, but also includes transforms (scaling, rotation, positioning) performed on the object in the output matrix data. This makes it easy to manipulate the entire group all at once.
Furthermore, now that the geometry is a standard matrix, we can use any number of jitter objects to tweak it. A jit.xfade allows us to combine the outputs of two separate jit.gl.gridshape objects, opening up a world of possibilities.
For the rotation data, we use jit.expr to create a normalized range of values across each axis of rotation, then multiply that by a custom value in degrees. If we set the value to 360, we will see the forms make one full rotation over the length of the array, regardless of how many we are drawing. Adjusting the offset determines the initial angle of rotation.
The scale is being set globally using the setall message to a jit.matrix, but could also be controlled by any matrix data we choose.
Download the patch and give it a try!
For those looking to take this further, make sure to check out Andrew Benson’s article Demystifying Expressions in Jitter as well as the many posts in the forums.