title: OSG osg::MatrixTransform
body: <p>I am trying to draw a compass within Head Up Display(HUD) in my application. I have successfully rendered the compass within the scene as a textured geometry. The question is when I try to rotate the compass using osg::MatrixTransfrom and osg::Matrix classes, it translates the compass to a wrong position in the scene. Here is the code :</p>
  
  <pre><code>osg::ref_ptr&lt;osg::Node&gt; CustomHUD::DrawCompass(void)
  {
  osg::ref_ptr&lt;osg::Vec3Array&gt; vertices = new osg::Vec3Array;
  vertices-&gt;push_back( osg::Vec3(CENTERX-150.0f,0.0f,0.0f));
  vertices-&gt;push_back( osg::Vec3(CENTERX-150.0f,300.0f,0.0f));
  vertices-&gt;push_back( osg::Vec3(CENTERX+150.0f,300.0f,0.0f));
  vertices-&gt;push_back( osg::Vec3(CENTERX+150.0f,0.0f,0.0f));
  
  osg::ref_ptr&lt;osg::Vec3Array&gt; normals = new osg::Vec3Array;
  normals-&gt;push_back( osg::Vec3(0.0f,0.0f,-1.0f));
  
  osg::ref_ptr&lt;osg::Vec2Array&gt; texcoords = new osg::Vec2Array;
  texcoords-&gt;push_back(osg::Vec2(0.0f,0.0f));
  texcoords-&gt;push_back(osg::Vec2(0.0f,1.0f));
  texcoords-&gt;push_back(osg::Vec2(1.0f,1.0f));
  texcoords-&gt;push_back(osg::Vec2(1.0f,0.0f));
  
  osg::ref_ptr&lt;osg::Geometry&gt; quad = new osg::Geometry;
  quad-&gt;setVertexArray(vertices.get());
  quad-&gt;setNormalArray(normals.get());
  quad-&gt;setNormalBinding(osg::Geometry::BIND_OVERALL);
  quad-&gt;setTexCoordArray(0,texcoords.get());
  quad-&gt;addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
  
  
  
  
  osg::ref_ptr&lt;osg::Texture2D&gt; texture = new osg::Texture2D;
  osg::ref_ptr&lt;osg::Image&gt; image = osgDB::readImageFile("/home/ttc/Pictures   compassfinal2.png");
  texture-&gt;setImage(image.get());
  //texture-&gt;setTextureSize(500,500);
  
  
  
  
  osg::ref_ptr&lt;osg::Group&gt; mainroot = new osg::Group;
  osg::ref_ptr&lt;osg::Geode&gt; drawing2 = new osg::Geode;
  
  drawing2-&gt;addDrawable(quad.get());
  drawing2-&gt;getOrCreateStateSet()-&gt;setTextureAttributeAndModes(0,texture.get());
  drawing2-&gt;getOrCreateStateSet()-&gt;setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
  drawing2-&gt;getOrCreateStateSet()-&gt;setMode(GL_LIGHTING,osg::StateAttribute::ON);
  drawing2-&gt;getOrCreateStateSet()-&gt;setMode(GL_BLEND,osg::StateAttribute::ON);
  
  
  
  
  vtTransform *transnode = new vtTransform;
  osg::ref_ptr&lt;osg::MatrixTransform&gt; transnodeosg = new osg::MatrixTransform;
  
  transnodeosg-&gt;setMatrix(osg::Matrix::rotate(-0.9,osg::Vec3f(0.0,0.0,1.0)));
  transnode-&gt;SetOsgTransform(transnodeosg);
  
  
  transnode-&gt;addChild(drawing2);
  mainroot-&gt;addChild(transnode);
  return mainroot.get();
  </code></pre>
  
  <p>}</p>
  
  <pre><code>osg::Camera* CustomHUD::CreateHUD()
  {
  // create a camera to set up the projection and model view matrices, and thesubgraph        to draw in the HUD
  osg::Camera* camera = new osg::Camera;
  
  // set the projection matrix
  camera-&gt;setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
  
  // set the view matrix
  camera-&gt;setReferenceFrame(osg::Transform::ABSOLUTE_RF);
  camera-&gt;setViewMatrix(osg::Matrix::identity());
  
  // only clear the depth buffer
  camera-&gt;setClearMask(GL_DEPTH_BUFFER_BIT);
  
  // draw subgraph after main camera view.
  camera-&gt;setRenderOrder(osg::Camera::POST_RENDER);
  
  // we don't want the camera to grab event focus from the viewers main camera(s).
  camera-&gt;setAllowEventFocus(false);
  
  
  
  // add to this camera a subgraph to render
  {
  
      geode = new osg::Geode();
  
      std::string timesFont("fonts/arial.ttf");
  
      // turn lighting off for the text and disable depth test to ensure it's always ontop.
      osg::StateSet* stateset = geode-&gt;getOrCreateStateSet();
  
      osg::Vec3 position(0.0f,0.0f,0.0f);
      osg::Vec3 delta(0.0f,-120.0f,0.0f);
  
      {
          osgText::Text* text = new  osgText::Text;
          geode-&gt;addDrawable( text );
          text-&gt;setFont(timesFont);
          text-&gt;setPosition(position);
          text-&gt;setText("Egypt Airforces SVS");
          position += delta;
      }
  
     DrawCenterSymbol();
  
     camera-&gt;addChild(geode);
     camera-&gt;addChild(DrawCompass());
     }
  </code></pre>