新增entity/component等transform便捷方法

This commit is contained in:
yhh
2020-06-09 11:09:26 +08:00
parent 262e16bb88
commit 9e0d14da7c
13 changed files with 1308 additions and 5 deletions

View File

@@ -14,4 +14,26 @@ class MathHelper {
public static toRadians(degrees: number){
return degrees * 0.017453292519943295769236907684886;
}
/**
* mapps值(在leftMin - leftMax范围内)到rightMin - rightMax范围内的值
* @param value
* @param leftMin
* @param leftMax
* @param rightMin
* @param rightMax
*/
public static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number){
return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin);
}
public static clamp(value: number, min: number, max: number){
if (value < min)
return min;
if (value > max)
return max;
return value;
}
}

View File

@@ -137,7 +137,7 @@ class Matrix2D {
return this.m11 * this.m22 - this.m12 * this.m21;
}
public static invert(matrix: Matrix2D, result: Matrix2D){
public static invert(matrix: Matrix2D, result: Matrix2D = Matrix2D.identity){
let det = 1 / matrix.determinant();
result.m11 = matrix.m22 * det;