Log in or register to post comments

multiple objects at different position on ImageTarget

May 7, 2012 - 8:16am #8

I am new to OpenGL and could not identify the lines of Code in the ImageTarget example that I need to modify for my aim. So I hope somebody can help:

I'd like to place one or more objects on the image target (could go with the teapot for now, but it should be something like a simple marker at the end). Their number and position changes according to interactions in the android app. So I need to pass the coordinates to the native code. But where exactly is the position of the teapot defined? It is center of the target by default but I would like to have other positions/coordinates. Where can I define this?

Re: multiple objects at different position on ImageTarget

May 7, 2012 - 2:30pm #7

You can translate 3D objects in target space using the translatePoseMatrix method. See the renderFrame method in ImageTargets.cpp:

        SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                         &modelViewMatrix.data[0]);

That translates the object up the Z axis by a fixed amount. Here's the coordinate system of the target: https://ar.qualcomm.at/resources/images/coordinateSystems.jpg

- Kim

Re: multiple objects at different position on ImageTarget

May 8, 2012 - 7:35am #6

Thank you that worked out well! Now I'd like to place several objects on the image target. I tried to set different coordinates again by calling SampleUtils::translatePoseMatrix... and then call again the glDrawElements function but without any effect.
How could I draw several objects lets say from an array with coordinates?

Re: multiple objects at different position on ImageTarget

May 9, 2012 - 1:21pm #5

You'll want to start with a fresh copy of the modelview matrix for each object:

modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

Then you can transform the matrix and feed it to the shader:

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                   (GLfloat*)&modelViewProjection.data[0] );

Finally render using glDrawElements. If you're using the same model you don't need to rebind the vertex attribs or texture.

- Kim

multiple objects at different position on ImageTarget

August 29, 2012 - 4:52pm #4

I have teaport image and I want my teapot to be at suppose say 4 places on the stones image.

What should I do ?

Do I just need different poseMatrix for all of them ?  Since the line is in for loop should I have 4 tracable objects for 4 teapots and then find the pose matrix ?

 

modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

multiple objects at different position on ImageTarget

September 7, 2012 - 12:15pm #3

You don't need to use multiple trackable instances, and can utilize the same pose matrix. The pose matrix is describing the position and orientation of the parent trackable.

The ImageTargets sample uses the following set of transforms to position the model:

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.

If you have four models, and wish to place them all at different positions on the same target, you can loop through these operations and the render steps for each model to position each at a different point on the target. You'll just need to substitute the model's arrays in these steps ..

 

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotVertices[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotTexCoords[0]);
       
        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
       
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

multiple objects at different position on ImageTarget

September 17, 2017 - 10:12pm #2

I am trying to render more than one image on a target image , i am a beginner in opengl, can you please explain in detail about this.

multiple objects at different position on ImageTarget

September 21, 2017 - 10:34am #1


Hello Yashu94.

This thread covers using OpenGL to render multiple models on an Image Target. If you're looking for a more detailed introduction on using OpenGL, I'd recommend looking for an online tutorial or book that goes over the basics.

Thanks,

-Vuforia Support

Log in or register to post comments