新增MathHelper.toInt
This commit is contained in:
Vendored
+1
@@ -2763,6 +2763,7 @@ declare module es {
|
|||||||
*/
|
*/
|
||||||
static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: any): number;
|
static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: any): number;
|
||||||
static fromAngle(angle: number): Vector2;
|
static fromAngle(angle: number): Vector2;
|
||||||
|
static toInt(val: number): number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
|||||||
+10
-9
@@ -5864,7 +5864,7 @@ var es;
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
t = es.MathHelper.clamp01(t) * this._curveCount;
|
t = es.MathHelper.clamp01(t) * this._curveCount;
|
||||||
res.range = Math.floor(t);
|
res.range = es.MathHelper.toInt(t);
|
||||||
t -= res.range;
|
t -= res.range;
|
||||||
res.range *= 3;
|
res.range *= 3;
|
||||||
}
|
}
|
||||||
@@ -6436,7 +6436,7 @@ var es;
|
|||||||
return t - Math.floor(t / length) * length;
|
return t - Math.floor(t / length) * length;
|
||||||
};
|
};
|
||||||
MathHelper.floorToInt = function (f) {
|
MathHelper.floorToInt = function (f) {
|
||||||
return Math.trunc(Math.floor(f));
|
return this.toInt(Math.floor(f));
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 将值绕一圈移动的助手
|
* 将值绕一圈移动的助手
|
||||||
@@ -6611,6 +6611,9 @@ var es;
|
|||||||
MathHelper.fromAngle = function (angle) {
|
MathHelper.fromAngle = function (angle) {
|
||||||
return new es.Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual();
|
return new es.Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual();
|
||||||
};
|
};
|
||||||
|
MathHelper.toInt = function (val) {
|
||||||
|
return val > 0 ? Math.floor(val) : Math.ceil(val);
|
||||||
|
};
|
||||||
MathHelper.Epsilon = 0.00001;
|
MathHelper.Epsilon = 0.00001;
|
||||||
MathHelper.Rad2Deg = 57.29578;
|
MathHelper.Rad2Deg = 57.29578;
|
||||||
MathHelper.Deg2Rad = 0.0174532924;
|
MathHelper.Deg2Rad = 0.0174532924;
|
||||||
@@ -8208,10 +8211,8 @@ var es;
|
|||||||
if (layerMask === void 0) { layerMask = this.allLayers; }
|
if (layerMask === void 0) { layerMask = this.allLayers; }
|
||||||
if (ignoredColliders === void 0) { ignoredColliders = null; }
|
if (ignoredColliders === void 0) { ignoredColliders = null; }
|
||||||
this._hitArray[0].reset();
|
this._hitArray[0].reset();
|
||||||
this.linecastAll(start, end, this._hitArray, layerMask);
|
|
||||||
this._hitArray[0].reset();
|
|
||||||
Physics.linecastAll(start, end, this._hitArray, layerMask, ignoredColliders);
|
Physics.linecastAll(start, end, this._hitArray, layerMask, ignoredColliders);
|
||||||
return this._hitArray[0].clone();
|
return this._hitArray[0];
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 通过空间散列强制执行一行,并用该行命中的任何碰撞器填充hits数组
|
* 通过空间散列强制执行一行,并用该行命中的任何碰撞器填充hits数组
|
||||||
@@ -8470,11 +8471,11 @@ var es;
|
|||||||
}
|
}
|
||||||
while (currentCell.x != lastCell.x || currentCell.y != lastCell.y) {
|
while (currentCell.x != lastCell.x || currentCell.y != lastCell.y) {
|
||||||
if (tMaxX < tMaxY) {
|
if (tMaxX < tMaxY) {
|
||||||
currentCell.x = es.MathHelper.approach(currentCell.x, lastCell.x, Math.abs(stepX));
|
currentCell.x = es.MathHelper.toInt(es.MathHelper.approach(currentCell.x, lastCell.x, Math.abs(stepX)));
|
||||||
tMaxX += tDeltaX;
|
tMaxX += tDeltaX;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentCell.y = es.MathHelper.approach(currentCell.y, lastCell.y, Math.abs(stepY));
|
currentCell.y = es.MathHelper.toInt(es.MathHelper.approach(currentCell.y, lastCell.y, Math.abs(stepY)));
|
||||||
tMaxY += tDeltaY;
|
tMaxY += tDeltaY;
|
||||||
}
|
}
|
||||||
cell = this.cellAtPosition(currentCell.x, currentCell.y);
|
cell = this.cellAtPosition(currentCell.x, currentCell.y);
|
||||||
@@ -8682,7 +8683,7 @@ var es;
|
|||||||
if (this._cellHits.length === 0)
|
if (this._cellHits.length === 0)
|
||||||
return false;
|
return false;
|
||||||
// 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中
|
// 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中
|
||||||
this._cellHits.sort(RaycastResultParser.compareRaycastHits);
|
this._cellHits = this._cellHits.sort(RaycastResultParser.compareRaycastHits);
|
||||||
for (var i = 0; i < this._cellHits.length; i++) {
|
for (var i = 0; i < this._cellHits.length; i++) {
|
||||||
this._hits[this.hitCounter] = this._cellHits[i];
|
this._hits[this.hitCounter] = this._cellHits[i];
|
||||||
// 增加命中计数器,如果它已经达到数组大小的限制,我们就完成了
|
// 增加命中计数器,如果它已经达到数组大小的限制,我们就完成了
|
||||||
@@ -8700,7 +8701,7 @@ var es;
|
|||||||
};
|
};
|
||||||
RaycastResultParser.compareRaycastHits = function (a, b) {
|
RaycastResultParser.compareRaycastHits = function (a, b) {
|
||||||
if (a.distance !== b.distance) {
|
if (a.distance !== b.distance) {
|
||||||
return a.distance - b.distance;
|
return b.distance - a.distance;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return a.collider.castSortOrder - b.collider.castSortOrder;
|
return a.collider.castSortOrder - b.collider.castSortOrder;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -17,7 +17,7 @@ module es {
|
|||||||
res.range = this._points.length - 4;
|
res.range = this._points.length - 4;
|
||||||
} else {
|
} else {
|
||||||
t = MathHelper.clamp01(t) * this._curveCount;
|
t = MathHelper.clamp01(t) * this._curveCount;
|
||||||
res.range = Math.floor(t);
|
res.range = MathHelper.toInt(t);
|
||||||
t -= res.range;
|
t -= res.range;
|
||||||
res.range *= 3;
|
res.range *= 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static floorToInt(f: number) {
|
public static floorToInt(f: number) {
|
||||||
return Math.trunc(Math.floor(f));
|
return this.toInt(Math.floor(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -675,5 +675,9 @@ module es {
|
|||||||
public static fromAngle(angle: number) {
|
public static fromAngle(angle: number) {
|
||||||
return new Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual();
|
return new Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static toInt(val: number){
|
||||||
|
return val>0 ? Math.floor(val):Math.ceil(val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,8 +146,6 @@ module es {
|
|||||||
* @param layerMask
|
* @param layerMask
|
||||||
*/
|
*/
|
||||||
public static linecast(start: Vector2, end: Vector2, layerMask: number = this.allLayers, ignoredColliders: Set<Collider> = null): RaycastHit {
|
public static linecast(start: Vector2, end: Vector2, layerMask: number = this.allLayers, ignoredColliders: Set<Collider> = null): RaycastHit {
|
||||||
this._hitArray[0].reset();
|
|
||||||
this.linecastAll(start, end, this._hitArray, layerMask);
|
|
||||||
this._hitArray[0].reset();
|
this._hitArray[0].reset();
|
||||||
Physics.linecastAll(
|
Physics.linecastAll(
|
||||||
start,
|
start,
|
||||||
@@ -156,7 +154,7 @@ module es {
|
|||||||
layerMask,
|
layerMask,
|
||||||
ignoredColliders
|
ignoredColliders
|
||||||
);
|
);
|
||||||
return this._hitArray[0].clone();
|
return this._hitArray[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -183,11 +183,11 @@ module es {
|
|||||||
|
|
||||||
while (currentCell.x != lastCell.x || currentCell.y != lastCell.y) {
|
while (currentCell.x != lastCell.x || currentCell.y != lastCell.y) {
|
||||||
if (tMaxX < tMaxY) {
|
if (tMaxX < tMaxY) {
|
||||||
currentCell.x = MathHelper.approach(currentCell.x, lastCell.x, Math.abs(stepX));
|
currentCell.x = MathHelper.toInt(MathHelper.approach(currentCell.x, lastCell.x, Math.abs(stepX)));
|
||||||
|
|
||||||
tMaxX += tDeltaX;
|
tMaxX += tDeltaX;
|
||||||
} else {
|
} else {
|
||||||
currentCell.y = MathHelper.approach(currentCell.y, lastCell.y, Math.abs(stepY));
|
currentCell.y = MathHelper.toInt(MathHelper.approach(currentCell.y, lastCell.y, Math.abs(stepY)));
|
||||||
|
|
||||||
tMaxY += tDeltaY;
|
tMaxY += tDeltaY;
|
||||||
}
|
}
|
||||||
@@ -427,7 +427,7 @@ module es {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中
|
// 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中
|
||||||
this._cellHits.sort(RaycastResultParser.compareRaycastHits);
|
this._cellHits = this._cellHits.sort(RaycastResultParser.compareRaycastHits);
|
||||||
for (let i = 0; i < this._cellHits.length; i++) {
|
for (let i = 0; i < this._cellHits.length; i++) {
|
||||||
this._hits[this.hitCounter] = this._cellHits[i];
|
this._hits[this.hitCounter] = this._cellHits[i];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user