Hi Jordi Torres,

Thanks a lot for the nice help.

To day I did some experiments. 

The AR library is giving pose matrix. Now I decomposed it into tans, rotation 
and scale vectors. And checked with each one by matrix multiplication. I found 
that the translation vector is irrelevant. I got transpose as like   17.98  
14.45 155.76 ect. With these values the model is not appread on the screen.  If 
I set the trans vect as 0.0 0.0 1 then the model is at the center of the screen.

I don't know why this behavior. I am posting in QCAR forum for help.

Is there any think I need to to with OSG?

Here is the complete code again 


Code:
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->addEventHandler(new 
osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet()));


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

    

    _viewer->getCamera()->setViewport(0,0,screenWidth, screenHeight);
    

    _viewer->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT );



    modelSwitch=new osg::Switch;
    trans=new osg::MatrixTransform();

    
    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");
    
    trans->addChild(loadedModel.get());
    modelSwitch->addChild(trans.get());
    }

    _root->addChild(modelSwitch.get());

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


    mload=false;
    }
    modelSwitch->setAllChildrenOff(); 
    modelSwitch->setChildValue(trans,1);





    State state = Renderer::getInstance().begin();
    // Explicitly render the Video Background
    Renderer::getInstance().drawVideoBackground();

    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {
    
      // Get the trackable:
      const Trackable* trackable = state.getActiveTrackable(tIdx);
      Matrix44F modelViewMatrix = 
Tool::convertPose2GLMatrix(trackable->getPose());




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


      osg::Vec3f tr,scal;
      osg::Quat rot,so,rot1,rot2;
      mat.decompose(tr,rot,scal,so);


      mat=osg::Matrix( 
osg::Matrix::scale(osg::Vec3(scal.x(),scal.y(),scal.z()))  * 
osg::Matrix::translate(0.0,0.0,1.0) * osg::Matrix::rotate(rot));

      trans->setMatrix(mat);

      _viewer->frame();
      Renderer::getInstance().end();
      break;
    }




I am reading the OSG model every time while rendering. That is for every 
viewer->frame(). If not reading the model is displayed only once. Do I need to 
take any clean up steps after viewer->frame().

Once again I will go through osgAndroid ( https://gitorious.org/osgandroid ) 
example.
 
Once again thank you very much for the nice help.



... 

Thank you!

Cheers,
Koduri

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49799#49799




_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to