Add Matrix3D::scaling

The Matrix3D class has functions to compute a translation matrix, a rotation matrix, a matrix from any 2D affine transform and even a frustum matrix. However it’s lacking a simple scaling matrix. As this is a very common thing in computer graphics, how about adding this simple function?

static Matrix3D scaling (Vector3D<Type> scale) noexcept
    return { scale.x, 0,       0,       0,
              0,       scale.y, 0,       0,
              0,       0,       scale.z, 0,
              0,       0,       0,       Type (1) };

I’d like to propose something a bit more detailed than simply the ability to scale a Matrix3D. There are other functions that would be useful and pertinent to 3D graphics: translation, reflection, shearing, and stretching/squeezing. Even more are projections of sorts.

The math library typically used in games is GLM, which contains the assortment of vectors, points, matrices, and the maths that go along with them. For influence, you can see some matrix functions here:

I‘m aware of glm and indeed, I was happy to get rid of that dependency for a simple project that now only uses the juce Matrix3D class :smile:

For more complex stuff I would always chose glm, however for simple stuff I like to do as much as possible with juce and the std library to keep the dependecy count low. I think this is the target use case for the juce Matrix3D class and a scaling function beneath the existing translation and rotation function would complete this class in a senseful way.

Well, I whipped this up if you want to give it a shot.
juce_Matrix3D.h (11.0 KB)

1 Like

Nice! To be honest I have not that much time to do some extensive testing and my current application needs nothing more in addition to the existing functionality than a scaling matrix, however it should not be to hard to write some unit tests that simply compare the results of your implementation against glm… will see if I find some time to do this.

Is the juce team even interested in extending Matrix3D like that, @fabian, @jules?

It should be straightforward enough to write some tests. Just pluck a resulting mat4 from glm and paste its guts into a Matrix3D for comparison.