Android - How do I project a screen touch onto the target?

August 10, 2012 - 2:20pm #1

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:

  1. 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
  2. Copy the projectScreenPointToPlane and linePlaneIntersection methods from Dominoes.cpp ( on iOS) to your project.
  3. Create a "QCAR::Matrix44F modelViewMatrix" global variable, and set it in the renderFrame method.
  4. 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).
  5. 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);

Topic locked