优化collision

This commit is contained in:
YHH
2020-06-15 08:46:38 +08:00
parent 246e9a9511
commit 7f8f1cf0d0
8 changed files with 132 additions and 7 deletions

View File

@@ -8,9 +8,9 @@ class Vector2 {
* @param x 二维空间中的x坐标
* @param y 二维空间的y坐标
*/
constructor(x: number, y: number){
constructor(x: number, y?: number){
this.x = x;
this.y = y;
this.y = y ? y : x;
}
public static add(value1: Vector2, value2: Vector2){
@@ -78,6 +78,10 @@ class Vector2 {
return (v1 * v1) + (v2 * v2);
}
public static lerp(value1: Vector2, value2: Vector2, amount: number){
return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
}
public static transform(position: Vector2, matrix: Matrix2D){
return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22));
}