Difference between revisions of "Joysticks"
From CCRMA Wiki
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
== Mapping Joysticks == | == Mapping Joysticks == | ||
+ | |||
+ | This bit of code will spit out whatever codes are being transmitted from your controller to ChucK. It's also important to test letting buttons go up and down separately to see how your controller deals with that, if it's important to you. I used it to figure out how to interpret the input from my controller or joystick. | ||
<pre> | <pre> | ||
Line 42: | Line 42: | ||
</pre> | </pre> | ||
+ | |||
+ | == What to do with the input now? == | ||
+ | |||
+ | The most effective method I found was to have the main loop waiting for joystick events. Once an event was triggered, trigger another event that some sporked function will take care of. | ||
+ | |||
+ | == Resources Used == | ||
+ | |||
+ | * [http://chuck.cs.princeton.edu/doc/language/ ChucK Language Specification] | ||
+ | * [http://smelt.cs.princeton.edu/pieces/JoyOfChant/JoyOfChant.ck JoyOfChant.ck] The source code to another ChucK program that I used to extract all of the joystick functions from. |
Latest revision as of 16:45, 15 March 2009
Mapping Joysticks
This bit of code will spit out whatever codes are being transmitted from your controller to ChucK. It's also important to test letting buttons go up and down separately to see how your controller deals with that, if it's important to you. I used it to figure out how to interpret the input from my controller or joystick.
Hid js; HidMsg msg; if( !js.openJoystick( 0 ) ) me.exit(); <<< "Ready?", "" >>>; while(true) { // wait for event js => now; while( js.recv( msg ) ) { js => now; <<< "\n\nI LIKE TO","MOVE IT MOVE IT" >>>; while( js.recv(msg)) { if( msg.isAxisMotion()) { <<< "axismotion" >>>; <<< "axis: ", msg.which, " position: ", msg.axisPosition >>>; } if( msg.isButtonDown()) { <<< "buttondown: ", msg.which >>>; } if( msg.isButtonUp()) { <<< "buttonup: ", msg.which >>>; } if(msg.isHatMotion() ) { <<< "hat: ", msg.idata >>>; } } } }
What to do with the input now?
The most effective method I found was to have the main loop waiting for joystick events. Once an event was triggered, trigger another event that some sporked function will take care of.
Resources Used
- ChucK Language Specification
- JoyOfChant.ck The source code to another ChucK program that I used to extract all of the joystick functions from.