Dear list members,

could you please help me with the issue how to get the position of my object?

I have developed a class, which is derived from the class "PositionAttitudeTransform" and this class encapsulates within its constructor some other classes/objects. These are namely "Switch" (to be able to set all children on or off), Geode, MatrixTransform and other.
My intention is to have a sphere that can be dragged in 3 dimensions by the "TranslateAxisDragger" and to get its new position. So far so good, the visualization of the sphere and of the dragger is successful and I also can drag the sphere around, but I cannot get the new position. I try to get the position with this->getPosition(), where "this" is an object of PositionAttitudeTransform, the result is always zero. I guess the parent class, derived from PositionAttitudeTransform does not get to know the changes of its children. Can you tell me how can I achieve my goal?

I thank you in advance.

kind regards,

Vitali

Here is the code of the constructor:

  TargetSetter::TargetSetter(Rcs::RHCPrimitive *primitive) : osg::PositionAttitudeTransform()
  {
    // store the pointer to the RHCPrimitive class
    _primitive = primitive;

    //root = new osg::Group;
    _switch = new osg::Switch;
    addChild(_switch.get() );

    // create a command manager
    cmdMgr = new osgManipulator::CommandManager;

    osg::ref_ptr<osg::Geode> geode_1 = new osg::Geode;
    osg::ref_ptr<osg::MatrixTransform> transform_1 = new osg::MatrixTransform;

    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
    hints->setDetailRatio(2.0f);

    // draw a sphere
    osg::ref_ptr<osg::ShapeDrawable> shape;
    osg::Vec3 position;
    float radius = 0.01;
    arr vec= _primitive->computeX1();  // get the coordinates of the initial target (can consist of more than 3 elements)
    // assuming that the first 3 elements of the vector are x,y,z coordinates
    position[0] = vec(0); position[1] = vec(1); position[2] = vec(2);
    shape = new osg::ShapeDrawable(new osg::Sphere(position,radius), hints.get());
    shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f));
    geode_1->addDrawable(shape.get());

    // draw info text beside the sphere
    CoordText = new osgText::Text;
    CoordText->setFont("fonts/times.ttf");
    CoordText->setCharacterSize(radius*4);
    CoordText->setPosition(osg::Vec3(position[0]-radius*2,position[1],position[2]));
    CoordText->setAxisAlignment(osgText::Text::SCREEN);
    CoordText->setBackdropType(osgText::Text::OUTLINE);
    CoordText->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX);
    char buf[15];
    sprintf(buf, "[%2.2f, %2.2f, %2.2f]",position[0],position[1],position[2]);
    CoordText->setText(buf);
    geode_1->addDrawable(CoordText);

    // material
      osg::ref_ptr<osg::Material> matirial = new osg::Material;
      matirial->setColorMode(osg::Material::DIFFUSE);
      matirial->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
      matirial->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));
      matirial->setShininess(osg::Material::FRONT_AND_BACK, 64.0f);
      this->getOrCreateStateSet()->setAttributeAndModes(matirial.get(), osg::StateAttribute::ON);

      transform_1.get()->addChild(addDraggerToScene(geode_1.get(), cmdMgr.get() ));

      _switch->addChild(transform_1.get());

      _switch->setAllChildrenOff(); // hide the target node

      _pickHandler = new TargetHandler(this);

      osg::Vec3d pos = this->getPosition();
      std::cerr << "!!!!position: " << pos[0]<< " , " << pos[1] << " , " << pos[2] << std::endl;
}
  

GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT!   
Jetzt freischalten unter http://movieflat.web.de
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to