|
2 | 2 |
|
3 | 3 | import org.bukkit.Location; |
4 | 4 | import org.bukkit.util.Vector; |
| 5 | +import top.zoyn.particlelib.utils.VectorUtils; |
5 | 6 |
|
6 | 7 | import java.util.Arrays; |
7 | 8 |
|
@@ -200,16 +201,12 @@ public void prettyPrinting() { |
200 | 201 | * 将本矩阵的变换作用至给定的坐标上 |
201 | 202 | * |
202 | 203 | * @param location 给定的坐标 |
| 204 | + * @param origin 原点坐标 用于确定变换的原点 |
203 | 205 | * @return {@link Location} |
204 | 206 | */ |
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)); |
213 | 210 | } |
214 | 211 |
|
215 | 212 | /** |
@@ -260,36 +257,4 @@ private Vector applyIn3DVector(Vector vector) { |
260 | 257 | return new Vector(ax + ay + az, bx + by + bz, cx + cy + cz); |
261 | 258 | } |
262 | 259 |
|
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 | | - |
295 | 260 | } |
0 commit comments