[osg-users] how to make a node fixed in screen position

forest37 forest37 at 163.com
Wed Sep 10 23:01:54 PDT 2008


 hi all,
    I want to draw axes in screen position,the axes can't be scaled or transformed ,but which can be rotated with other scene.I do it like this,but the billboard (texts: 'X','Y','Z') doesn't work,what should I do to make the billboard work well?“axes.osg” is downloaded from the osg homepage.
 
osgViewer::Viewer viewer;
class orbit : public osg::NodeCallback 
{
public:
 orbit() {} 
 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
 {  
  osg::PositionAttitudeTransform *pat = dynamic_cast<osg::PositionAttitudeTransform *>(node);
  if( tx != NULL )
  {
       osg::Camera *camera=viewer.getCamera();
       osg::Matrixd pMatrix = camera->getViewMatrix();
       pat->setAttitude(pMatrix.getRotate());
  }   
 }
}; 
osg::Group* fun()
{
   osg::Group *group=new osg::Group();
 
    osg::Node *axis=osgDB::readNodeFile("data\\axes.osg");
    osg::PositionAttitudeTransform * tran = new osg::PositionAttitudeTransform;
    tran->addChild(axis);
    tran->setPosition(osg::Vec3(5,5,0));
    tran->setUpdateCallback(new orbit());
 
    osg::MatrixTransform* ModelViewMatrix = new osg::MatrixTransform;
    ModelViewMatrix->setMatrix(osg::Matrix::identity()); 
    ModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    ModelViewMatrix->addChild(tran);
 
    osg::Projection* ProjectionMatrix = new osg::Projection;
    ProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,10,0,10)); 
    ProjectionMatrix->addChild(ModelViewMatrix);
    
    group->addChild(ProjectionMatrix);
    return group;
}
 
int _tmain(int argc, _TCHAR* argv[])
{  
 osg::Group *mRoot =fun(); 
 viewer.setSceneData(mRoot);
 return viewer.run();
}
 
best regards
 
forest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080911/658b2858/attachment-0002.htm>


More information about the osg-users mailing list