Hi,
Hi, I am new to Android programming. I followed the osgAndroidExampleGLES1 and developed a small example. It is working well but have a small issue. First of all I will give my complete code here Code: #include"osgModel.hpp" OsgMainApp osgM; void OsgMainApp::readModel() { loadedModel = osgDB::readNodeFile("/mnt/sdcard/OSG/Piller.osg"); if (loadedModel == 0) { LOG("Model not loaded"); } else { LOG("Model loaded"); loadedModel->setName("/mnt/sdcard/OSG/Piller.osg"); } } void OsgMainApp::initOsgWindow(int sW,int sH) { x=0; y=0; width=sW; height=sH; _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 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); _viewer->getCamera()->setViewport(0,0,sW, sH); _viewer->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT ); modelSwitch=new osg::Switch; trans=new osg::MatrixTransform(); trans->addChild(loadedModel.get()); modelSwitch->addChild(trans.get()); _root->addChild(modelSwitch.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); } void OsgMainApp::renderOsg(osg::Matrix mat) { modelSwitch->setAllChildrenOff(); modelSwitch->setChildValue(trans,1); osg::Vec3f tr,scal; osg::Quat rot,so,rot1,rot2; mat.decompose(tr,rot,scal,so); rot1=rot; rot2=rot; rot.makeRotate(osg::DegreesToRadians(45.0),1,0,0); rot2.makeRotate(osg::DegreesToRadians(180.0),0,1,0); trans->preMult(osg::Matrix::rotate(rot1)); trans->preMult(osg::Matrix::rotate(rot)); trans->preMult(osg::Matrix::rotate(rot2)); //trans->preMult(osg::Matrix::scale(osg::Vec3(0.5,0.5,0.5))); _viewer->frame(); } JNIEXPORT void JNICALL Java_com_Samples_initApplicationNative( JNIEnv* env, jobject obj, jint width, jint height) { screenWidth = width; screenHeight = height; osgM.initOsgWindow(screenWidth,screenHeight); osgM.readModel(); } JNIEXPORT void JNICALL Java_com_Samples_renderer( JNIEnv* env, jobject obj, jint width, jint height) { //osgM.initOsgWindow(screenWidth,screenHeight); //ERROR IS WITH THIS osg::Matrix mat; mat=osg::Matrix::scale(osg::Vec3(1.5,1.5,1.5)); osgM.renderOsg(mat); } In this code I called initOsgWindow and readModel in "Java_com_Samples_initApplicationNative". In "Java_com_Samples_renderer" function I am calling "renderOsg". If I call only this function then the model is not appearing on the screen. If I call "initosgWindow" also then the model appears on the screen. But my model has some animation so the animation is playing incorrect as the osg is setting every time. I have gone through the "osgAndroidExampleGLES1" several times. But I am not able to figure out the error? What could be the mistake to reset the osg settings every time? ... Thank you! Cheers, Koduri ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50227#50227 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org