"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Basic OpenGL drawing

Hi, I've done some OpenGL in C++ before with GLUT but everything in ImageTargets is overwhelming me. The basic stuff I've done in Java for Android wasn't nearly as involved. My first problem is trying to find out how to get the origin of a Trackable. Looking at the API I'm thinking it may be within the pose matrix? Once I have the origin I will be putting it into an array, and then I want to pass that array to glVertexPointer and then run glDrawArrays with a line strip. I see that in Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering is where the teapot is being rendered on each trackable. If I'm going to draw lines between the origin of each trackable, would I want to do my rendering here or somewhere else? Thanks!

Update on what I've gleaned from spending more time reading: The place where I want to be for rendering is Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame within the else for OpenGL ES 2.0 Also to get my origin I need to grab the floats out of the Vec2f which ImageTarget

Let me start with a post including some code that should be helpful. The next post will explain some things :) This is a replacement renderFrame method for the ImageTargets sample. It will render a line connecting the center of the chips target to the center of the stones target.

Okay, so that code is somewhat complex, because this is a complicated problem! The problem is that the pose matrix defines a local coordinate system for each trackable, with the center of the trackable as the origin (0, 0, 0).

Finally, you asked about the various OpenGL arrays: vertices[] - These are the 3D points that define your geometry. This array is always needed. texcoords[] - These are 2D U,V texture coordinates, one per vertex. They describe how to map a 2D image onto a 3D object.

Thanks a ton! I've got my project working perfectly. It first draws a red line between each trackable, in the order that they are picked up. When I click Nearest Neighbor in the menu it switches the line to the sorted order and turns blue.

Kim, can you translate this into code for unity? Preferably into .js I am not sure how to convert all this C++ matrix stuff into unity script. Thanks.

No need for this in Unity, the trackables are already brought into a unified coordinate system to work with the Unity game engine. You can refer to the transform.position values directly.

I cannot get that code to work. Can you provide some more information on how to get that to work? Where do I attach the script to? What objects do I drop on onto the inspector public variables? I Added two frame marker prefabs to the Hierarchy.

That should work, I added my script to the ARCamera but that shouldn't make a difference. Perhaps you need to create and bind a material.

Actually, adding that script to an empty gameobject won't work. Adding it to the ARCamera does. Binding a material doesn't make a difference. I agree with you that it shouldn't make a difference where you attach the script. But it does.