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

Author Topic: AxisPOV always zero, others fine?  (Read 4231 times)

0 Members and 1 Guest are viewing this topic.

Tain

  • Newbie
  • *
  • Posts: 4
    • View Profile
AxisPOV always zero, others fine?
« on: January 02, 2010, 06:15:59 am »
I cannot seem to get any sort of non-zero result from any POV hats for the life of me. I've tried two different controllers; a standard Xbox 360 wired controller, and an Xbox 360 arcade stick with no analog axes.

Here's a simple program that I can close using an analog stick but not a POV hat:

Code: [Select]
int main()
{

sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test Window");

while (App.IsOpened())
{

sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}

if (App.GetInput().GetJoystickAxis(0, sf::Joy::AxisPOV) == 45)
App.Close();

if (App.GetInput().GetJoystickAxis(0, sf::Joy::AxisX) == 100)
App.Close();

}

return 0;
}


I hope I'm missing something obvious.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
AxisPOV always zero, others fine?
« Reply #1 on: January 02, 2010, 11:53:30 am »
Are you sure that something on your pad is mapped to the POV?
Laurent Gomila - SFML developer

Tain

  • Newbie
  • *
  • Posts: 4
    • View Profile
AxisPOV always zero, others fine?
« Reply #2 on: January 02, 2010, 01:29:49 pm »
Pretty sure, yeah. Other programs recognize the d-pad directions as POV Hat directions.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
AxisPOV always zero, others fine?
« Reply #3 on: January 02, 2010, 02:10:13 pm »
What is your OS?
Laurent Gomila - SFML developer

Tain

  • Newbie
  • *
  • Posts: 4
    • View Profile
AxisPOV always zero, others fine?
« Reply #4 on: January 02, 2010, 08:00:08 pm »
Windows 7. Wish I had something else to test it with, but everybody here is using it.

Dravere

  • Newbie
  • *
  • Posts: 37
    • View Profile
AxisPOV always zero, others fine?
« Reply #5 on: January 02, 2010, 09:54:14 pm »
Just tested it too:
Win7 x64 POV hat always 0
WinXP x86 POV hat always 0

Code:
Code: [Select]
#include <SFML/Graphics.hpp>

#include <string>
#include <sstream>
#include <iostream>


std::string toString(float val)
{
std::ostringstream oss;
oss << val;
return oss.str();
}


int main()
{
sf::RenderWindow app(sf::VideoMode(800, 600, 32), "Test Window");

sf::String text;
sf::Event evt;

while(app.IsOpened())
{
while(app.GetEvent(evt))
{
if (evt.Type == sf::Event::Closed)
{
app.Close();
}
}

float pov = app.GetInput().GetJoystickAxis(0, sf::Joy::AxisPOV);
float x = app.GetInput().GetJoystickAxis(0, sf::Joy::AxisX);

text.SetText("POV: " +  toString(pov) + "   X: " + toString(x));

app.Clear();
app.Draw(text);

app.Display();
}

return 0;
}


Joystick:
Thrustmaster 16.000M

If I look at the game controller settings in the control panel, the POV hat is mapped and does function.

Dravere

Dravere

  • Newbie
  • *
  • Posts: 37
    • View Profile
AxisPOV always zero, others fine?
« Reply #6 on: January 02, 2010, 11:08:29 pm »
Asked a friend to test my code too. His OS:
Vista x64 SP2

Joystick:
Saitek ST290 Pro

Result:
POV is always 0.

Dravere

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
AxisPOV always zero, others fine?
« Reply #7 on: January 03, 2010, 12:49:28 am »
What about the other buttons and axes? Are they working?

I don't have a joystick with POV, so I'll need someone who is able to modify and recompile SFML to do some tests.
Laurent Gomila - SFML developer

Dravere

  • Newbie
  • *
  • Posts: 37
    • View Profile
AxisPOV always zero, others fine?
« Reply #8 on: January 03, 2010, 04:54:02 am »
Everything else seems to work.
And for some ridiculous reason I didn't sleep and searched the bug.
In "void Joystick::Initialize(unsigned int Index)" in "Joystick.cpp" you get the number of axes and assume that POV is also an axis. But POV isn't counted as axis. If you want to see if the joystick supports POV you need to check the dwCaps attribute for JOYCAPS_HASPOV.
http://msdn.microsoft.com/en-us/library/dd757103.aspx

Hmmm, looking at that code ...
There could be another error. You assume if dwNumAxes is for example 4, that those are X, Y, Z and R. But this isn't guaranteed. Also in that situation you need to check the dwCaps attribute or the system axis could be mapped to the wrong sfml axis.

**
Edit:
... When I turned off the computer I realised I wrote something wrong. Couldn't get asleep without correcting it first ... dude, I need professional help :lol:

It isn't a problem, that it is mapped the wrong way, it will be simply ignored. We take again the example with dwNumAxes == 4.
Let us say it is X, Y, Z and U. In WindowImpl you assume that the axes are in order. So you check sf::Joy::AxisX (0), sf::Joy::AxisY (1), sf::Joy::AxisZ (2) and sf::Joy::AxisR (3). But in our example there is no R. So you won't send any event about sf::Joy::AxisU (4). The same way you ignore sf::Joy::AxisPOV and don't send any event for this axis, but the POV also isn't counted as axis.
Sorry, but it seems you will need some bigger rework todo ;)

Ok, but now I'm going to bed... 5:20 AM ...

Dravere

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
AxisPOV always zero, others fine?
« Reply #9 on: January 03, 2010, 02:06:50 pm »
Wow, thanks a lot for your help :)

Quote
Sorry, but it seems you will need some bigger rework todo

Not that much actually, just replacing GetAxesCount() by something like IsAxisSupported(AxisType) ;)
Laurent Gomila - SFML developer

Tain

  • Newbie
  • *
  • Posts: 4
    • View Profile
AxisPOV always zero, others fine?
« Reply #10 on: January 08, 2010, 03:31:50 am »
I just tried the latest from the SVN and found that my main arcade stick now works (X360 Street Fighter IV TE Stick), POV and all, whereas a second one that I have (X360 Hori Fighting Stick EX2) doesn't work at all (no buttons or axes).

I tried the EX2 on 1.5 again and found that it doesn't work there, either, despite Windows and other programs recognizing it just fine. I found that to be really strange.

Also, the standard Xbox 360 USB controller's POV hat works fine now.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
AxisPOV always zero, others fine?
« Reply #11 on: January 08, 2010, 07:44:14 am »
Quote
I just tried the latest from the SVN and found that my main arcade stick now works (X360 Street Fighter IV TE Stick), POV and all

Great, thanks for your feedback :)

Quote
whereas a second one that I have (X360 Hori Fighting Stick EX2) doesn't work at all (no buttons or axes).

That's strange. Would you be able to debug your application and see what happens when SFML initializes the joysticks (using step by step execution)? That would help a lot.
Laurent Gomila - SFML developer

 

anything