Transform3D.setScale(Vector3f) appears to be buggy in that it does not preserve pre-existing rotation. The work-around that I use is to set the scale first and then set the rotation. The setRotation() method does preserve pre-existing scale.
Here is the old code. You can see that is simply overwrites the 3x3 rotation/scale matrix. This only works if there is no pre-existing rotation:
/**
* Set this transform to a scaling matrix after setting it to
* the identity matrix.
*/
public final void setScale(Vector3f v) {
// matrix.setIdentity();
// matrix.setScale(v.x);
matrix.m00 = v.x;
matrix.m11 = v.y;
matrix.m22 = v.z;
setChanged(true);
}
Here is my work-around code. It preserves copies of the translation and rotation and then resets everything with the scaling set before the rotation.
transform.get ( translationVector3f );
transform.getRotation ( rotationMatrix3f );
transform.setIdentity ( );
transform.set ( translationVector3f );
transform.setScale ( scaleVector3f );
transform.setRotation ( rotationMatrix3f );
Here is the javadoc for Matrix4f.setRotation():
Unfortunately Matrix4f does not have a setScale(Vector3f) method, only a setScale(float) method.
How about we fix Transform3D.setScale(Vector3f) by replacing the old code with something like the work-around?