Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - CopyConstructor

Pages: [1]
1
Window / Bug in Window/Win32/JoystickImpl.cpp
« on: February 24, 2016, 09:09:08 pm »
Hi,

For me, querying the axis position of the POV is buggy under windows:
 ( Joystick::getAxisPosition(0,Joystick::Axis::PovX) )  it returns strange values.

The reason is located in Window/Win32/JoystickImpl.cpp:

JoystickState JoystickImpl::update()
{
    JOYINFOEX pos;
    pos.dwFlags  = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | JOY_RETURNBUTTONS;
    pos.dwFlags |= (m_caps.wCaps & JOYCAPS_POVCTS) ? JOY_RETURNPOVCTS : JOY_RETURNPOV;
    pos.dwSize   = sizeof(JOYINFOEX);
    if (joyGetPosEx(m_index, &pos) == JOYERR_NOERROR)
    {
....    
       // Special case for POV, it is given as an angle
        if (pos.dwPOV != 0xFFFF)
        {
            float angle = pos.dwPOV / 18000.f * 3.141592654f;  //Bug: angle is in *degrees*!
            state.axes[Joystick::PovX] = std::sin(angle) * 100;
            state.axes[Joystick::PovY] = std::cos(angle) * 100;
        }
        else
        {
            state.axes[Joystick::PovX] = 0;
            state.axes[Joystick::PovY] = 0;
        }
  }
...
}
 

The error is pos.dwPOV is in degrees already! (*100)
For me, this degrees either with Flag JOYCAPS_POVCTS or JOY_RETURNPOVCTS.
Only the convertion for range [-100 .. 100] is needed.
( But I would really recommend to use a angle (radiants or degrees) for the POV, all other is not intuitive. )

According to MSDN this is right:

dwPOV
Current position of the point-of-view control. Values for this member are in the range 0 through 35,900. These values represent the angle, in degrees, of each view multiplied by 100.
JOY_RETURNPOV   
The dwPOV member contains valid information about the point-of-view control, expressed in discrete units.
JOY_RETURNPOVCTS   
The dwPOV member contains valid information about the point-of-view control expressed in continuous, one-hundredth degree units.

https://msdn.microsoft.com/de-de/library/windows/desktop/dd757112.aspx

My Situation:
Joystick is: Speedlink Phantom Hawk
Driver: default windows 10 driver (nothing additional installed from manufacturer)
OS: Windows 10


Workaround:
Use joyGetPosEx() by your own:
                               
#include <Mmsystem.h>

        JOYINFOEX pos;
        pos.dwFlags = JOY_RETURNPOVCTS;// or  JOY_RETURNPOV give the same: degrees for my stick
        pos.dwSize = sizeof(JOYINFOEX);
        if (joyGetPosEx(JOYSTICK_1, &pos) == JOYERR_NOERROR)
        {
                if (pos.dwPOV != JOY_POV_CENTERED)
                { // use pos.dwPOV
                }
        }
.....

This values are correct for my joystick:
#define JOY_POV_CENTERED                (WORD) -1
#define JOY_POV_FORWARD                 JOY_POVFORWARD
#define JOY_POV_RIGHT_FORWARD   4500
#define JOY_POV_RIGHT                   JOY_POVRIGHT
#define JOY_POV_RIGHT_BACKWARD  13500
#define JOY_POV_BACKWARD                JOY_POVBACKWARD
#define JOY_POV_LEFT_BACKWARD   22500
#define JOY_POV_LEFT                    JOY_POVLEFT
#define JOY_POV_LEFT_FORWARD    31500
 

 
This bug was already noticed 4 Years ago!
Why the hack is this not corrected?

http://fr.sfml-dev.org/forums/index.php?topic=7054.0



Pages: [1]