OpenGL - How do I scale and/or position my models?

August 10, 2012 - 2:04pm #1
Sizing and positioning the 3D content

Now that the trackables are sized correctly, we can position and scale the 3D content to sit correctly on the target. By default, the pose matrix will place content in the center of the target with X to the right, Y to the top, and Z coming out of the target: https://ar.qualcomm.at/resources/images/coordinateSystems.jpg We can apply translations, rotations, and scales to the pose matrix to make the final modelview matrix. The ImageTargets sample uses the following set of transforms:

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]);

 

Note that the transforms are applied from bottom to top. In this case, the model is scaled by kObjectScale and then translated up the Z axis by kObjectScale. You can obtain the trackable size of image targets and frame markers at runtime by casting the Trackable object to the specific class (ImageTarget or Marker) and calling the getSize() method. For MultiTargets you can query the size of individual Parts. See the code snippets in this article for an example of sizing a plane to match a target: TexturedPlaneOnTarget.xml

 

Topic locked