Commit f1502810 authored by rockyl's avatar rockyl

transform组价增加逆矩阵属性

parent 09b3eebd
...@@ -120,11 +120,8 @@ export default class InteractComponent extends ScillaComponent { ...@@ -120,11 +120,8 @@ export default class InteractComponent extends ScillaComponent {
* @param e * @param e
*/ */
hitTest(e) { hitTest(e) {
const matrix = this.transform.getMatrix(); const matrix = this.transform.getMatrix(false, true);
const invertMatrix = this.invertMatrix; matrix.transformPoint(e.x, e.y, this.localPos);
invertMatrix.copyFrom(matrix);
invertMatrix.invert();
invertMatrix.transformPoint(e.x, e.y, this.localPos);
let result = false; let result = false;
const renderers = this.entity.getComponents(Renderer); const renderers = this.entity.getComponents(Renderer);
......
...@@ -32,6 +32,11 @@ export default class Transform extends ScillaComponent { ...@@ -32,6 +32,11 @@ export default class Transform extends ScillaComponent {
@dirtyFieldTrigger @dirtyFieldTrigger
position: Vector2D = new Vector2D(0, 0); position: Vector2D = new Vector2D(0, 0);
/**
* 全局坐标
*/
private _globalPosition: Vector2D = new Vector2D(0, 0);
/** /**
* 节点透明度 * 节点透明度
*/ */
...@@ -73,6 +78,7 @@ export default class Transform extends ScillaComponent { ...@@ -73,6 +78,7 @@ export default class Transform extends ScillaComponent {
protected _localMatrix: Matrix = Matrix.create(); protected _localMatrix: Matrix = Matrix.create();
protected _globalMatrix: Matrix = Matrix.create(); protected _globalMatrix: Matrix = Matrix.create();
protected _globalInvertMatrix: Matrix = Matrix.create();
protected _globalPivotMatrix: Matrix = Matrix.create(); protected _globalPivotMatrix: Matrix = Matrix.create();
protected dirty: boolean; protected dirty: boolean;
...@@ -110,6 +116,14 @@ export default class Transform extends ScillaComponent { ...@@ -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?) { makeDirty(value, key, oldValue?) {
this.dirty = true; this.dirty = true;
...@@ -183,6 +197,8 @@ export default class Transform extends ScillaComponent { ...@@ -183,6 +197,8 @@ export default class Transform extends ScillaComponent {
if (parentTransform) { if (parentTransform) {
this._renderAlpha = parentTransform._renderAlpha * this.alpha; this._renderAlpha = parentTransform._renderAlpha * this.alpha;
_globalMatrix.concat(parentTransform.getMatrix(true)); _globalMatrix.concat(parentTransform.getMatrix(true));
}else{
this._renderAlpha = this.alpha;
} }
}else{ }else{
this._renderAlpha = this.alpha; this._renderAlpha = this.alpha;
...@@ -197,8 +213,17 @@ export default class Transform extends ScillaComponent { ...@@ -197,8 +213,17 @@ export default class Transform extends ScillaComponent {
/** /**
* 获取矩阵 * 获取矩阵
*/ */
getMatrix(withPivot = false): Matrix { getMatrix(withPivot: boolean = false, invert: boolean = false): Matrix {
return withPivot ? this._globalPivotMatrix : this._globalMatrix; let matrix = withPivot ? this._globalPivotMatrix : this._globalMatrix;
if(invert){
const invertMatrix = this._globalInvertMatrix;
invertMatrix.copyFrom(matrix);
invertMatrix.invert();
return invertMatrix;
}
return matrix;
} }
onUpdate(t) { 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