Scale retrieve method for Matrix4f

Hey guys.

I created a method in blender importer that retreives the scale from Matrix4f.
Here it is.

public Vector3f getScale(Matrix4f matrix) {
float scaleX = (float) Math.sqrt(matrix.m00 * matrix.m00 + matrix.m10 * matrix.m10 + matrix.m20 * matrix.m20);
float scaleY = (float) Math.sqrt(matrix.m01 * matrix.m01 + matrix.m11 * matrix.m11 + matrix.m21 * matrix.m21);
float scaleZ = (float) Math.sqrt(matrix.m02 * matrix.m02 + matrix.m12 * matrix.m12 + matrix.m22 * matrix.m22);
return new Vector3f(scaleX, scaleY, scaleZ);

How do you think about adding it to Matrix4f class ?
I have been using it for a long time and looks like it works correclty :wink:

The implementation would look like this:
public Vector3f toScaleVector() {
Vector3f result = new Vector3f();
return result;

public void toScaleVector(Vector3f vector) {
float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20);
float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21);
float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22);
vector.set(scaleX, scaleY, scaleZ);


For what it’s worth, I’m fine with it. I don’t like the name really but it fits the other methods in the class… so my discomfort is invalid. :slight_smile:

I’m ok too go ahead. Could you please document them though?

Sure I will :slight_smile:

OK, I have just made a commit :wink: