边框支持旋转
This commit is contained in:
Vendored
+2
-1
@@ -1196,6 +1196,8 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class Rectangle extends egret.Rectangle {
|
||||
_tempMat: Matrix2D;
|
||||
_transformMat: Matrix2D;
|
||||
readonly max: Vector2;
|
||||
readonly center: Vector2;
|
||||
location: Vector2;
|
||||
@@ -1207,7 +1209,6 @@ declare module es {
|
||||
getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2;
|
||||
getClosestPointOnBoundsToOrigin(): Vector2;
|
||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
||||
setEgretRect(rect: egret.Rectangle): Rectangle;
|
||||
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5675,17 +5675,38 @@ var es;
|
||||
return boundsPoint;
|
||||
};
|
||||
Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) {
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
this.height = height * scale.y;
|
||||
};
|
||||
Rectangle.prototype.setEgretRect = function (rect) {
|
||||
this.x = rect.x;
|
||||
this.y = rect.y;
|
||||
this.width = rect.width;
|
||||
this.height = rect.height;
|
||||
return this;
|
||||
if (rotation == 0) {
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
this.height = height * scale.y;
|
||||
}
|
||||
else {
|
||||
var worldPosX = parentPosition.x + position.x;
|
||||
var worldPosY = parentPosition.y + position.y;
|
||||
this._transformMat = es.Matrix2D.create().translate(-worldPosX - origin.x, -worldPosY - origin.y);
|
||||
this._tempMat = es.Matrix2D.create().scale(scale.x, scale.y);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
this._tempMat = es.Matrix2D.create().rotate(rotation);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
this._tempMat = es.Matrix2D.create().translate(worldPosX, worldPosY);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
var topLeft = new es.Vector2(worldPosX, worldPosY);
|
||||
var topRight = new es.Vector2(worldPosX + width, worldPosY);
|
||||
var bottomLeft = new es.Vector2(worldPosX, worldPosY + height);
|
||||
var bottomRight = new es.Vector2(worldPosX + width, worldPosY + height);
|
||||
topLeft = es.Vector2Ext.transformR(topLeft, this._transformMat);
|
||||
topRight = es.Vector2Ext.transformR(topRight, this._transformMat);
|
||||
bottomLeft = es.Vector2Ext.transformR(bottomLeft, this._transformMat);
|
||||
bottomRight = es.Vector2Ext.transformR(bottomRight, this._transformMat);
|
||||
var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
||||
var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
||||
var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
||||
var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
||||
this.location = new es.Vector2(minX, minY);
|
||||
this.width = maxX - minX;
|
||||
this.height = maxY - minY;
|
||||
}
|
||||
};
|
||||
Rectangle.rectEncompassingPoints = function (points) {
|
||||
var minX = Number.POSITIVE_INFINITY;
|
||||
@@ -6620,7 +6641,7 @@ var es;
|
||||
this._store = new Map();
|
||||
}
|
||||
NumberDictionary.prototype.getKey = function (x, y) {
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString();
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
|
||||
};
|
||||
NumberDictionary.prototype.add = function (x, y, list) {
|
||||
this._store.set(this.getKey(x, y), list);
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -19,11 +19,11 @@ module scene {
|
||||
bg.addComponent(new es.BoxCollider());
|
||||
bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
|
||||
|
||||
for (let i = 0; i < 1; i++) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
|
||||
let player2 = this.createEntity("player2");
|
||||
player2.addComponent(new es.SpriteRenderer()).setSprite(sprite);
|
||||
player2.position = new es.Vector2(Math.random() * 100, Math.random() * 100);
|
||||
player2.position = new es.Vector2(Math.random() * 1000, Math.random() * 1000);
|
||||
player2.addComponent(new es.BoxCollider());
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-1
@@ -1196,6 +1196,8 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class Rectangle extends egret.Rectangle {
|
||||
_tempMat: Matrix2D;
|
||||
_transformMat: Matrix2D;
|
||||
readonly max: Vector2;
|
||||
readonly center: Vector2;
|
||||
location: Vector2;
|
||||
@@ -1207,7 +1209,6 @@ declare module es {
|
||||
getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2;
|
||||
getClosestPointOnBoundsToOrigin(): Vector2;
|
||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
||||
setEgretRect(rect: egret.Rectangle): Rectangle;
|
||||
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
||||
}
|
||||
}
|
||||
|
||||
+33
-12
@@ -5675,17 +5675,38 @@ var es;
|
||||
return boundsPoint;
|
||||
};
|
||||
Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) {
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
this.height = height * scale.y;
|
||||
};
|
||||
Rectangle.prototype.setEgretRect = function (rect) {
|
||||
this.x = rect.x;
|
||||
this.y = rect.y;
|
||||
this.width = rect.width;
|
||||
this.height = rect.height;
|
||||
return this;
|
||||
if (rotation == 0) {
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
this.height = height * scale.y;
|
||||
}
|
||||
else {
|
||||
var worldPosX = parentPosition.x + position.x;
|
||||
var worldPosY = parentPosition.y + position.y;
|
||||
this._transformMat = es.Matrix2D.create().translate(-worldPosX - origin.x, -worldPosY - origin.y);
|
||||
this._tempMat = es.Matrix2D.create().scale(scale.x, scale.y);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
this._tempMat = es.Matrix2D.create().rotate(rotation);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
this._tempMat = es.Matrix2D.create().translate(worldPosX, worldPosY);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
var topLeft = new es.Vector2(worldPosX, worldPosY);
|
||||
var topRight = new es.Vector2(worldPosX + width, worldPosY);
|
||||
var bottomLeft = new es.Vector2(worldPosX, worldPosY + height);
|
||||
var bottomRight = new es.Vector2(worldPosX + width, worldPosY + height);
|
||||
topLeft = es.Vector2Ext.transformR(topLeft, this._transformMat);
|
||||
topRight = es.Vector2Ext.transformR(topRight, this._transformMat);
|
||||
bottomLeft = es.Vector2Ext.transformR(bottomLeft, this._transformMat);
|
||||
bottomRight = es.Vector2Ext.transformR(bottomRight, this._transformMat);
|
||||
var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
||||
var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
||||
var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
||||
var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
||||
this.location = new es.Vector2(minX, minY);
|
||||
this.width = maxX - minX;
|
||||
this.height = maxY - minY;
|
||||
}
|
||||
};
|
||||
Rectangle.rectEncompassingPoints = function (points) {
|
||||
var minX = Number.POSITIVE_INFINITY;
|
||||
@@ -6620,7 +6641,7 @@ var es;
|
||||
this._store = new Map();
|
||||
}
|
||||
NumberDictionary.prototype.getKey = function (x, y) {
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString();
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
|
||||
};
|
||||
NumberDictionary.prototype.add = function (x, y, list) {
|
||||
this._store.set(this.getKey(x, y), list);
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,5 +1,7 @@
|
||||
module es {
|
||||
export class Rectangle extends egret.Rectangle {
|
||||
public _tempMat: Matrix2D;
|
||||
public _transformMat: Matrix2D;
|
||||
/**
|
||||
* 获取矩形的最大点,即右下角
|
||||
*/
|
||||
@@ -141,22 +143,45 @@ module es {
|
||||
}
|
||||
|
||||
public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number){
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
this.height = height * scale.y;
|
||||
}
|
||||
if (rotation == 0){
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
this.height = height * scale.y;
|
||||
} else {
|
||||
// 特别注意旋转的边界。我们需要找到绝对的最小/最大值并从中创建边界
|
||||
let worldPosX = parentPosition.x + position.x;
|
||||
let worldPosY = parentPosition.y + position.y;
|
||||
|
||||
/**
|
||||
* 将egret矩形转化为Rectangle
|
||||
* @param rect
|
||||
*/
|
||||
public setEgretRect(rect: egret.Rectangle): Rectangle{
|
||||
this.x = rect.x;
|
||||
this.y = rect.y;
|
||||
this.width = rect.width;
|
||||
this.height = rect.height;
|
||||
return this;
|
||||
// 将参考点设置为世界参考
|
||||
this._transformMat = Matrix2D.create().translate(-worldPosX - origin.x, -worldPosY - origin.y);
|
||||
this._tempMat = Matrix2D.create().scale(scale.x, scale.y);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
this._tempMat = Matrix2D.create().rotate(rotation);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
this._tempMat = Matrix2D.create().translate(worldPosX, worldPosY);
|
||||
this._transformMat = this._transformMat.multiply(this._tempMat);
|
||||
|
||||
// TODO: 这有点傻。我们可以把世界变换留在矩阵中,避免在世界空间中得到所有的四个角
|
||||
let topLeft = new Vector2(worldPosX, worldPosY);
|
||||
let topRight = new Vector2(worldPosX + width, worldPosY);
|
||||
let bottomLeft = new Vector2(worldPosX, worldPosY + height);
|
||||
let bottomRight = new Vector2(worldPosX + width, worldPosY + height);
|
||||
|
||||
topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
|
||||
topRight = Vector2Ext.transformR(topRight, this._transformMat);
|
||||
bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
|
||||
bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
|
||||
|
||||
let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
||||
let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
||||
let minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
||||
let maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
||||
|
||||
this.location = new Vector2(minX, minY);
|
||||
this.width = maxX - minX;
|
||||
this.height = maxY - minY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -231,7 +231,7 @@ module es {
|
||||
* @param y
|
||||
*/
|
||||
private getKey(x: number, y: number): string {
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString();
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
|
||||
}
|
||||
|
||||
public add(x: number, y: number, list: Collider[]) {
|
||||
|
||||
Reference in New Issue
Block a user