框架优化

This commit is contained in:
yhh
2021-07-02 10:11:09 +08:00
parent ea482dab48
commit 3d9c8699e7
31 changed files with 1050 additions and 1105 deletions

View File

@@ -390,8 +390,8 @@ module es {
* @param other
*/
public static project(self: Vector2, other: Vector2) {
let amt = Vector2.dot(self, other) / other.lengthSquared();
let vec = new Vector2(amt * other.x, amt * other.y);
let amt = self.dot(other) / other.lengthSquared();
let vec = other.scale(amt);
return vec;
}
@@ -606,7 +606,7 @@ module es {
return false;
}
return !Number.isFinite(x);
return x !== Infinity;
}
public static smoothDamp(current: number, target: number, currentVelocity: number, smoothTime: number, maxSpeed: number, deltaTime: number): { value: number; currentVelocity: number } {
@@ -671,5 +671,9 @@ module es {
public static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax): number {
return rightMin + ((MathHelper.clamp(value, leftMin, leftMax) - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin);
}
public static fromAngle(angle: number) {
return new Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual();
}
}
}