Skip to content

Commit

Permalink
Tweaked mat4 MakeRotation (-6B).
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Feb 21, 2021
1 parent d41353b commit 5c51962
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions size_history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1333,3 +1333,4 @@
66075,tweaked clampcolor
66023,tweaked mat4 multiplication and transpose
66008,new mat3/mat4 transpose functions
66002,tweaked mat4 makerotation
23 changes: 12 additions & 11 deletions src/engine/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,25 +769,26 @@ NOINLINE mat4 MakeRotation(const vec3& angles) {
0.f, 0.f, 0.f, 1.f, // column 3
};
} else {
mat4 rot[3]; // yaw, pitch, roll
mat4 result = i4x4;

u32 axis = 0;
do {
float s = Math::sin(angles[axis]);
u32 i = axis == 2; // 0 0 1
u32 j = (axis != 0) + 1; // 1 2 2

mat4 rot = i4x4;
float c = Math::cos(angles[axis]);
rot[i][i] = c;
rot[j][j] = c;

u32 i = axis == 2; // 0 0 1
u32 j = 2 - (axis == 0); // 1 2 2
float s = Math::sin(angles[axis]);
rot[j][i] = -s;
rot[i][j] = s;

rot[axis] = i4x4;
rot[axis][i][i] = c;
rot[axis][i][j] = s;
rot[axis][j][i] = -s;
rot[axis][j][j] = c;

result = result * rot;
} while (++axis < 3);

return rot[0] * rot[1] * rot[2];
return result;
}
}

Expand Down

0 comments on commit 5c51962

Please sign in to comment.