Log in or register to post comments

3D model is not rendering with OSG render lib

September 3, 2012 - 5:39am #1

Hi,

I am new to Qualcomm SDK. I did ImageTargets sample on my Android device.

Now I am trying to replace tea pot with some 3D object.

To render 3D object i choosed OpenSceneGraph (OSG) library.

I successfully added OSG rendering code to ImageTargets example.

 

This is the code I added to "renderFrame" method.

 if(mload)//to init OSG
  {
     
        LOG("Init==============");  
  int x=0;
  int y=0;

  int width=screenWidth;
  int height=screenHeight;

  _viewer = new osgViewer::Viewer();
    _viewer->setUpViewerAsEmbeddedInWindow(x, y, width, height);
     _root = new osg::Group();

    _viewer->realize();
    _state = _root->getOrCreateStateSet();
    _state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
    _state->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
    _state->setMode(GL_CULL_FACE, osg::StateAttribute::ON);

    _viewer->setSceneData(_root.get());

    _viewer->addEventHandler(new osgViewer::StatsHandler);
    _viewer->addEventHandler(new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet()));
    _viewer->addEventHandler(new osgViewer::ThreadingHandler);
    _viewer->addEventHandler(new osgViewer::LODScaleHandler);

 _manipulator = new osgGA::KeySwitchMatrixManipulator;

    _manipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
    _manipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
    _manipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
    _manipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
    _manipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() );
    _manipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() );
    _manipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() );

    _viewer->setCameraManipulator( _manipulator.get() );

    _viewer->getViewerStats()->collectStats("scene", true);
     //config.mSize.data[0] = screenWidth;
      //  config.mSize.data[1] = videoMode.mHeight * (screenWidth / (float)videoMode.mWidth);

_viewer->getCamera()->setViewport(0,0,800, 600);
//_viewer->setLightingMode(osg::View::HEADLIGHT);
    _viewer->getCamera()->setProjectionMatrix(osg::Matrix(projectionMatrix.data));

trans=new osg::MatrixTransform();
   
   
    LOG("Load Model");
  osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("/mnt/sdcard/OSG/lz.osg");
  if (loadedModel == 0) {
            LOG("Model not loaded");
        } else {
            LOG("Model loaded");
           

            loadedModel->setName("/mnt/sdcard/OSG/lz.osg");
            //_root->addChild(loadedModel);
            trans->addChild(loadedModel.get());
        }
       
  _root->addChild(trans.get());

        _viewer->setSceneData(NULL);
    _viewer->setSceneData(_root.get());
     _manipulator->getNode();
    _viewer->home();

    _viewer->getDatabasePager()->clear();
    _viewer->getDatabasePager()->registerPagedLODs(_root.get());
    _viewer->getDatabasePager()->setUpThreads(3, 1);
    _viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(2);
    _viewer->getDatabasePager()->setUnrefImageDataAfterApplyPolicy(true, true);
    mload=false;
  }
 

 

 _viewer->frame();// called every time

 

only with this code the model is rendering on the screen.

 

But the 3D model is not rendering when I draw video background. That is when I added this statement "QCAR::Renderer::getInstance().drawVideoBackground();" the model is not redering on the screen.

I tried to setting the viewPort and projection matrix to OSG. But still the model is not rendering on the screen.

 

Can you please help me where am i doing the mistake.

 

Thanks & Regards

ANReddy.

 

 

3D model is not rendering with OSG render lib

September 14, 2012 - 3:09am #5

Hi,

Thank you very much for the help.

I tried as your guidence. But still the model is not appeared in the screen.

Here is the code what I did

const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
const QCAR::ImageTarget* imageTarget = static_cast<const QCAR::ImageTarget*>(trackable);
QCAR::Vec2F targetSz = imageTarget->getSize();
QCAR::Matrix44F modelViewMatrix =         QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

QCAR::Matrix44F modelViewProjection;

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

SampleUtils::scalePoseMatrix(targetSz.data[0], targetSz.data[0], targetSz.data[0],&modelViewMatrix.data[0]);

SampleUtils::multiplyMatrix(&projectionMatrix.data[0],&modelViewMatrix.data[0] ,&modelViewProjection.data[0]);

osg::Matrix mat;
mat.set(osg::Matrix(modelViewProjection.data));

(After this OSG renders according to the matrix)

I am not getting the model on screen even if I replace  "targetSz.data[0]"  with "kObjectScale"

Please can you help me how to solve this problem.

 

I am using Android 2.2.1 and kernal version as 2.6.32.9

 

3D model is not rendering with OSG render lib

September 6, 2012 - 9:23am #4

The pose matrix describes the position and orientation of the target from the camera perspective. The ModelView matrix describes the position of the model in relation to the target. So try modifying the modelview matrix to adjust the position of your model.

By default, the pose matrix will place content in the center of the target with X to the right, Y to the top, and Z coming out of the target: https://ar.qualcomm.at/resources/images/coordinateSystems.jpg

We can apply translations, rotations, and scales to the pose matrix to make the final modelview matrix. The ImageTargets sample uses the following set of transforms:

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. You can obtain the trackable size of image targets and frame markers at runtime by casting the Trackable object to the specific class (ImageTarget or Marker) and calling the getSize() method. For MultiTargets you can query the size of individual Parts.

3D model is not rendering with OSG render lib

September 6, 2012 - 2:59am #3

Hi,

I did some experiments with QCAR. I decomposed the QCAR Pose matrix (from Matrix44f) into transilation, scale and rotation vectors and checked with each one.

I got model on my screen with all vectors except translate vector. If I set the extracted translated vector (used matrix multiplication to use scale and rotation vectors) then model is not on the screen.

I got some of the translation vectors in LOGCat like 17.98    14.45    155.76 etc. With these translation the model is not displayed on the screen. If I set translation vector as 0.0 0.0 1.0 then the model is displayed on the scree.

Why I am not able to reder the model correctly with the ranslation values which I got from QCAR pose matrix? Do I need to add any other statements?

I am using OpenGLES1.  I set the flag USE_OPENGL_ES_1_1  to true in "Android.mk" file.

3D model is not rendering with OSG render lib

September 3, 2012 - 1:25pm #2

I haven't worked w/ OSG before, but if you can PM me w/ a link to your code, I'll take a look at it.

Log in or register to post comments