Search code examples
javascriptspark-ar-studio

How to translate gesture pixel location to local X,Y coordinates in Spark AR


I am using Spark AR Studio. When I use gestures like tap or pan, I get the position in pixels on the screen. I want to be able to it the values in local coordinates, to know for example, if a 3D object is tapped.

For example, for the "iPhone 8" simulation within Spark AR I get:

Screen Scale: 2
Screen Size: 750, 1334

Spark AR uses X/Y coordinate system with the center point at 0,0.


Solution

  • for detecting if a 3D object is tapped, you can use a producer patch of your object with an patch "Object tap".

    for converting the screen position to a canvas position, you can use this patch system below, it use the device patch so it should work with all device automatically :

    enter image description here