Skip to content

Instantly share code, notes, and snippets.

@anthonypena97
Created January 6, 2022 07:27

Revisions

  1. anthonypena97 created this gist Jan 6, 2022.
    13 changes: 13 additions & 0 deletions Pointer Coordinates
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // from work with three.js project

    // desktop pointer
    pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
    pointer.y = - (event.clientY / window.innerHeight) * 2 + 1;

    // mobile touch
    pointer.x = +(event.targetTouches[0].pageX / window.innerWidth) * 2 + -1;
    pointer.y = -(event.targetTouches[0].pageY / window.innerHeight) * 2 + 1;

    //mobile click
    pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
    pointer.y = - (event.clientY / window.innerHeight) * 2 + 1;