Skip to content

Commit

Permalink
feat(scenegraph): add global/local point mapping methods
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 8, 2019
1 parent 84d2a8b commit 3906c4c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/scenegraph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,34 @@ export class Node2D implements ISceneNode<Node2D>, IToHiccup {
return n;
}
}
const q = mulV23([], this.invMat, p);
const q = this.mapGlobalPoint(p);
if (this.containsLocalPoint(q)) {
return { node: this, p: q };
}
}
}

/**
* Returns copy of world space point `p`, transformed into this
* node's local coordinate system.
*
* @param p
*/
mapGlobalPoint(p: ReadonlyVec) {
return mulV23([], this.invMat, p);
}

/**
* Returns copy of node local space point `p`, transformed into the
* coordinate system of `dest` node.
*
* @param dest
* @param p
*/
mapLocalPointToNode(dest: Node2D, p: ReadonlyVec) {
return mulV23(null, dest.invMat, mulV23([], this.mat, p));
}

/**
* Returns true, if given point is contained within the boundary of
* this node. Since this class is used as generic base
Expand Down

0 comments on commit 3906c4c

Please sign in to comment.