Welcome! Log In Create A New Profile

Advanced

Nunchuk Stick

Posted by profetylen 
Nunchuk Stick
May 30, 2009 12:48AM
How do I get information about the nunchuck stick? (and the classic controller sticks)

I have searched a couple of source codes but I can't really figure out how to do it.

edit: and the gamecube C-stick



Edited 1 time(s). Last edit at 05/30/2009 12:52AM by profetylen.
Re: Nunchuk Stick
May 30, 2009 03:08AM
Did you look at Tantric's libGUI code? It should have what you're seeking.
Re: Nunchuk Stick
May 30, 2009 10:42AM
You get access to gamecube pad analog sticks using PAD_StickX and PAD_StickY functions provided by libogc. The value retuned is an integer between -127 and 128.

There isn't similar routine for WPAD (Nunchuk or Classic analog sticks) but here's the ones I use for accessing them in a similar way as gamecub pad analog sticks

static s8 WPAD_StickX(u8 chan,u8 right)
{
  float mag = 0.0;
  float ang = 0.0;
  WPADData *data = WPAD_Data(chan);

  switch (data->exp.type)
  {
    case WPAD_EXP_NUNCHUK:
    case WPAD_EXP_GUITARHERO3:
      if (right == 0)
      {
        mag = data->exp.nunchuk.js.mag;
        ang = data->exp.nunchuk.js.ang;
      }
      break;

    case WPAD_EXP_CLASSIC:
      if (right == 0)
      {
        mag = data->exp.classic.ljs.mag;
        ang = data->exp.classic.ljs.ang;
      }
      else
      {
        mag = data->exp.classic.rjs.mag;
        ang = data->exp.classic.rjs.ang;
      }
      break;

    default:
      break;
  }

  /* calculate X value (angle need to be converted into radian) */
  if (mag > 1.0) mag = 1.0;
  else if (mag < -1.0) mag = -1.0;
  double val = mag * sin(M_PI * ang/180.0f);
 
  return (s8)(val * 128.0f);
}


static s8 WPAD_StickY(u8 chan, u8 right)
{
  float mag = 0.0;
  float ang = 0.0;
 WPADData *data = WPAD_Data(chan);


  switch (data->exp.type)
  {
    case WPAD_EXP_NUNCHUK:
    case WPAD_EXP_GUITARHERO3:
      if (right == 0)
      {
        mag = data->exp.nunchuk.js.mag;
        ang = data->exp.nunchuk.js.ang;
      }
      break;

    case WPAD_EXP_CLASSIC:
      if (right == 0)
      {
        mag = data->exp.classic.ljs.mag;
        ang = data->exp.classic.ljs.ang;
      }
      else
      {
        mag = data->exp.classic.rjs.mag;
        ang = data->exp.classic.rjs.ang;
      }
      break;

    default:
      break;
  }

  /* calculate X value (angle need to be converted into radian) */
  if (mag > 1.0) mag = 1.0;
  else if (mag < -1.0) mag = -1.0;
  double val = mag * cos(M_PI * ang/180.0f);
 
  return (s8)(val * 128.0f);
}

The "right" argument makes returning the right stick value, if it exists.
Re: Nunchuk Stick
May 30, 2009 12:16PM
@DrTwox: No, I didn't think of that!

@ekeeke: Yes, I have found PAD_StickX and PAD_StickY, but how do I access the C-stick?

Thanks, both of you for the help! :)



Edited 1 time(s). Last edit at 05/30/2009 12:21PM by profetylen.
Re: Nunchuk Stick
May 30, 2009 04:26PM
There are PAD_SubStickX and PAD_SubStickY functions for that (look at PAD.h for the complete API).
Generally speaking, even when not documented, the header files of libogc in your libogc/includes/ path are a very good source of information when starting development. Function names are generally meaningful enough ...
Re: Nunchuk Stick
May 31, 2009 12:33PM
Okay!

Thanks again! :D
Sorry, only registered users may post in this forum.

Click here to login