About Store Forum Documentation Contact



Post Reply 
Direct Input Help
Author Message
Xenom Offline
Member

Post: #1
Direct Input Help
This is probably a pretty dumb question, but how exactly do you use the JoypadClass in the Joypad header to find what the actual analog values are on the joystick? For example there is a class called DirectInputSource under the JoypadClass which has the positions, rotation, and slider defined, but how can I use these values in a function? I assume I have to define an object of some kind but I'm not really sure how.

By the way, OOP is fairly new to me, so I have a feeling I'm missing something very fundamental. I'm also curious how exactly this header relates back to DirectInput in the first place. Anyways I apologize for the noobery and appreciate any help.
07-03-2012 10:42 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Direct Input Help
why not use dir_a and dir_an members?
also there is a C++ tutorial on joypad values
07-04-2012 12:20 PM
Find all posts by this user Quote this message in a reply
battlegear2099 Offline
Member

Post: #3
RE: Direct Input Help
Hi I am looking for some info/code on how I can detect and access a Windows usb PC joystick/ throttle device and all the buttons. Like the old example with a modified input.h from a old version that is no longer compatible from 2012 found on here. The current joypad example detects the Xbox controller fine so I know it can see windows game pads. But does not see a windows joystick. Is there a way now? does anyone have example they can give me.

Thanks
11-06-2021 12:46 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Direct Input Help
Have you tried the info I've sent you via email?

If DirectInput then can you please check if it has any switch to use XInput instead?
I've dropped DirectInput support since it causes slow downs for engine startup.
But you can manually restore it by editing this file:
https://github.com/Esenthel/EsenthelEngi...ders.h#L97
#define JP_DIRECT_INPUT (WINDOWS_OLD && 0)
replace with
#define JP_DIRECT_INPUT WINDOWS_OLD

Alternatively you can try using this:
https://www.x360ce.com/
11-06-2021 01:14 PM
Find all posts by this user Quote this message in a reply
battlegear2099 Offline
Member

Post: #5
RE: Direct Input Help
I couldn't find it in my emails with you , I re looked again and this time used search and found it today. ok I rebuilt just the libs and copied them over and that worked great detected on the joypad example. the T.Flight Hotas 4 ,Throttle and Peddals.
(This post was last modified: 11-06-2021 08:35 PM by battlegear2099.)
11-06-2021 07:28 PM
Find all posts by this user Quote this message in a reply
battlegear2099 Offline
Member

Post: #6
RE: Direct Input Help
Hi Greg

the old direct X input , is that fully implemented? like the xinput for all the buttons and button names
do I need add those extra buttons to a header engine file and extend it. like the gamepad buttons has the 0-32 button index lists when pol and I can pull the buttonnames, the old directx buttons index in old SDK are format like button1 0000, button2 0001 to the last, I expect I need to add those?. I was playing around with the joypad example, I am trying to wrap my head around how to use the button flag states for the line with Str buttons; FREP(32)buttons+=Joypads[0].b(i); .and also pull the .buttonnames from it instead of state flag output and apply that to game basic example as all the examples in your engine use keyboard kb.b and mouse and not a game pad, so I not sure if its just simple change. I am looking for a example to follow.

Thanks
(This post was last modified: 11-12-2021 07:51 PM by battlegear2099.)
11-12-2021 07:40 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Direct Input Help
Yes you only get 32 button indexes, that all varies based on the joypad model, so it's best you add some option in your game to allow users configure what button they need for certain action.
11-13-2021 08:35 AM
Find all posts by this user Quote this message in a reply
battlegear2099 Offline
Member

Post: #8
RE: Direct Input Help
ok I did this using the joypad example for just one button of raw 32 states, prob too many ok for now, if I understand you correctly this is with the joypad[0] button state , this simple addition seems to work with the state clicked in str button and then I would add a case [] statement for all the buttons I need. works with tested gamepad and joystick button and I expect both are directx input and not xinput uses another system. And then I create another button number list. so this how it should be done? if yes then I am right learning path on your engine. been allot of years since I did any programming like C++, trying not to hurt my old brain. its sore from just this only just starting this. hopefullly it will get better more I flex my brain. I am getting progress lol

if(Joypads.elms())

{
D.text(0, 0.9, Joypads[0].name());

Str buttons; FREP(32) buttons+=Joypads[0].b(i); D.text(Rect_C(0, 0.8, 1, 0), S+"\n"+buttons);

if(buttons == "01000000000000000000000000000000") D.text(Rect_C(0, 0.12, 1, 0), S+"\ Hit: "); else D.text(0, 0, S+"no Hit ");

D.text(0, 0.5, S+"Triggers: "+Joypads[0].trigger[0]+' '+Joypads[0].trigger[1]);
Rect_C( 0 , 0, 0.5, 0.5).draw(BLACK, false); (Joypads[0].dir *0.25 ).draw(RED);
Rect_C( 0.6, 0, 0.5, 0.5).draw(BLACK, false); (Joypads[0].dir_a[0]*0.25+Vec2(-0.6, 0)).draw(RED);
Rect_C(-0.6, 0, 0.5, 0.5).draw(BLACK, false); (Joypads[0].dir_a[1]*0.25+Vec2( 0.6, 0)).draw(RED);

}

else


D.text(0, 0, S+"No Joypads detected" );
}
(This post was last modified: 11-14-2021 03:26 AM by battlegear2099.)
11-14-2021 02:18 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Direct Input Help
don't compare strings, just check buttons individually
Joypads[0].b(i)
11-14-2021 04:02 AM
Find all posts by this user Quote this message in a reply
battlegear2099 Offline
Member

Post: #10
RE: Direct Input Help
(11-14-2021 04:02 AM)Esenthel Wrote:  don't compare strings, just check buttons individually
Joypads[0].b(i)

ok ya I see that now, allot less complex
than what I was trying.

OK thats all working now, found joystick/gamepad old 2009 GamePad TOPHAT/PS3 GAMEPAD input link code on here -- user sydbod and barthap.
https://www.esenthel.com/forum/showthrea...t=joystick
https://www.esenthel.com/forum/showthread.php?tid=2946

Incase anyone needs this
for use on the Game Basic Multiple World Example.
Draws All inputs mouse, keyboard, joypad/gamepad/joystick all buttons clicked
to screen. no rumble vibration/ force feedback etc added yet will add when tested and working soon.
And cleanup add more code. I will add the input movement code in the class player when I complete and test it.

**************************************************************************
this block -> commented out
//enum {TRIGGER,BUTTON2,BUTTON3,BUTTON4,BUTTON5,BUTTON6,BUTTON7,BUTTON8};
//enum {JOYPAD1,JOYPAD2,JOYPAD3,JOYPAD4};

note: I could not get the function, Inputbutton JoyButton function to work that was in this old code, says errror no overloaded function takes 4 arguments when trying to compile, I did fine the error on the internet but on just c ++ so I read that, but my understanding is limited, so I am not sure and I could not find any esenthel code that is using the function that worked. so I commented out the function and enum's and used another joy button method instead and built ok. So is there a error in the format on this old code or has the function in api changed?. I like to know on how to fix and use or why it wont work if its a simple fix.

//InputButton JoyButton (INPUT_JOYPAD, TRIGGER, JOYPAD1, NULL); // //InputButton(INPUT_TYPE type, Byte button, Byte device=0, Bool (*req)()=NULL)
********************************************************************




MAIN
******
Add to top of file
**************
Vec2 point , // point position
axis , // x,y joystick values
extra , // rudder,throttle values
tophat; // tophat vectors
int TRIGGERL ;
int TRIGGERR ;
Char c; // character pressed
*****************************************************


void Draw()

{
Renderer(Render);
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 = Joypads[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 = Joypads[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 = Joypads[0].dir;

D.text(1, 0.7, Joypads[0].name());
Str buttons; FREP(32)buttons+=Joypads[0].b(i); D.text(Rect_C(1, 0.6, 0, 0), S+"Buttons:\n"+buttons);

D.text(0, 0, S+"JoystickTophat/dpad Vec x : "+tophat+ " JoystickTophat/dpad Vec y : "+tophat ); // draw joystick tophat/dpad Vec value

TRIGGERL = Joypads[0].trigger[0];
TRIGGERR = Joypads[0].trigger[1];


//No InputButton JoyButton Function working +JoyButton.on() ) commented out
*******************************************************************
JoyButton.button=button 1;
D.text(0,0.0, S+"Joystick JoyButton(button 0)=Stick(button 1) : "+JoyButton.on() ); // draw trigger state
JoyButton.button=button 8;
D.text(0,-0.1, S+"Joystick JoyButton(button 7)=Stick(button 8) : "+JoyButton.on() ); // draw button state
***********************************************************

//JoyButton.button=TRIGGERL;
// D.text(0,-0.2, S+"Joystick JoyButton(button 0)=Stick(TRIGGERL) : "+TRIGGERL); // draw trigger state
// JoyButton.button=TRIGGERR;
// D.text(0,-0.3, S+"Joystick JoyButton(button 7)=Stick(TRIGGERR) : "+TRIGGERR); // draw button state

D.text(0,-0.2, S+"Joystick JoyButton(button 0)=Stick(TRIGGERL) : "+TRIGGERL+ "Joystick JoyButton(button 7)=Stick(TRIGGERR) : "+TRIGGERR); // draw button state

}
(This post was last modified: 11-17-2021 04:07 AM by battlegear2099.)
11-15-2021 02:37 AM
Find all posts by this user Quote this message in a reply
Post Reply