优化vector2构造函数

This commit is contained in:
yhh
2021-05-24 17:20:27 +08:00
parent 9c7703eb2d
commit da3ab02a8d
20 changed files with 177 additions and 109 deletions

View File

@@ -54,7 +54,7 @@ module es {
/**
* 该刚体的速度
*/
public velocity: Vector2 = new Vector2();
public velocity: Vector2 = es.Vector2.zero;
/**
* 质量为0的刚体被认为是不可移动的。改变速度和碰撞对它们没有影响
@@ -213,7 +213,7 @@ module es {
* @param minimumTranslationVector
* @param responseVelocity
*/
public calculateResponseVelocity(relativeVelocity: Vector2, minimumTranslationVector: Vector2, responseVelocity: Vector2 = new Vector2()) {
public calculateResponseVelocity(relativeVelocity: Vector2, minimumTranslationVector: Vector2, responseVelocity: Vector2 = es.Vector2.zero) {
// 首先我们得到反方向的归一化MTV表面法线
let inverseMTV = Vector2.multiplyScaler(minimumTranslationVector, -1);
let normal = Vector2.normalize(inverseMTV);

View File

@@ -245,7 +245,7 @@ module es {
if (scale instanceof Vector2) {
this.transform.setScale(scale);
} else {
this.transform.setScale(new Vector2(scale));
this.transform.setScale(new Vector2(scale, scale));
}
return this;
@@ -257,7 +257,7 @@ module es {
if (scale instanceof Vector2) {
this.transform.setLocalScale(scale);
} else {
this.transform.setLocalScale(new Vector2(scale));
this.transform.setLocalScale(new Vector2(scale, scale));
}
return this;

View File

@@ -77,16 +77,16 @@ module es {
for (let i = 0, s = this._components.length; i < s; ++ i) {
this.handleRemove(this._components[i]);
}
this.componentsByType.clear();
this.componentsToAddByType.clear();
this._components.length = 0;
this._updatableComponents.length = 0;
this._componentsToAdd = {};
this._componentsToRemove = {};
this._componentsToAddList.length = 0;
this._componentsToRemoveList.length = 0;
}
this.componentsByType.clear();
this.componentsToAddByType.clear();
this._components.length = 0;
this._updatableComponents.length = 0;
this._componentsToAdd = {};
this._componentsToRemove = {};
this._componentsToAddList.length = 0;
this._componentsToRemoveList.length = 0;
}
public deregisterAllComponents() {