Hi,

yeah. I found my geometry center as ( 0.04,0.075,0.0).  So first I do the 
rotation of 90 degree about z-axis and then translating my geometry to 0 by 
subtracting the aboive center values.
Again I m getting  my geometry is translated and half of the geometry is off 
the view. Have a look at my code, I dont understand where I am making mistake.

void applyTexture(osg::Drawable* drawable, std::string imgName)
{
    static std::string filePath = getenv("OSGHOME");
    osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filePath + imgName);
    osg::ref_ptr<osg::Texture2D> tex2D = new osg::Texture2D;
    tex2D->setImage(image.get());
    tex2D->setResizeNonPowerOfTwoHint(false);
    drawable->getOrCreateStateSet()->setTextureAttributeAndModes
        (0, tex2D.get());
    drawable->getOrCreateStateSet()->setMode(GL_LIGHTING,                       
                            osg::StateAttribute::OVERRIDE |       
osg::StateAttribute::OFF);
    osg::ref_ptr<osg::TexEnv> texEnv = new osg::TexEnv;
    texEnv->setMode(osg::TexEnv::REPLACE);
    drawable->getOrCreateStateSet()->setTextureAttributeAndModes
        (0, texEnv.get());  
}

osg::Geode* createGeometry()
{
              float x = 0.0, y = 0.0;
              float width=0.08 , height=0.15 ;
              std::string imgName="\\images\\ring_active.png";
              osg::Geometry* boxGeom = new osg::Geometry;

    boxGeom->setName("myGeometry");
    osg::Vec3Array* vertices = new osg::Vec3Array;
    int _z=0.0;
    vertices->push_back(osg::Vec3(x,  y, _z));
    vertices->push_back(osg::Vec3(x + width, y, _z));
    vertices->push_back(osg::Vec3(x + width, y + height, _z));
    vertices->push_back(osg::Vec3(x, y + height , _z));
    boxGeom->setVertexArray(vertices);
    osg::Vec3Array* normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0.0f,50.0f,1.0f));   
    boxGeom->setNormalArray(normals);
    boxGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back(osg::Vec4(0., 0., 0., 0.9));
    boxGeom->setColorArray(colors);
    boxGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
    //applying texture
    osg::ref_ptr<osg::Vec2Array> texCoordArray = new osg::Vec2Array;  
    texCoordArray->push_back(osg::Vec2(0.f, 0.f));
    texCoordArray->push_back(osg::Vec2(1.0, 0.f));
    texCoordArray->push_back(osg::Vec2(1.0, 1.0));
    texCoordArray->push_back(osg::Vec2(0.0, 1.0));      
    boxGeom->setTexCoordArray(0, texCoordArray.get());
    applyTexture(boxGeom, imgName);
    boxGeom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));  
    osg::StateSet* stateset = boxGeom->getOrCreateStateSet();
    stateset->setMode(GL_BLEND,osg::StateAttribute::ON);  
     stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
     osg::Geode* _geode=new osg::Geode;
     _geode->addDrawable(boxGeom);
     _geode->setName("myGeode");       
     geometry_center=boxGeom->getBound().center();
     return _geode;
}

 

int main( int argc, char **argv )

{
              osg::Camera* g_camera=new osg::Camera;
              g_camera->setProjectionMatrixAsOrtho2D(0,1,0,1.25);
              g_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
              g_camera->setClearMask(GL_DEPTH_BUFFER_BIT);
              g_camera->setRenderOrder(osg::Camera::POST_RENDER);
              //rotate
              osg::ref_ptr<osg::MatrixTransform> rotMT=new 
osg::MatrixTransform;                            osg::Matrix rmatrix;         
              
rmatrix.makeRotate(osg::DegreesToRadians(45.),osg::Vec3f(0.0,0.0,1.0));         
    
              rotMT->setMatrix(rmatrix);

              //translate
              osg::ref_ptr<osg::MatrixTransform> transMT=new 
osg::MatrixTransform;                            osg::Matrix tmatrix;
              tmatrix.makeTranslate(osg::Vec3f(-0.04,-0.075,0.0));
              transMT->setMatrix(tmatrix);
             
            rotMT->addChild(transMT.get());
              transMT->addChild(createGeometry());
              g_camera->addChild(rotMT.get());
         

              osgViewer::Viewer viewer;
 
            viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);        
            viewer.setCameraManipulator( new osgGA::TrackballManipulator() );   
          
            viewer.addEventHandler(new Rot);
            viewer.setSceneData(g_camera);

              osg::Vec3d eye(osg::Vec3f(0.0,0.0,0.0));
              osg::Vec3d center(osg::Vec3f(0.0,0.0,0.0));
              osg::Vec3d up(osg::Vec3f(0.0,0.0,0.0));

              viewer.getCameraManipulator()->setHomePosition(eye,center,up);
              viewer.home();
              viewer.realize();

             while(!viewer.done())             
                     viewer.frame();    

       return 0;

}





Cheers,
Akilan

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





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

Reply via email to