Skip to content

Commit

Permalink
refactor(view): add vector target viewToNormalizedCoords.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jan 26, 2021
1 parent 999851a commit b83a9c8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,13 @@ class View extends THREE.EventDispatcher {
/**
* Convert view coordinates to normalized coordinates (NDC)
* @param {THREE.Vector2} viewCoords (in pixels, 0-0 = top-left of the View)
* @param {THREE.Vector2} target
* @return {THREE.Vector2} - NDC coordinates (x and y are [-1, 1])
*/
viewToNormalizedCoords(viewCoords) {
_eventCoords.x = 2 * (viewCoords.x / this.camera.width) - 1;
_eventCoords.y = -2 * (viewCoords.y / this.camera.height) + 1;
return _eventCoords;
viewToNormalizedCoords(viewCoords, target = _eventCoords) {
target.x = 2 * (viewCoords.x / this.camera.width) - 1;
target.y = -2 * (viewCoords.y / this.camera.height) + 1;
return target;
}

/**
Expand Down

0 comments on commit b83a9c8

Please sign in to comment.