Skip to content

Commit

Permalink
fix 2d affine transform computing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Ji committed Nov 21, 2024
1 parent 5e6e8ac commit f0055d3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/j2d/AffineTransform.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ pub fn setToRotateByPoint(self: *Self, p: jok.Point, radian: f32) void {
}

pub fn setToRotateToVec(self: *Self, v: jok.Point) void {
self.mat = zmath.rotationZ(math.atan2(f32, v.y, v.x));
self.mat = zmath.rotationZ(math.atan2(v.y, v.x));
}

pub fn setToRotateToVecByPoint(self: *Self, p: jok.Point, v: jok.Point) void {
self.mat = zmath.mul(
zmath.mul(
zmath.translation(-p.x, -p.y, 0),
zmath.rotationZ(math.atan2(f32, v.y, v.x)),
zmath.rotationZ(math.atan2(v.y, v.x)),
),
zmath.translation(p.x, p.y, 0),
);
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn rotateByPoint(self: Self, p: jok.Point, radian: f32) Self {

pub fn rotateToVec(self: Self, v: jok.Point) Self {
return .{
.mat = zmath.mul(self.mat, zmath.rotationZ(math.atan2(f32, v.y, v.x))),
.mat = zmath.mul(self.mat, zmath.rotationZ(math.atan2(v.y, v.x))),
};
}

Expand All @@ -157,7 +157,7 @@ pub fn rotateToVecByPoint(self: Self, v: jok.Point, p: jok.Point) Self {
zmath.mul(
zmath.mul(
zmath.translation(-p.x, -p.y, 0),
zmath.rotationZ(math.atan2(f32, v.y, v.x)),
zmath.rotationZ(math.atan2(v.y, v.x)),
),
zmath.translation(p.x, p.y, 0),
),
Expand Down

0 comments on commit f0055d3

Please sign in to comment.