The ImageTargets sample shows how to augment an image target with a simple 3D model (a teapot model); the code to position and scale the 3D model on top of the detected target is located in the renderFrame() function in the ImageTargets.cpp file; such code sets the modelview matrix that will be used for the 3D model in OpenGL, starting with the trackable pose (w.r.t. the camera) and then applying a set of transformations.
The sample code, in particular, applies a translation and a scaling operation by using some sample utility functions, as shown in the following code snippet (extracted from the sample):
QCAR::Matrix44F modelViewProjection; SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]); SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]);
In order to also apply a rotation to the 3D model, around one of its local axes, it is sufficient to add another sample utility function call specifically for the rotation part:
QCAR::Matrix44F modelViewProjection; SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]); float angle = 0.0f; // YOUR ROTATION ANGLE HERE (in degrees) SampleUtils::rotatePoseMatrix(angle, 0.0f, 0.0f, 1.0f, &modelViewMatrix.data[0]); SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]);