About Store Forum Documentation Contact



Post Reply 
InputButton for joypad direction?
Author Message
gwald Offline
Member

Post: #1
InputButton for joypad direction?
Hello smile
I'm looking at using InputButton class for mapping KB/controllers.
It takes these parameters:
INPUT_TYPE type ; // input type
Byte button, // button index
device; // device index (for example Joypad device index)

Which is fine for KB and joypad buttons, but joypad directions ( and analog sticks) don't return as buttons:
JoypadClass
Vec2 dir , // digital direction
dir_a [2], // analog direction
dir_an[2]; // normalized analog direction

It returns Vec2 data fine (as per joypad tut) but no button data is return when checking buttons Joypad[0].b(i);

So I'm not sure what to pass the InputButton.button (button index) value.
Have I missed something really obvious?

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
(This post was last modified: 05-21-2013 11:26 AM by gwald.)
05-21-2013 10:48 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: InputButton for joypad direction?
Hello, InputButton does not support joypad directions, or for example mouse cursor positions. (only buttons and keyboard keys are supported)
05-23-2013 02:25 PM
Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #3
RE: InputButton for joypad direction?
(05-23-2013 02:25 PM)Esenthel Wrote:  Hello, InputButton does not support joypad directions, or for example mouse cursor positions. (only buttons and keyboard keys are supported)

That's what I thought, that's cool.
I use a custom version of your InputButton class and it works fine smile
My test code below, for others interested:

Code:
enum INPUTCONTROLLER_TYPE // Input Device Type
{
   INPUTCONTROLLER_NONE    , // None
   INPUTCONTROLLER_KEYBOARD, // Keyboard
   INPUTCONTROLLER_MOUSE   , // Mouse
   INPUTCONTROLLER_JOYPAD  , // Joypad
   // gwald
   INPUTCONTROLLER_JOYPAD_DIR_RIGHT  , // X POS = RIGHT
   INPUTCONTROLLER_JOYPAD_DIR_LEFT  , // X NEG = LEFT
   INPUTCONTROLLER_JOYPAD_DIR_UP  , // Y POS = UP
   INPUTCONTROLLER_JOYPAD_DIR_DOWN  , // Y NEG = DOWN
   INPUTCONTROLLER_JOYPAD_LEFTAN_UP  , // Joypad ANALOG Direction
   INPUTCONTROLLER_JOYPAD_LEFTAN_DOWN  , // Joypad ANALOG Direction
   INPUTCONTROLLER_JOYPAD_LEFTAN_LEFT  , // Joypad ANALOG Direction
   INPUTCONTROLLER_JOYPAD_LEFTAN_RIGHT  , // Joypad ANALOG Direction  
   INPUTCONTROLLER_JOYPAD_RIGHTAN_UP  , // Joypad ANALOG Direction
   INPUTCONTROLLER_JOYPAD_RIGHTAN_DOWN  , // Joypad ANALOG Direction
   INPUTCONTROLLER_JOYPAD_RIGHTAN_LEFT  , // Joypad ANALOG Direction
   INPUTCONTROLLER_JOYPAD_RIGHTAN_RIGHT  , // Joypad ANALOG Direction
};


struct InputController : InputButton
{
      
  //  INPUT_TYPE type  ; // the same but stores extra types
  // Byte       button, // KB key or JOY button
  //            device; // device index (for example Joypad device index)
  
   flt onAll()C
   {
      if(type > INPUTCONTROLLER_JOYPAD) // JOYPAD DIRECT/ANALOG
      {
        
        Vec2    dir =  Joypad[device].dir ;
        flt RightLR = Joypad[device].dis.rz;
        flt RightUD = Joypad[device].dis.z;
        flt LEFTLR = Joypad[device].dis.x;
        flt LEFTUD = Joypad[device].dis.y;
                  
        // Log(S+ "\r\n dir.y = " + (dir.y)  + " true! =x " +(dir.x) + "\r\n" );
        
         switch(type)
         {  
             case  INPUTCONTROLLER_JOYPAD_DIR_UP: // POS Y UP
               return   (dir.y); //            
             case  INPUTCONTROLLER_JOYPAD_DIR_RIGHT:    // POS X RIGH
              return  (dir.x); //
             case  INPUTCONTROLLER_JOYPAD_DIR_DOWN:     // MINUS Y DOWN
               return  -(dir.y); //
             case  INPUTCONTROLLER_JOYPAD_DIR_LEFT:     // MINUS X LEFT
              return -(dir.x);
        }

        return 0; //false;
      }
      else // button or key
      {        
        return (flt)super.on();  
      }
      
      
   }; // onAll
  
};

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
05-24-2013 02:13 AM
Visit this user's website Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #4
RE: InputButton for joypad direction?
(05-23-2013 02:25 PM)Esenthel Wrote:  Hello, InputButton does not support joypad directions, or for example mouse cursor positions. (only buttons and keyboard keys are supported)

Hello again,
I'm try to capture the keyboard keys (alphanumeric/arrows etc).

InputButton // universal Input Button, may be a button from Keyboard, Mouse, Joypad
INPUT_TYPE type ; // input type
Byte button, // button index
device; // device index (for example Joypad device index)

type, I set to INPUT_KEYBOARD
button, I've tried passing Kb.c()/KB.f() values but doesn't work.
device, I assume this is not required.

No functions in Kb returns KB_BUTTON.
How do I get the key press to the button index param?

Thanks in advance.
gwald.

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
05-24-2013 10:28 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: InputButton for joypad direction?
Hello!

Could you be more specific with your question?

Your InputController class sounds like good solution.

Kb.f should work ok with keyboard arrows
for KB_BUTTON you can test Kb.b methods
KbSc can operate on Char, KB_FUNC and KB_BUTTON
InputButton can operate only on KB_BUTTON - you just set the value for KB_BUTTON (yes device index is not used for keyboard)
05-24-2013 12:37 PM
Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #6
RE: InputButton for joypad direction?
Hey thanks for the reply!
Well this is my problem:
(05-24-2013 12:37 PM)Esenthel Wrote:  InputButton can operate only on KB_BUTTON - you just set the value for KB_BUTTON
How do I capture a key and set it?

I know I can set it like this:

//KB_W=0x11, // W
Byte button=KB_BUTTON::KB_W;
InputButton ForwardKey = InputButton(INPUT_KEYBOARD, button,0);
if(ForwardKey.on() ) point.y+=0.001; // when 'w', move point up


All functions in keyboard.h return Bools/chars/KB_FUNC etc.
But none return KB_BUTTON?

I'm trying to map key presses to KB_BUTTON.

Is there a way to convert the output of these:
KB_FUNC Kb.f()
char Kb.c()

To: KB_BUTTON so I can store it in InputButton.button?

Oh.. it's okay, I found it in the code here:
http://www.esenthel.com/community/showth...p?tid=4229

Wow, I see!

It involves:
*_functionKeys("0") = KB_0
etc...
AND
Map<Str,UInt> _functionKeys(a::MapFKCompare, a::MapFKCreate); // default map for command => KB conversions
And
// Map related functions
static Bool MapABCreate( Str &data, C Str &key, Ptr user) { return true; }
static Int MapABCompare(C Str &a, C Str &b) { return Compare(a, b); }
static Bool MapFKCreate( UInt &data, C Str &key, Ptr user){ return true; }
static Int MapFKCompare(C Str &a, C Str &b) { return Compare(a, b); }

Trying to figure it out, I'll get it.
Thanks again for your help.

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
(This post was last modified: 05-24-2013 02:34 PM by gwald.)
05-24-2013 02:29 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply