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.
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