Skip to content

Commit

Permalink
[6.0.10][publish] fix matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed May 22, 2023
1 parent 3023800 commit b349a85
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static Matrix rotateAroundXAxis(double theta) {
}

/**
* 通过给定的角度返回一个关于Z轴的旋转矩阵
* 通过给定的角度返回一个关于Y轴的旋转矩阵
* <p>注意:该方法会返回3阶方阵</p>
*
* @param theta 旋转角度
Expand Down Expand Up @@ -152,4 +152,4 @@ public static Matrix scale(int row, int column, double value) {
return eyes(row, column).multiply(value);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b349a85

Please sign in to comment.