The Dominoes sample includes code for projecting a touch point in screen space onto the target plane. A user can pull this functionality into his own app using the following steps:
- Copy SampleMath.h and SampleMath.cpp from the Dominoes sample to your project. On Android, be sure to add SampleMath.cpp to the LOCAL_SRC_FILES variable in Android.mk.
- Copy the projectScreenPointToPlane and linePlaneIntersection methods from Dominoes.cpp (Dominoes.mm on iOS) to your project.
- Create a "QCAR::Matrix44F modelViewMatrix" global variable, and set it in the renderFrame method.
- On Android, create a "QCAR::Matrix44F inverseProjMatrix" global variable, and set it after initializing the projection matrix (see the setProjectionMatrix method in QCARBase.cpp in the Dominoes sample).
- Call the projectScreenPointToPlane method as follows:
QCAR::Vec3F intersection, lineStart, lineEnd;
projectScreenPointToPlane(QCAR::Vec2F(touch.x, touch.y), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);