From b349a85a85e08e6d1ca5f7d0e9fbe7b9040940bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 22 May 2023 17:36:46 +0800 Subject: [PATCH] [6.0.10][publish] fix matrix --- .../taboolib/module/effect/math/Matrix.java | 47 +++---------------- .../taboolib/module/effect/math/Matrixs.java | 4 +- .../taboolib/module/effect/ParticleObj.kt | 28 +++++++++-- 3 files changed, 33 insertions(+), 46 deletions(-) diff --git a/module/module-effect/src/main/java/taboolib/module/effect/math/Matrix.java b/module/module-effect/src/main/java/taboolib/module/effect/math/Matrix.java index fe1b4895f..778394e9e 100644 --- a/module/module-effect/src/main/java/taboolib/module/effect/math/Matrix.java +++ b/module/module-effect/src/main/java/taboolib/module/effect/math/Matrix.java @@ -201,16 +201,12 @@ public void prettyPrinting() { * 将本矩阵的变换作用至给定的坐标上 * * @param location 给定的坐标 + * @param origin 原点坐标 用于确定变换的原点 * @return {@link Location} */ - public Location applyLocation(Location location) { - if (getRow() == 2 && getColumn() == 2) { - return applyIn2DLocation(location); - } else if (getRow() == 3 && getColumn() == 3) { - return applyIn3DLocation(location); - } - - throw new IllegalArgumentException("当前矩阵非 2*2 或 3*3 的方阵"); + public Location applyLocation(Location location, Location origin) { + Vector vector = createVector(origin, location); + return origin.clone().add(applyVector(vector)); } /** @@ -261,36 +257,7 @@ private Vector applyIn3DVector(Vector vector) { return new Vector(ax + ay + az, bx + by + bz, cx + cy + cz); } - private Location applyIn2DLocation(Location location) { - double x = location.getX(); - double z = location.getZ(); - double ax = getAsArray()[0][0] * x; - double ay = getAsArray()[0][1] * z; - - double bx = getAsArray()[1][0] * x; - double by = getAsArray()[1][1] * z; - - return new Location(location.getWorld(), ax + ay, location.getY(), bx + by, location.getYaw(), location.getPitch()); + public static Vector createVector(Location start, Location end) { + return new Vector(end.getX() - start.getX(), end.getY() - start.getY(), end.getZ() - start.getZ()); } - - private Location applyIn3DLocation(Location location) { - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - - double ax = getAsArray()[0][0] * x; - double ay = getAsArray()[0][1] * y; - double az = getAsArray()[0][2] * z; - - double bx = getAsArray()[1][0] * x; - double by = getAsArray()[1][1] * y; - double bz = getAsArray()[1][2] * z; - - double cx = getAsArray()[2][0] * x; - double cy = getAsArray()[2][1] * y; - double cz = getAsArray()[2][2] * z; - - return new Location(location.getWorld(), ax + ay + az, bx + by + bz, cx + cy + cz, location.getYaw(), location.getPitch()); - } - -} +} \ No newline at end of file diff --git a/module/module-effect/src/main/java/taboolib/module/effect/math/Matrixs.java b/module/module-effect/src/main/java/taboolib/module/effect/math/Matrixs.java index dfd12efe8..ab1e4b05c 100644 --- a/module/module-effect/src/main/java/taboolib/module/effect/math/Matrixs.java +++ b/module/module-effect/src/main/java/taboolib/module/effect/math/Matrixs.java @@ -99,7 +99,7 @@ public static Matrix rotateAroundXAxis(double theta) { } /** - * 通过给定的角度返回一个关于Z轴的旋转矩阵 + * 通过给定的角度返回一个关于Y轴的旋转矩阵 *
注意:该方法会返回3阶方阵
* * @param theta 旋转角度 @@ -152,4 +152,4 @@ public static Matrix scale(int row, int column, double value) { return eyes(row, column).multiply(value); } -} +} \ No newline at end of file diff --git a/module/module-effect/src/main/kotlin/taboolib/module/effect/ParticleObj.kt b/module/module-effect/src/main/kotlin/taboolib/module/effect/ParticleObj.kt index 3a9f97b36..9b6a620ac 100644 --- a/module/module-effect/src/main/kotlin/taboolib/module/effect/ParticleObj.kt +++ b/module/module-effect/src/main/kotlin/taboolib/module/effect/ParticleObj.kt @@ -21,19 +21,39 @@ abstract class ParticleObj(var spawner: ParticleSpawner) { private var matrix: Matrix? = null private var task: PlatformTask? = null - fun addMatrix(matrix: Matrix) { + /** + * 给该特效对象叠加一个矩阵 + * + * @param matrix 给定的矩阵 + * @return [ParticleObj] + */ + open fun addMatrix(matrix: Matrix): ParticleObj { if (this.matrix == null) { setMatrix(matrix) + return this } this.matrix = matrix.multiply(this.matrix) + return this } - fun setMatrix(matrix: Matrix?) { + /** + * 给该特效对象设置一个矩阵 + * 该方法将会直接覆盖之前所有已经变换好的矩阵 + * + * @param matrix 给定的矩阵 + * @return [ParticleObj] + */ + open fun setMatrix(matrix: Matrix?): ParticleObj { this.matrix = matrix + return this } - - fun removeMatrix() { + /** + * 移除该特效对象的矩阵 + * @return [ParticleObj] + */ + open fun removeMatrix(): ParticleObj { matrix = null + return this } fun hasMatrix(): Boolean {