Commit f1502810 authored by rockyl's avatar rockyl

transform组价增加逆矩阵属性

parent 09b3eebd
......@@ -120,11 +120,8 @@ export default class InteractComponent extends ScillaComponent {
* @param e
*/
hitTest(e) {
const matrix = this.transform.getMatrix();
const invertMatrix = this.invertMatrix;
invertMatrix.copyFrom(matrix);
invertMatrix.invert();
invertMatrix.transformPoint(e.x, e.y, this.localPos);
const matrix = this.transform.getMatrix(false, true);
matrix.transformPoint(e.x, e.y, this.localPos);
let result = false;
const renderers = this.entity.getComponents(Renderer);
......
......@@ -32,6 +32,11 @@ export default class Transform extends ScillaComponent {
@dirtyFieldTrigger
position: Vector2D = new Vector2D(0, 0);
/**
* 全局坐标
*/
private _globalPosition: Vector2D = new Vector2D(0, 0);
/**
* 节点透明度
*/
......@@ -73,6 +78,7 @@ export default class Transform extends ScillaComponent {
protected _localMatrix: Matrix = Matrix.create();
protected _globalMatrix: Matrix = Matrix.create();
protected _globalInvertMatrix: Matrix = Matrix.create();
protected _globalPivotMatrix: Matrix = Matrix.create();
protected dirty: boolean;
......@@ -110,6 +116,14 @@ export default class Transform extends ScillaComponent {
}
}
/**
* 获取全局坐标
*/
get globalPosition(){
this._globalPosition.setXY(this._globalMatrix.tx, this._globalMatrix.ty);
return this._globalPosition;
}
makeDirty(value, key, oldValue?) {
this.dirty = true;
......@@ -183,6 +197,8 @@ export default class Transform extends ScillaComponent {
if (parentTransform) {
this._renderAlpha = parentTransform._renderAlpha * this.alpha;
_globalMatrix.concat(parentTransform.getMatrix(true));
}else{
this._renderAlpha = this.alpha;
}
}else{
this._renderAlpha = this.alpha;
......@@ -197,8 +213,17 @@ export default class Transform extends ScillaComponent {
/**
* 获取矩阵
*/
getMatrix(withPivot = false): Matrix {
return withPivot ? this._globalPivotMatrix : this._globalMatrix;
getMatrix(withPivot: boolean = false, invert: boolean = false): Matrix {
let matrix = withPivot ? this._globalPivotMatrix : this._globalMatrix;
if(invert){
const invertMatrix = this._globalInvertMatrix;
invertMatrix.copyFrom(matrix);
invertMatrix.invert();
return invertMatrix;
}
return matrix;
}
onUpdate(t) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment