Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request - key control ala ofxGameCamera #4

Open
jvcleave opened this issue Mar 20, 2012 · 6 comments
Open

feature request - key control ala ofxGameCamera #4

jvcleave opened this issue Mar 20, 2012 · 6 comments

Comments

@jvcleave
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants