-
July 31st, 2014, 11:57 AM
#1
[win32] - about joystick
i'm trying calculate the button selection... i'm mean using 1,2,3,4,5,6,7....
what isn't right with these calculation:
Code:
lngButton = (log(b.dwButtons) / log(2)) + 1;
some numbers are the same with diferent buttons.
so what i'm doing wrong with calculation?
-
July 31st, 2014, 12:03 PM
#2
Re: [win32] - about joystick
Don't understand what you are trying to do??
What values can b.dwButtons take and what corresponding vakue do you want lngButton to be?? What is the type of lngButton?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 31st, 2014, 12:06 PM
#3
Re: [win32] - about joystick
Originally Posted by 2kaud
Don't understand what you are trying to do??
What values can b.dwButtons take and what corresponding vakue do you want lngButton to be?? What is the type of lngButton?
i know the 2^x=buttonvalue, but i want to know the x. i forget some math... but i'm read more.
the lngButton is long
-
July 31st, 2014, 12:10 PM
#4
Re: [win32] - about joystick
more easy than i thot:
Code:
long lngButton=0;
if (b.dwButtons!=0)
{
lngButton = log2(b.dwButtons);
}
and now works.
how can i test how many joysticks are connect to pc?
how i know that was joystick 1 be used?
-
July 31st, 2014, 12:20 PM
#5
Re: [win32] - about joystick
What you want to know is the bit position that is set - yes?
Have a look at _BitScanForward()
http://msdn.microsoft.com/en-us/libr...vs.120%29.aspx
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 31st, 2014, 12:26 PM
#6
Re: [win32] - about joystick
Originally Posted by 2kaud
please see my last post
-
August 1st, 2014, 11:10 AM
#7
Re: [win32] - about joystick
sorry... you have right... the JOYINFOEX.dwButtons it's a bit buttons
let me ask: how can i combine the buttons?
Code:
if(b.dwButtons==JOY_BUTTON1 & JOY_BUTTON2)
MessageBox(NULL,"hi", "hello",MB_OK);
isn't the same of button 1 and 2 beeing pressed in same time?
-
August 1st, 2014, 12:40 PM
#8
Re: [win32] - about joystick
try this
Code:
if (((b.dwButtons & JOY_BUTTON1) == JOY_BUTTON1) && ((b.dwButtons & JOY_BUTTON2) == JOY_BUTTON2)) {
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 1st, 2014, 12:44 PM
#9
Re: [win32] - about joystick
Originally Posted by 2kaud
try this
Code:
if (((b.dwButtons & JOY_BUTTON1) == JOY_BUTTON1) && ((b.dwButtons & JOY_BUTTON2) == JOY_BUTTON2)) {
works fine thanks.... i'm sorry, but that line can be simplificated?
-
August 1st, 2014, 12:51 PM
#10
Re: [win32] - about joystick
Depending...
It might simplify to
Code:
if ((b.dwButtons & JOY_BUTTON1) && (b.dwButtons & JOY_BUTTON2)) {
or even
Code:
if (b.dwButtons & (JOY_BUTTON1 | JOY_BUTTON2)) {
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 1st, 2014, 01:01 PM
#11
Re: [win32] - about joystick
Originally Posted by 2kaud
Depending...
It might simplify to
Code:
if ((b.dwButtons & JOY_BUTTON1) && (b.dwButtons & JOY_BUTTON2)) {
or even
Code:
if (b.dwButtons & (JOY_BUTTON1 | JOY_BUTTON2)) {
Thanks for all
-
August 1st, 2014, 01:08 PM
#12
Re: [win32] - about joystick
sorry, but can i do something like these:
if(buttons==(JOY_BUTTON1 | JOY_BUTTON2))
//do something
???
i mean convert the b.dwButtons to buttons
-
August 1st, 2014, 01:14 PM
#13
Re: [win32] - about joystick
i did these:
Code:
JOYINFOEX b;
b.dwSize=sizeof(JOYINFOEX );
b.dwFlags=JOY_RETURNALL;
joyGetPosEx(JOYSTICKID1,&b);
long h =(b.dwButtons & b.dwButtons);
if (h==(JOY_BUTTON1 | JOY_BUTTON2))
MessageBox(NULL,"hi beaury", "hello",MB_OK);
works... but tell me what you think about the conversion?
i have 1 personal reason for do these, but tell me something please
Last edited by Cambalinho; August 1st, 2014 at 01:16 PM.
-
August 1st, 2014, 02:43 PM
#14
Re: [win32] - about joystick
Code:
long h =(b.dwButtons & b.dwButtons);
this is just
Code:
long h = b.dwButtons;
Code:
if (h==(JOY_BUTTON1 | JOY_BUTTON2))
yes providing no other bits in h are set. If other bits in h are set then the compare will fail. That is why I used bitwise and. If the only bits in b.dwButtons that can be set at the same time are JOY_BUTTON1 JOY_BUTTON2 then
Code:
if (b.dwButtons == (JOY_BUTTON1 | JOY_BUTTON2))
should be OK but IMO I would not recommend doing it like this. If in the future there was a change in the spec and bits other than JOY_BUTTON1 JOY_BUTTON2 could be set at the same time then this code would fail.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 1st, 2014, 03:37 PM
#15
Re: [win32] - about joystick
Originally Posted by 2kaud
Code:
long h =(b.dwButtons & b.dwButtons);
this is just
Code:
long h = b.dwButtons;
Code:
if (h==(JOY_BUTTON1 | JOY_BUTTON2))
yes providing no other bits in h are set. If other bits in h are set then the compare will fail. That is why I used bitwise and. If the only bits in b.dwButtons that can be set at the same time are JOY_BUTTON1 JOY_BUTTON2 then
Code:
if (b.dwButtons == (JOY_BUTTON1 | JOY_BUTTON2))
should be OK but IMO I would not recommend doing it like this. If in the future there was a change in the spec and bits other than JOY_BUTTON1 JOY_BUTTON2 could be set at the same time then this code would fail.
see what i'm doing with joystick:
Code:
else if(wParam==JoystickTimer)
{
JOYINFOEX b;
b.dwSize=sizeof(JOYINFOEX );
b.dwFlags=JOY_RETURNALL;
//cicle all possible joysticks
for (int i=0, i<16; i++)
{
int direction=0;
if(joyGetPosEx(i,&b)!= JOYERR_NOERROR) //if theres any error then continue to next joystick
continue;
long h =b.dwButtons;
//testing the directions
//will be 8 directions(inclued diagonals)
if (b.dwXpos == 0 && b.dwYpos == 0)
{
direction=1
}
else if (b.dwXpos == 0 && b.dwYpos == 65535)
{
direction=2;
}
Joystick(i, direction,h);
}
i'm doing something wrong with directionals... but i will do some consts\enum
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|