0
votes

I want to create a dynamic sphere in OSG which would be created(moved) by the mouse left click at that location (center) and with a dynamic radius of the mouse pointer current location's distance to the center....

I understand that for this reason I need to create an osgGA::GUIEventHandler Object and implement the virtual handle function but I miss other details like finding the sphere object it self from the scene and changing its attributes.

I also tried to change A picking example but failed to detect the sphere in the nodePath or creating a new sphere

1
Now if only you had a specific programming question.stark

1 Answers

1
votes

I would probably start by creating a custom class derived from one of the osgGA Manipulator classes.

You'll want to override the handle() method with something like this:

bool CustomManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    using namespace osgGA;

    if (ea.getEventType()==GUIEventAdapter::FRAME)
    {
        if (_thrown) aa.requestRedraw();
    }
    else if (ea.getEventType()==GUIEventAdapter::PUSH)
    {
        // check if your sphere is picked using LineSegmentIntersector
        // (like in the picking example) and set a flag
    }
    else if (ea.getEventType()==GUIEventAdapter::DRAG)
    {
        // update the position and radius of your sphere if the flag was set
    }
    else if (ea.getEventType()==GUIEventAdapter::RELEASE)
    {
        // release the sphere, unset the flag
    }   
    return false;
}

Then remember to use setCameraManipulator() on your viewer to add this instead of the default TrackballManipulator.