Hi,
Thank you verymuch for the quick help.
I forgot to mention in the previous post that I made video as background by
making "GL_DEPTH_BUFFER_BIT". That is I used "
_viewer->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT )".
I have a look at the code of osgAnroidExample. But I am not able to find any
specific info about camera settings in any of the C++ files.
If I assign the transformation matrix which I got from the 3rd Party AR library
then model is not appearing on the screen. If not assign the transformation
matrix then the model is appeared on the screen.
AR library is giving a projection matrix. I used
"_viewer->getCamera()->setProjectionMatrix(osg::Matrix(projectionMatrix.data));".
But even I am not able to see model on scree.
Here I listed the full OSG code with the transformation matrix
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/test.osg");
trans->addChild(loadedModel.get());
modelSwitch->addChild(trans.get());
}
_root->addChild(modelSwitch.get());
_viewer->setSceneData(NULL);
_viewer->setSceneData(_root.get());
_manipulator->getNode();
_viewer->home();
State state = Renderer::getInstance().begin();
// Explicitly render the Video Background
Renderer::getInstance().drawVideoBackground();
for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
{
//_viewer->getCamera()->setProjectionMatrix(osg::Matrix(projectionMatrix.data));
//NotGetting even I set projection matrix
// Get the trackable:
const Trackable* trackable = state.getActiveTrackable(tIdx);
Matrix44F modelViewMatrix =
Tool::convertPose2GLMatrix(trackable->getPose());
osg::Matrix mat;
mat.set(osg::Matrix(modelViewMatrix.data));
trans->setMatrix(mat);
osg::Vec3f tr,scal;
osg::Quat rot,so,rot1,rot2;
mat.decompose(tr,rot,scal,so);
_viewer->frame();
Renderer::getInstance().end();
break;
}
I logged the Transformation matrix and here I am giving two of them
Code:
0.953237 -0.0311842 0.300609 0
0.165658 -0.778015 -0.606012 0
0.252777 0.627472 -0.736467 0
16.6605 14.1914 162.78 1
Equalent OSG scale and Tranlate vectors (x,y,z values): 1 1 1 and 16.6605
14.1914 162.78
0.999434 0.0286711 0.0175895 0
0.0336364 -0.853354 -0.520246 0
9.4044e-05 0.520543 -0.853835 0
75.0211 38.932 197.853 1
Equalent OSG scale and Tranlate vectors (x,y,z values): 1 1 1 and 75.0211
38.932 197.853
3rdParty AR library gave an example to draw a teapot. Here I am giving that
code for the reference.
Code:
// Set GL11 flags:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
//getting tracker code and setting video code here (as above)
...............................
........................
// Load projection matrix:
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(projectionMatrix.data);
// Load model view matrix:
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(modelViewMatrix.data);
glTranslatef(0.f, 0.f, kObjectScale);
glScalef(kObjectScale, kObjectScale, kObjectScale);
// Draw object:
glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &teapotNormals[0]);
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
(const GLvoid*) &teapotIndices[0]);
I think I am missing some of the OSG settings.
Can you please help me what I am missing.
I am using OpenGLES1.
...
Thank you!
Cheers,
Koduri
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49775#49775
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org