About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
GamePad TOPHAT
Author Message
sydbod Offline
Member

Post: #1
GamePad TOPHAT
I am having difficulty finding any information about how to access the readings from the TOPHAT of a joystick.

Have managed to work out the axis and the buttons, but the TOPHAT still eludes me.

Code:
/***************** MODIFIED "input.cpp"  SAMPLE CODE ****************************/
#include "stdafx.h"// point position
/******************************************************************************/
Vec2    point,    // point position
        axis,    // x,y joystick values
        extra;    // rudder,throttle values
Char    c;        // character pressed

enum    {TRIGGER,BUTTON2,BUTTON3,BUTTON4,BUTTON5,BUTTON6,BUTTON7,BUTTON8};
enum    {JOYPAD1,JOYPAD2,JOYPAD3,JOYPAD4};

InputButton JoyButton(INPUT_JP,TRIGGER,JOYPAD1,NULL); // InputButton(INPUT_TYPE type, Byte button, Byte device=0, Bool (*req)()=NULL)
/******************************************************************************/
void InitPre()
{
   App.name("Input");
   App.flag=APP_NO_FX;
   PakAdd("../data/engine.pak");
}
/******************************************************************************/
Bool Init()
{
   Text_ds.color =BLACK; // here change the default text color
   Text_ds.shadow=0;     // here disable shadows
   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
   if(Kb.bp(KB_ESC))return false;
  
   if(Kb.c())c=Kb.c(); // if character pressed remember to draw it later

   if(Kb.b(KB_LEFT ))point.x-=Tm.d()/2; // move point left  when 'left  arrow' is on according to time delta
   if(Kb.b(KB_RIGHT))point.x+=Tm.d()/2; // move point right when 'right arrow' is on according to time delta
   if(Kb.b(KB_DOWN ))point.y-=Tm.d()/2; // move point down  when 'down  arrow' is on according to time delta
   if(Kb.b(KB_UP   ))point.y+=Tm.d()/2; // move point up    when 'up    arrow' is on according to time delta

   if(Kb.bp(KB_Z))point.x-=0.1; // when 'z' is pushed        , move point left
   if(Kb.br(KB_X))point.x+=0.1; // when 'x' is released      , move point right
   if(Kb.bd(KB_C))point.y+=0.1; // when 'c' is double clicked, move point up
  
   return true;
}
/******************************************************************************/
void Draw()
{
   D.clear(WHITE);

   D.dot(RED  ,Ms.pos); // draw red   dot at mouse cursor position
   D.dot(GREEN,point ); // draw green dot at 'point' position
  
   if(Ms.b(0))D.dot(BLACK, -0.1,0.4, 0.1); // when 0th mouse button on, draw big black dot
   if(Ms.b(1))D.dot(BLACK,  0.1,0.4, 0.1); // when 1st mouse button on, draw big black dot

   D.text(0,0.9, S+"character : "+c ); // draw stored character
   D.text(0,0.7, S+"mouse : "+Ms.pos); // draw mouse  position
   D.text(0,0.6, S+"point : "+point ); // draw point  position

   axis = Jp[0].dir_a[0];
   D.text(0,0.5, S+"Joystick x : "+axis.x ); // draw joystick x value
   D.text(0,0.4, S+"Joystick y : "+axis.y ); // draw joystick y value

   extra = Jp[0].dir_a[1];
   D.text(0,0.3, S+"Joystick extraA(rudder) : "+extra.x ); // draw joystick rudder value
   D.text(0,0.2, S+"Joystick extraA(throttle) : "+extra.y ); // draw joystick throttle value

   JoyButton.button=TRIGGER;
   D.text(0,0.1, S+"Joystick JoyButton(button 0)=Stick(button 1) : "+JoyButton.on() ); // draw trigger state
   JoyButton.button=BUTTON8;
   D.text(0,0.0, S+"Joystick JoyButton(button 7)=Stick(button 8) : "+JoyButton.on() ); // draw button state


}
/******************************************************************************/

Any assistance would be greatly appreciated. smile
07-02-2009 03:18 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
Re: GamePad TOPHAT
what is a TOPHAT?

Have you tried
Jp[0].dir
and
Jp[0].dir_a
?
07-02-2009 06:54 PM
Find all posts by this user Quote this message in a reply
sydbod Offline
Member

Post: #3
Re: GamePad TOPHAT
A TOPHAT is a single button (usually on the top of the joystick, that can be moved in any of the following directions (forward, 45deg forward right, 45deg forward left, right, left,45deg left backwards,45deg right backwards, backwards).

It is used to allow a person to look in any of those directions around themselves, without having to rotate the character themselves(ie change the pilots view from his cockpit without having to change the direction of the aircraft)

Quote:The DirectX SDK has the following additional information:

rgdwPOV

Direction controllers, such as point-of-view hats. The position is indicated in hundredths of a degree clockwise from north (away from the user). The center position is normally reported as - 1; but see Remarks. For indicators that have only five positions, the value for a controller is - 1, 0, 9,000, 18,000, or 27,000.
.
.
.
Remarks.
.
.
Some drivers report the centered position of the POV indicator as 65,535. Determine whether the indicator is centered as follows:

BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);

