Hello Guest

Rotation matrix scales the object

  • 0 Replies
  • 30 Views
Rotation matrix scales the object
« on: January 08, 2021, 01:39:19 »
Roation matrix code:
Code: [Select]
public static mat4 rotateMat(mat4 mat, float angle, vec3 axis) {
mat4 result = new mat4();
float radians = (float) Math.toRadians(angle);
float cos = (float) Math.cos(radians);
float sin = (float) Math.sin(radians);
float x2 = (float) Math.pow(axis.x, 2);
float y2 = (float) Math.pow(axis.y, 2);
float z2 = (float) Math.pow(axis.z, 2);
result.mat[0][0]+=cos+x2*(1-cos);
result.mat[0][1]+=axis.x*axis.y*(1-cos)-axis.z*sin;
result.mat[0][2]+=axis.x*axis.z*(1-cos)+axis.z*sin;

result.mat[1][0]+=axis.y*axis.x*(1-cos)+axis.z*sin;
result.mat[1][1]+=cos+z2*(1-cos);
result.mat[1][2]+=axis.y*axis.z*(1-cos)+axis.x*sin;

result.mat[2][0]+=axis.z*axis.x*(1-cos)-axis.y*sin;
result.mat[2][1]+=axis.z*axis.y*(1-cos)-axis.x*sin;
result.mat[2][2]+=cos+z2*(1-cos);





return result;
}
Source:


It rotates, but also scales the object, why?
And it seems logic, because the scaling is set by the diagonal of the matrix, but the rotation matrix overwrites that diagonal
« Last Edit: January 08, 2021, 01:53:43 by Mihai_Ionut_Floares »