Matrix3/Matrix4 Additions & ShapeRenderer

I invested some time today to fix a long standing feature enhancement: in-place matrix operations. What’s that? OpenGL ES 1.x (and desktop OpenGL) have a rather convenient way of concatenating matrix operations:

These functions operate on the top of the currently active matrix stack of OpenGL. The transformations are applied from bottom to top (rotate, scale then translate in the above example).

Doing something like this with Matrix3 and Matrix4 was a bit of a piece in the ass until now as one had to use a temporary matrix to achieve the same. I went ahead and implemented three new methods on Matrix3 and Matrix4: rotate, scale and translate. These will post-multiply the matrix with a rotation, scaling or translation matrix, in-place. No need for a temporary matrix anymore. Furthermore, the methods return a reference to the matrix so you can easily chain transformations.

In addition to that i wrote a little class called ShapeRenderer which allows you to draw points, lines, (filled) rectangles, and boxes. The class is meant to support you while debugging and follows the batching paradigmn we have in a lot of our graphics classes. It’s actually not terribly slow, but i’d still not recommend using it in production.


You can find the code that produces the above output here. I put a bit of effort in the javadocs of the class as well. This is how i want all our javadocs to look like in the near future, maybe you can give me feedback if it’s good enough.

2 thoughts on “Matrix3/Matrix4 Additions & ShapeRenderer

  1. Oh that’s cool, i really wanted to find some time to code just that Mat3/4 stuff this evening, but failed hard due to me discovering the SpriteBatch always uses VA instead of VBO unless the number of buffers are specified. Thank you much for the great addition!

Leave a Reply

Your email address will not be published.