SFML community forums
Help => Window => Topic started by: Tain 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:
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.
-
Are you sure that something on your pad is mapped to the POV?
-
Pretty sure, yeah. Other programs recognize the d-pad directions as POV Hat directions.
-
What is your OS?
-
Windows 7. Wish I had something else to test it with, but everybody here is using it.
-
Just tested it too:
Win7 x64 POV hat always 0
WinXP x86 POV hat always 0
Code:
#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
-
Asked a friend to test my code too. His OS:
Vista x64 SP2
Joystick:
Saitek ST290 Pro
Result:
POV is always 0.
Dravere
-
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.
-
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
-
Wow, thanks a lot for your help :)
Sorry, but it seems you will need some bigger rework todo
Not that much actually, just replacing GetAxesCount() by something like IsAxisSupported(AxisType) ;)
-
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.
-
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 :)
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.