elliotwoods / ofxGrabCam

Simple camera (ofEasyCam replacement) for openFrameworks for quickly browsing your scene
http://blog.kimchiandchips.com
73 stars 24 forks source link

feature request - key control ala ofxGameCamera #4

Open jvcleave opened 12 years ago

jvcleave commented 12 years ago

Because being able to move without a mouse would be awesome (nice for laptops) https://github.com/Flightphase/ofxGameCamera/blob/master/src/ofxGameCamera.cpp

elliotwoods commented 12 years ago

i think kyle tried implementing key controls last time. i presume we'd have xyz translate controls and orbit controls on mouse i think if you wanted something more than that (i.e. zoom, orbit keys) then it might become a bit too crowded on the keyboard perhaps? i mean, wouldn't leave very many keys for the rest of your app controls.

perhaps we could have an ofGrabCam::addKeyModifier(OF_KEY_ALT) make it so you'd have to hold alt for the keys to work (to unclutter your keyboard for everything else)

jvcleave commented 12 years ago

Yeah another approach could be to have an isKeyBoardEnabled option that allowed you to bind the keys. Maybe even broken out into a separate utility Class like ofxGrabCamKeyUtils. Something like that could load a config file to allow custom mappings

elliotwoods commented 12 years ago

yeah that'd be great but i think adding extra files would break oF standards

perhaps syntax like:

class ofBaseHasActions {
public:
    virtual void doAction(int action) = 0; ///<override this function to perform your actions 
};

class ofBaseHasHotkeys : public ofBaseHasActions {
public:
    ~ofBaseHasHotkeys(); ///<removes hotkeys from this instance from static dictionary
    void addHotkey(int key, int action); ///<throws a warning if this key is already linked to any action globally
    void removeHotkey(int key);
protected:
    static std::map<int , pair<ofBaseHasHotkeys *, int> > hotkeyDictionary; ///< global map of [key, [instance, action] ]
};

I presume that the int action would be sufficient to deal with local enums, so ofNode might look like: ofNode yeah! this could be anything, not just cameras!

class ofNode : public ofBaseHasHotkeys {
public:
    enum action { PITCH_UP, PITCH_DOWN, YAW_LEFT, YAW_RIGHT, ROLL_LEFT, ROLL_RIGHT, etc }
    virtual void doAction(int action); ///<note that it's still virtual so child classes can add further hotkeys as long as they remember to call ofNode::doAction(action)
....
};
elliotwoods commented 12 years ago

a couple of other notes:

we could keep hotkeys seperate and have ofNode inherit ofBaseHasActions then have a global action register:

static std::map<int , pair<ofBaseHasHotkeys *, int> > hotkeyDictionary;
void ofAddHotkey(int key, int action, ofBaseHasActions * instance);
void ofRemoveHotkey(int key, ofBaseHasActions * instance = 0); ///<by default removes all hotkey associations

then we'd also need

class ofBaseHasActions {
public:
    ~ofBaseHasActions(); ///<removes any hotkeys linked to this instance from the dictionary
    virtual void doAction(int action) = 0; ///<override this function to perform your actions 
};

the above still requires the user to define the hotkeys at compile time (rather than in a file)

and i can see this being a bit of a bugger to debug for new users if something goes wrong (it's not very safe) the inherited ofBasHasHotkeys approach is cleaner I'm 100% sure nobody's going to buy into this though

I'd suggest having a look at https://github.com/elliotwoods/ofxGrabCam/tree/interactive with https://github.com/elliotwoods/ofxDraggableNode note the 'interactive' branch of ofxGrabCam it's an experiment in direct interactions with nodes adding hotkeys to ofxDraggableNode would be totally possible with something like the above without the core support as you add the ofNode to a dictionary of interactive objects (which then receive mouse actions from ofxGrabCam for translate, rotate).

elliotwoods commented 12 years ago

ah!!!!! sorry thought this was comments on ofEasyCam

yes of course! will definitely be looking into implementing more modes of interaction perhaps mostly in ofxDraggableNode (prefer the name ofxInteractiveNode)

jvcleave commented 12 years ago

I was wondering what you meant about breaking convention but I thought maybe you were trying to get ofxGrabCam into core :)