Log in or register to post comments

How To disable pose updates on a rendered model - aka Freezing a model, Disabling 'Tracking'

July 8, 2012 - 2:27pm #1

We've gotten several inquiries on how to cause a model to be rendered in a static pose after its target has initially been detected, such that it does not follow the target. Some devs have referred to this operation as disabling Tracking, but this is typically not actually what they are attempting - rendering a model in relation to the pose of a Trackable is distinct from the process of Tracking the target. Here the conventional use of 'tracking' is not technically correct.

The following demonstrates a simple method for rendering a model in a static pose once an associated Trackable has been detected. This is based on the Android ImageTargets sample, and will cause the Teapot model to be rendered in the original pose at which the target is detected and to maintain that pose while the target it is in view regardless of the subsequent position of the target.

 

In ImageTargets.cpp @ ln 75, under the definition of the projectionMatrix, add the following..

 

// The projection matrix used for rendering virtual objects:
QCAR::Matrix44F projectionMatrix;
// The ModelView Projection Matrix that stores the original pose of the model
QCAR::Matrix44F stableModelViewProjection;
// a boolean flag indicating whether to render the model in a static pose
bool modelPoseIsStatic = false;

and then copy the following code to lines 386 - 402

 

        if( !modelPoseIsStatic ){

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

            stableModelViewProjection = modelViewProjection;
            modelPoseIsStatic = true;

        }else{

            modelViewProjection = stableModelViewProjection;
        }

 

You're simply wrapping the original section, which updates the modelViewProjection with a conditional statement that incorporates a branch in which the projection is assigned from a copy of the original model pose. You'll notice that stableModelViewProjection is defined in the first instance from the original modelViewProjection generated by multiplying the projectionMatrix, which is based on the camera's intrinsic calibration parameters, and the modelViewMatrix from the Trackable's pose. After this occurs, the modelPoseIsStatic flag is set to true, which prevents the stableModelViewProjection from being subsequently redefined, and forces the modelViewProjection used for rendering to be defined from stableModelViewProjection. You can set modelPoseIsStatic elsewhere (e.g. an event handler ) to customize this behavior.

* this example assumes that you are using OpenGL ES 2.0

How To disable pose updates on a rendered model - aka Freezing a

September 18, 2012 - 11:33pm #4

This is very usefull tip, thanks. But i need to keep the object on screen even when trackable is out, after once it captured. So far, i've done:

 

 int textureId = 0;

// Did we find any trackables this frame?

for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)    {

// found trackable

 trackableCaptured = true;

...

textureId = textureIndex;

...

}

 

 // if there is no trackable on screen

    // but at least one trackable has captured once

    if(state.getNumActiveTrackables() == 0 && trackableCaptured) {


    LOG("Captured trackable, but it's not on screen now");


    QCAR::Matrix44F modelViewProjection;


    SampleUtils::translatePoseMatrix(0.0f, 0.0f, 0.0f,

&modelViewMatrix.data[0]);

SampleUtils::scalePoseMatrix(1.0f, 1.0f, 0.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);


        const Texture* const thisTexture = textures[textureId];

        LOG("TextureId: % d", thisTexture->mTextureID);


        glActiveTexture(GL_TEXTURE0);

        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,

                           (GLfloat*)&modelViewProjection.data[0] );


        glDrawElements(GL_TRIANGLES, NUM_PLANE_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &planeIndices[0]);


    }

 

    glDisable(GL_DEPTH_TEST);

 

 

But i'm getting object at last position, which is mostly on corner... How can i move it to center? Any help please?

I found which coordinates my object needs to go, lets assume that x: 130.000000 y:300.000000

But when i code like:

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

the object disappears from screen. What am i doing wrong? 

 

Thanks,

yaya

How To disable pose updates on a rendered model

July 27, 2012 - 10:33am #3

Yes the objects are rendered in relations to the camera perspective. What do you want to accomplish? - to freeze the model in a fixed screen position, or its world space? The first will retain the objects position relative to the camera, the second will decouple the object from both the target and camera.

How To disable pose updates on a rendered model

July 25, 2012 - 10:07am #2

I realize this is an Android specific solution (in the Android forums, no less) but what would be the best way to approach this in the Unity project, in particular for use with FrameMarkers? I'm guessing that it's not nearly as simple due to the nature of the camera position updates, but does that mean that Unity is rendering the objects based on the camera positioning by QCAR?

Log in or register to post comments