EDIT: You are correct,"Jp[0].dir",axis.x in combination with axis.y, provide a normalized value of the one tophat control button.
I will have a closer look at the the header files and see what is the correct single data point.
07-03-2009 02:06 AM
Find all posts by this user Quote this message in a reply
sydbod Offline
Member

Post: #4
Re: GamePad TOPHAT
Just in case the following code is of value to others in a joystick information search.

Code:
/***************** MODIFIED "input.cpp"  SAMPLE CODE ****************************/
#include "stdafx.h"// point position
/******************************************************************************/
Vec2    point,    // point position
        axis,    // x,y joystick values
        extra,    // rudder,throttle values
        tophat; // tophat vectors
Char    c;        // character pressed

enum    {TRIGGER,BUTTON2,BUTTON3,BUTTON4,BUTTON5,BUTTON6,BUTTON7,BUTTON8};
enum    {JOYPAD1,JOYPAD2,JOYPAD3,JOYPAD4};

InputButton JoyButton(INPUT_JP,TRIGGER,JOYPAD1,NULL); // InputButton(INPUT_TYPE type, Byte button, Byte device=0, Bool (*req)()=NULL)
/******************************************************************************/
void InitPre()
{
   App.name("Input");
   App.flag=APP_NO_FX;
   PakAdd("../data/engine.pak");
}
/******************************************************************************/
Bool Init()
{
   Text_ds.color =BLACK; // here change the default text color
   Text_ds.shadow=0;     // here disable shadows
   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
   if(Kb.bp(KB_ESC))return false;
  
   if(Kb.c())c=Kb.c(); // if character pressed remember to draw it later

   if(Kb.b(KB_LEFT ))point.x-=Tm.d()/2; // move point left  when 'left  arrow' is on according to time delta
   if(Kb.b(KB_RIGHT))point.x+=Tm.d()/2; // move point right when 'right arrow' is on according to time delta
   if(Kb.b(KB_DOWN ))point.y-=Tm.d()/2; // move point down  when 'down  arrow' is on according to time delta
   if(Kb.b(KB_UP   ))point.y+=Tm.d()/2; // move point up    when 'up    arrow' is on according to time delta

   if(Kb.bp(KB_Z))point.x-=0.1; // when 'z' is pushed        , move point left
   if(Kb.br(KB_X))point.x+=0.1; // when 'x' is released      , move point right
   if(Kb.bd(KB_C))point.y+=0.1; // when 'c' is double clicked, move point up
  
   return true;
}
/******************************************************************************/
void Draw()
{
   D.clear(WHITE);

   D.dot(RED  ,Ms.pos); // draw red   dot at mouse cursor position
   D.dot(GREEN,point ); // draw green dot at 'point' position
  
   if(Ms.b(0))D.dot(BLACK, -0.1,0.4, 0.1); // when 0th mouse button on, draw big black dot
   if(Ms.b(1))D.dot(BLACK,  0.1,0.4, 0.1); // when 1st mouse button on, draw big black dot

   D.text(0,0.9, S+"character : "+c ); // draw stored character
   D.text(0,0.7, S+"mouse : "+Ms.pos); // draw mouse  position
   D.text(0,0.6, S+"point : "+point ); // draw point  position

   axis = Jp[0].dir_a[0];
   D.text(0,0.5, S+"Joystick x : "+axis.x ); // draw joystick x value
   D.text(0,0.4, S+"Joystick y : "+axis.y ); // draw joystick y value

   extra = Jp[0].dir_a[1];
   D.text(0,0.3, S+"Joystick extraA(rudder) : "+extra.x ); // draw joystick rudder value
   D.text(0,0.2, S+"Joystick extraA(throttle) : "+extra.y ); // draw joystick throttle value

   tophat = Jp[0].dir;
   D.text(0,0.1, S+"JoystickTophat Vec x : "+tophat.d[0] +" JoystickTophat Vec y : "+tophat.d[1] ); // draw joystick tophat Vec value

   JoyButton.button=TRIGGER;
   D.text(0,0.0, S+"Joystick JoyButton(button 0)=Stick(button 1) : "+JoyButton.on() ); // draw trigger state
   JoyButton.button=BUTTON8;
   D.text(0,-0.1, S+"Joystick JoyButton(button 7)=Stick(button 8) : "+JoyButton.on() ); // draw button state
}
/******************************************************************************/

A code fragments section on this forum would be a handy idea for this sort of material.
07-03-2009 03:30 AM
Find all posts by this user Quote this message in a reply
Post Reply