Log in or register to post comments

3D Model moves slightly when moving around the marker

December 9, 2011 - 3:21am #1

Hi.

We use an external 3D engine to display a custom model on top of the marker. To affix the model on the marker, we use the getPose() method in native code to return us a float array that we use to set our camera matrix. This works perfectly except for on thing, if we move our device around our marker, the model always translates a bit.
So if we look at the dead center of our marker, our model is in the center. If we move our device a bit to the left (so that the left boarder of the marker is in the center of our camera) the model is not anymore at the center of the marker, but a bit to the left. This is not the case with the supplied samples (i.e. Teapot in ImageTargets) and independent of the QCAR version (1.0.6 or the 1.5 beta).
Any idea why that is? I guess we need to add some kind of "compensation" on the pose matrix, but depending on which values?

3D Model moves slightly when moving around the marker

March 14, 2013 - 2:55am #12

Hi, if you search the Forum, you will find that people have integrated various rendering engines with Vuforia, from Ogre (c++) to Irrlicht,  to jMonkey, jPCT and min3D on Java;

if you plan to code primarily in Java (at least for the rendering part), one option used by many developers on this Forum is JPCT-ae; there is also a good tutorial on how to integrate it in Vuforia (step-by-step):

http://www.jpct.net/wiki/index.php/Integrating_JPCT-AE_with_Vuforia

 

3D Model moves slightly when moving around the marker

March 14, 2013 - 2:45am #11

I'm working on android platform

3D Model moves slightly when moving around the marker

March 13, 2013 - 2:27am #10

Hi stage.satge2013

what platform are you interested in ? Android / iOS / Unity ?

 

3D Model moves slightly when moving around the marker

March 13, 2013 - 2:18am #9

Hi

can i use an external 3D engine to make different  objects?Are you working with unity?

Re: 3D Model moves slightly when moving around the marker

December 22, 2011 - 3:32am #8

I'm not sure what exactly was the solution, but I guess it were the adjusted FoV values, since I hadn't any luck with the translation/rotation values. Thanks!

Another thing: Is it possible to get the x/y/z rotation values from the pose matrix?

Edit: Nevermind, got it working with the code from here: http://www.geometrictools.com/Documentation/EulerAngles.pdf (Section 2.1)

Re: 3D Model moves slightly when moving around the marker

December 16, 2011 - 8:34am #7

That's right, the pose is a standard rotation/translation matrix, you should be able to extract meaningful values from it. The format you listed looks right.

I had another thought regarding your problem: this might be an issue with the FOV (field of view) used by the projection matrix. QCAR uses a FOV that is device-specfic. Unfortunately we do not make this directly available through the SDK, but but you should be able to calculate it using the CameraCalibration getSize and getFocalLength values. Look here for some help with the math: http://paulbourke.net/miscellaneous/lens/

- Kim

Re: 3D Model moves slightly when moving around the marker

December 15, 2011 - 11:48am #6

Does the matrix returned by getPose() contain translation information, that you can directly read out? I read somewhere here that its a standard 3x4 transformation matrix. Your FastCV toolkit uses the following format for its pose matrices, is it the same for QCAR?

r1, r2, r3, t1,
r4, r5, r6, t2,
r7, r8, r9, t3

If so, I would probably need to extract the translation information and set it as the position vector of the camera (and the rotation as the rotation/backbuffer matrix).

Re: 3D Model moves slightly when moving around the marker

December 13, 2011 - 1:42am #5

QCAR uses a right-handed coordinate system, so do make sure that the engine is using a right-handed coordinate system for its projection. I'm guessing it does given that the content is lining up at all.  Now that you mention it, jPCT uses system that is rotated by 180° around the x-axis. But somehow the returned matrix in the correct format, since our object is placed right on the marker and we don't do any conversions to the matrix. I tried rotating the matrix by 180° around x, but then our object is not on the marker anymore. Both QCAR and jPCT use row-major matrices.  Is there any rotational offset when you rotate the target in front of the device?  No, rotating is fine. As are y and z translations. The distortion only show if we "translate" the device on the x axis (moving it left and right).  Is it possible for you to introduce a custom projection matrix to your 3D engine? Unfortunately not.

Re: 3D Model moves slightly when moving around the marker

December 12, 2011 - 10:55am #4

It sounds like your engine is now using the same viewport that QCAR is using to render the video. That's a good first step, and means you no longer need the projection matrix fix I provided above. I'm surprised this didn't completely fix the problem though...

QCAR uses a right-handed coordinate system, so do make sure that the engine is using a right-handed coordinate system for its projection. I'm guessing it does given that the content is lining up at all.

Is there any rotational offset when you rotate the target in front of the device?

Is it possible for you to introduce a custom projection matrix to your 3D engine?

- Kim

Re: 3D Model moves slightly when moving around the marker

December 12, 2011 - 1:44am #3

Thanks, but that didn't seem to be the reason for the slight translations.
From how I understand your code you modify the projection matrix to use a different aspect ratio. Since we use the modelview matrix for our object, maybe we need to apply the code on the latter?

But your suggestion with the different viewport sizes solved another issue we had (our model was "squished" if we rotated our device). We use an external 3D engine (jPCT-ae), so we don't really have much influence what it internally does. I searched if we maybe anywhere passed a specific screen size to the engine and ended up changing the size of the FrameBuffer() object jPCT uses for rendering stuff, to the slightly larger viewport size QCAR uses (to 1280x960 instead of 1280*720) and the deformation is gone.

Re: 3D Model moves slightly when moving around the marker

December 9, 2011 - 2:43pm #2

A first guess is that you are resetting the viewport in your custom 3D engine. With QCAR, the camera image is rendered to a viewport that is slightly larger than the screen, as the camera image aspect ratio is typically different than the screen aspect ratio. If you let your engine reset the viewport to fit the screen you end up compressing the 3D objects in relation to the camera image. That could result in the sort of bug you're talking about here.

You have two options:

1. Make sure your engine doesn't call glViewport.
2. Fix the projection matrix to work with a screen sized viewport:

ImageTargets.cpp

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_startCamera(JNIEnv *, jobject)
{
    ***
 
    // Cache the projection matrix:
    const QCAR::Tracker& tracker = QCAR::Tracker::getInstance();
    const QCAR::CameraCalibration& cameraCalibration =
                                    tracker.getCameraCalibration();
    projectionMatrix = QCAR::Tool::getProjectionGL(cameraCalibration, 2.0f,
                                            2000.0f);
    
    QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();
    
    int viewportWidth = config.mSize.data[0];
    int viewportHeight = config.mSize.data[1];
    
    if (viewportWidth != screenWidth)
    {
        float viewportDistort = viewportWidth / (float) screenWidth;
        projectionMatrix.data[0] *= viewportDistort;
    }
    
    if (viewportHeight != screenHeight)
    {
        float viewportDistort = viewportHeight / (float) screenHeight;
        projectionMatrix.data[5] *= viewportDistort;
    }
}

- Kim

Log in or register to post comments