Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kooparse authored Mar 5, 2024
2 parents f6aa18f + 68e7722 commit 5b26d16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/mat3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ pub fn Mat3x3(comptime T: type) type {
pub fn extractEulerAngles(self: Self) Vector3 {
const m = self.orthoNormalize();

const theta_x = math.atan2(T, m.data[1][2], m.data[2][2]);
const theta_x = math.atan2(m.data[1][2], m.data[2][2]);
const c2 = @sqrt(math.pow(T, m.data[0][0], 2) + math.pow(T, m.data[0][1], 2));
const theta_y = math.atan2(T, -m.data[0][2], @sqrt(c2));
const theta_y = math.atan2(-m.data[0][2], @sqrt(c2));
const s1 = @sin(theta_x);
const c1 = @cos(theta_x);
const theta_z = math.atan2(T, s1 * m.data[2][0] - c1 * m.data[1][0], c1 * m.data[1][1] - s1 * m.data[2][1]);
const theta_z = math.atan2(s1 * m.data[2][0] - c1 * m.data[1][0], c1 * m.data[1][1] - s1 * m.data[2][1]);

return Vector3.new(root.toDegrees(theta_x), root.toDegrees(theta_y), root.toDegrees(theta_z));
}
Expand Down
6 changes: 3 additions & 3 deletions src/mat4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ pub fn Mat4x4(comptime T: type) type {
pub fn extractEulerAngles(self: Self) Vector3 {
const m = self.orthoNormalize();

const theta_x = math.atan2(T, m.data[1][2], m.data[2][2]);
const theta_x = math.atan2(m.data[1][2], m.data[2][2]);
const c2 = @sqrt(math.pow(T, m.data[0][0], 2) + math.pow(T, m.data[0][1], 2));
const theta_y = math.atan2(T, -m.data[0][2], @sqrt(c2));
const theta_y = math.atan2(-m.data[0][2], @sqrt(c2));
const s1 = @sin(theta_x);
const c1 = @cos(theta_x);
const theta_z = math.atan2(T, s1 * m.data[2][0] - c1 * m.data[1][0], c1 * m.data[1][1] - s1 * m.data[2][1]);
const theta_z = math.atan2(s1 * m.data[2][0] - c1 * m.data[1][0], c1 * m.data[1][1] - s1 * m.data[2][1]);

return Vector3.new(root.toDegrees(theta_x), root.toDegrees(theta_y), root.toDegrees(theta_z));
}
Expand Down
2 changes: 0 additions & 2 deletions src/quaternion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,13 @@ pub fn Quaternion(comptime T: type) type {
/// Extract euler angles (degrees) from quaternion.
pub fn extractEulerAngles(self: Self) Vector3 {
const yaw = math.atan2(
T,
2 * (self.y * self.z + self.w * self.x),
self.w * self.w - self.x * self.x - self.y * self.y + self.z * self.z,
);
const pitch = math.asin(
-2 * (self.x * self.z - self.w * self.y),
);
const roll = math.atan2(
T,
2 * (self.x * self.y + self.w * self.z),
self.w * self.w + self.x * self.x - self.y * self.y - self.z * self.z,
);
Expand Down

0 comments on commit 5b26d16

Please sign in to comment.