Skip to content

Commit 2b8521e

Browse files
committed
修复: Matrix#applyLocation 无法使用的问题
1 parent 43b0db8 commit 2b8521e

1 file changed

Lines changed: 5 additions & 40 deletions

File tree

  • src/main/java/top/zoyn/particlelib/utils/matrix

src/main/java/top/zoyn/particlelib/utils/matrix/Matrix.java

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.Location;
44
import org.bukkit.util.Vector;
5+
import top.zoyn.particlelib.utils.VectorUtils;
56

67
import java.util.Arrays;
78

@@ -200,16 +201,12 @@ public void prettyPrinting() {
200201
* 将本矩阵的变换作用至给定的坐标上
201202
*
202203
* @param location 给定的坐标
204+
* @param origin 原点坐标 用于确定变换的原点
203205
* @return {@link Location}
204206
*/
205-
public Location applyLocation(Location location) {
206-
if (getRow() == 2 && getColumn() == 2) {
207-
return applyIn2DLocation(location);
208-
} else if (getRow() == 3 && getColumn() == 3) {
209-
return applyIn3DLocation(location);
210-
}
211-
212-
throw new IllegalArgumentException("当前矩阵非 2*2 或 3*3 的方阵");
207+
public Location applyLocation(Location location, Location origin) {
208+
Vector vector = VectorUtils.createVector(origin, location);
209+
return origin.clone().add(applyVector(vector));
213210
}
214211

215212
/**
@@ -260,36 +257,4 @@ private Vector applyIn3DVector(Vector vector) {
260257
return new Vector(ax + ay + az, bx + by + bz, cx + cy + cz);
261258
}
262259

263-
private Location applyIn2DLocation(Location location) {
264-
double x = location.getX();
265-
double z = location.getZ();
266-
double ax = getAsArray()[0][0] * x;
267-
double ay = getAsArray()[0][1] * z;
268-
269-
double bx = getAsArray()[1][0] * x;
270-
double by = getAsArray()[1][1] * z;
271-
272-
return new Location(location.getWorld(), ax + ay, location.getY(), bx + by, location.getYaw(), location.getPitch());
273-
}
274-
275-
private Location applyIn3DLocation(Location location) {
276-
double x = location.getX();
277-
double y = location.getY();
278-
double z = location.getZ();
279-
280-
double ax = getAsArray()[0][0] * x;
281-
double ay = getAsArray()[0][1] * y;
282-
double az = getAsArray()[0][2] * z;
283-
284-
double bx = getAsArray()[1][0] * x;
285-
double by = getAsArray()[1][1] * y;
286-
double bz = getAsArray()[1][2] * z;
287-
288-
double cx = getAsArray()[2][0] * x;
289-
double cy = getAsArray()[2][1] * y;
290-
double cz = getAsArray()[2][2] * z;
291-
292-
return new Location(location.getWorld(), ax + ay + az, bx + by + bz, cx + cy + cz, location.getYaw(), location.getPitch());
293-
}
294-
295260
}

0 commit comments

Comments
 (0)