Re: [Plib-users] Input Library
Brought to you by:
sjbaker
From: Steve B. <sjb...@ai...> - 2000-02-19 02:55:43
|
Ryujin Doraegon wrote: > > Hello, i'm looking for a library that help me manage user input from a keyboard > or joystick but with some special features. Well, PLIB has a joystick library that makes reading the current position quite easy - but to decide which "move" was made via some complex sequence of joystick actions is beyond what we do. I seriously doubt you'll find a package that'll have those features directly - but it wouldn't be to hard to write. You'd have to decide exactly which parts of the joystick range constitute "down" (the joystick axes go from -1 to +1 - so "down" could mean "any Y value less than -0.5"...say). You could split the ranges of the joystick into (say) 8 regions with a neutral region in the middle: int where_is_the_stick ( float x, float y ) { if ( y > 0.5 ) { if ( x < -0.5 ) return TOP_LEFT ; if ( x > 0.5 ) return TOP_RIGHT ; return TOP_CENTER ; } if ( y < -0.5 ) { if ( x < -0.5 ) return BOTTOM_LEFT ; if ( x > 0.5 ) return BOTTOM_RIGHT ; return BOTTOM_CENTER ; } if ( x < -0.5 ) return LEFT ; if ( x > 0.5 ) return RIGHT ; return NEUTRAL ; } ...call that routine every frame to catagorize the position. Every time the joystick CHANGES position compared to last frame, store that in an array that holds (say) the last 20 places the joystick visited. Now, whenever you add an entry into that array, you can compare the last few locations the joystick was at against a table of "moves" that your game needs to recognise. So, "Hit forwards twice" would be when you've seen NEUTRAL/TOP/NEUTRAL/TOP/NEUTRAL and "Moved in a semicircle" would be BOTTOM/BOTTOM-LEFT/LEFT/TOP-LEFT/TOP or something. You'll probably need to recognise several combinations of functions for each move because he may start his semicircle at BOTTOM-LEFT instead of BOTTOM - and you probably don't want the moves to have to be TOO exact. > im using OpenGL and the GLUT Library, it seems that GLUT doesn't support this > features. I don't think any library does - you have to write it yourself. > Another thing is that i don want the keyboard autorepeat feature, > when i press a key i want it pressed until i release it. You can turn off autorepeat in GLUT. Just call glutIgnoreKeyRepeat(). -- Steve Baker http://web2.airmail.net/sjbaker1 sjb...@ai... (home) http://www.woodsoup.org/~sbaker sj...@ht... (work) |