eXperiment robotics framework

The 3 possibilities of interaction with the 3D world given user input by the order they happen in the framework are:
  1. All the objects in the hit vector are available; Use this one when the Event Handler acts upon more than one object that can be overlayed
  2. Just the event is returned; Use this one when receiving only key events or to rotate and object or to deselect an Active Event Handler
  3. The position of the hit and the Object hitted are delivered by the order that happens; Use this one in most cases like for positioning a object in the world

The search only ends when some event(...) returns true or the queue ends.

To implement it, make your Object3D inherit the WorldEventHandler class and implement the method you want.

struct WorldEventHandler {
    virtual int event(int& event, Vec3& hit, Object3D * o); // called 1st
    virtual int event(int& event); // called 2nd
    virtual int event(int& event,vector<Hit>& vectorHit); // called last
    virtual ~WorldEventHandler();
};

An example of iterating the hit vector.

int ManagerTags::event( int& event, vector<Hit>& hv ) {
    if (hv.size()>0) {
        if (event==fltk::PUSH && fltk::event_button()==fltk::LeftButton) {
            std::auto_ptr<PopupMenu> mb = std::auto_ptr<PopupMenu>(new PopupMenu(event_x(),event_y(),100,100, "pick object for tagging"));
            mb->type(PopupMenu::POPUP1);
            for(vector<Hit>::iterator i=hv.begin(), i_end=hv.end() ; i !=i_end ; i++ ) {
                ostringstream outs;  // Declare an output string stream.
                outs << "[" << i->glName <<"] "<< MGLNames.getObject3Dp(i->glName)->tags->getTags() ;
                string s = outs.str();      // Get the created string from the output stream.
                uint * name = new uint(i->glName);
                Item * item = new Item(strdup(s.c_str()),0,select_object_cb, (void*) name);
                mb->add(item);
            }
            mb->popup();
            return true;
        }
    }
    return false;
}

An example of receiving just the event, in this case used for canceling the Active Event Handler when the escape key is pressed.

int ManagerTags::event(int& e) {
    if (fltk::event_button()==fltk::EscapeKey) {
        MGLNames.setAEH(0);
        return true;
    };
    return false;
}

An example of getting the tags of an object

int ManagerTags::event(int& event, Vec3& hit, Object3D * o) {
    if (event==fltk::PUSH && fltk::event_button()==fltk::LeftButton) {
        Tags * tags = (o->tags.get());
        if(tags) {
            this->tags_Object3D = tags;
            this->updateTagsOnObject();
        }
        return true;
    } else
        return false;
}

for a explanation of the implementation of this section.


The miarn project - written by Joao Xavier