Log in or register to post comments

Overlay disappears at specific distance

November 11, 2013 - 11:56am #1

Hi,

I have used the ImageTarget Example combined with a Code Snippet to augment an Image with a 2D Overlay. (the Code snippet is attached at the end.) This works wonderful. But : when I move away with my Phone at a specific Distance then the overlay disappears. If I hold it parallel to the Image then it disappears completely if not then it starts to disappear with the part which is further away from the phone.

Then I used this method to measure the distance :

 QCAR::Matrix34F pose = result->getPose();
        QCAR::Vec3F position(pose.data[3], pose.data[7], pose.data[11]);
        float distance = sqrt(position.data[0] * position.data[0] +
                              position.data[1] * position.data[1] +
                              position.data[2] * position.data[2]);
        LOG("distance: %f", distance);

the objects disapper with a distance of round about 2500.0 (float) 

Does anyone have a clue where i can increase this value ?

regards

 

Attachment

inserted into imagetargets cpp

QCAR::Vec2F tar
                        getSize = ((QCAR::ImageTarget *) &trackable)->getSize();
                        QCAR::Matrix44F modelViewProjection;
                        SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                                         &modelViewMatrix.data[0]);
                        SampleUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f,
                                                     &modelViewMatrix.data[0]);
                        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                                    &modelViewMatrix.data[0] ,
                                                    &modelViewProjection.data[0]);

                         glUseProgram(shaderProgramID);

                         glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                               (const GLvoid*) &planeVertices[0]);
                         glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                               (const GLvoid*) &planeNormals[0]);
                         glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                               (const GLvoid*) &planeTexcoords[0]);
                         glEnableVertexAttribArray(vertexHandle);
                         glEnableVertexAttribArray(normalHandle);
                         glEnableVertexAttribArray(textureCoordHandle);
                         glActiveTexture(GL_TEXTURE0);
                         glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
                         glEnable(GL_BLEND);
                                        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
                         glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                                            (GLfloat*)&modelViewProjection.data[0] );
                         glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
                                        (const GLvoid*) &planeIndices[0]);

 

AND at the top of the FIle imagetargets.cpp

#include <QCAR/ImageTarget.h>
static const float planeVertices[] =
{
    -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.5, 0.0, -0.5, 0.5, 0.0,
};
static const float planeTexcoords[] =
{
    0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0
};
static const float planeNormals[] =
{
    0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0
};
static const unsigned short planeIndices[] =
{
    0, 1, 2, 0, 2, 3
};
 

 

 

Overlay disappears at specific distance

November 12, 2013 - 12:58am #2

What you observe is simply due to the "far distance clip plane" which is an OpenGL setting to clip objects beyond a certain distance.

You can solve the issue by simply increasing the far distance (which is set exactly to 2500 in the sample, as you noticed) to some higher value (e.g. put 4000 or 5000 and you'll be safe).

The code is in ImageTargets.cpp:

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix(JNIEnv *, jobject)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix");

    // Cache the projection matrix:
    const QCAR::CameraCalibration& cameraCalibration =
                                QCAR::CameraDevice::getInstance().getCameraCalibration();
    projectionMatrix = QCAR::Tool::getProjectionGL(cameraCalibration, 2.0f, 2500.0f);
}

Just replace the 2500.0f with a higher value.

 

Log in or register to post comments