SFML community forums
Help => Graphics => Topic started by: Williamson on December 03, 2008, 07:09:11 pm
-
Hi everyone!
Thanks to Wizzard, I managed to make a fair amount of progress, but I have hit another snag: I need to get the absolute coordinates of a point when it is clicked (so, not relative to the sf::View, but to the world itself). I tried
sf::Vector2f MousePosAbsolute;
MousePosAbsolute.x = displayWindow.GetInput().GetMouseX();
MousePosAbsolute.y = displayWindow.GetInput().GetMouseY();
But it didnt seem to work.
Have I done something wrong? Or am I barking up the wrong tree?
Thanks!
Williamson
-
This gets the mouse position in window coordinates.
In SVN there's a RenderWindow::ConvertCoords function that does exactly what you want.
-
Thanks!
So there isnt one in the current, stable 1.3 version of SFML?
Williamson
-
It is in SFML version 1.3 too.
sf::Vector2f MousePosAbsolute = displayWindow.ConvertCoords(displayWindow.GetInput().GetMouseX(), displayWindow.GetInput().GetMouseY());
-
I thought that THAT was used to get the position relative to the view.
Williamson
-
It is in SFML version 1.3 too.
Oops :lol:
-
I thought that THAT was used to get the position relative to the view.
In the example code I gave you, I was using two completely separate views, one to draw GUI objects and one to draw world objects.
// Returns the view that RenderWindow creates automatically
displayWindow.GetDefaultView();
RenderWindow creates a view automatically, that, by default, is perfect to draw GUI objects.
// Creates a view that fits the whole window
sf::View worldView = sf::View(sf::Vector2f(playerX, playerY), );
The world view, which describes the world from the player's perspective, needs to be created in order to draw world objects.
// Sets the coordinate system and Draws and Renders all Drawables
displayWindow.SetView(worldView); // Use world coordinate system
displayWindow.Draw(worldMap); // Draw the Map
displayWindow.SetView(App.GetDefaultView()); // Use window coordinate system
displayWindow.Draw(guiPlayer); // Draw the Player
This brings us back to the example code I showed you before.
sf::Vector2f MousePosAbsolute = displayWindow.ConvertCoords(displayWindow.GetInput().GetMouseX(), displayWindow.GetInput().GetMouseY(), worldView);
To get the position of the mouse from the world's view, simply use the above code.
It's important to realize that views are just cameras for your application, they change the meaning of objects' positions based on how they're viewing it.
-
It is in SFML version 1.3 too.
I really think that it was buggy in version 1.3.
The SVN version seems quite stable though.
-
Its really weird: no matter which I try, I get the same result: the coordinates that I clicked from the views point of view, rather than those of the world.
I am SURE that shouldnt be happening :shock:
Should I try the SVN version?
Williamson
-
Yes (http://www.sfml-dev.org/wiki/en/tutorials/getsvnversion), you should try to use the SVN version.
-
In any case, I'm sure that there is a bug. With this code:
sf::Vector2f MousePosAbsolute = displayWindow.ConvertCoords(displayWindow.GetInput().GetMouseX(), displayWindow.GetInput().GetMouseY());
sf::Vector2f MousePosB;
MousePosB.x = displayWindow.GetInput().GetMouseX();
MousePosB.y = displayWindow.GetInput().GetMouseY();
std::cout << "Type 1:" << ((int)MousePosB.x - (int)MousePosB.x%64)/64 << ":" << ((int)MousePosB.y - (int)MousePosB.y%64)/64 << std::endl;
std::cout << "Type 2:" << ((int)MousePosAbsolute.x - (int)MousePosAbsolute.x%64)/64 << ":" << ((int)MousePosAbsolute.y - (int)MousePosAbsolute.y%64)/64 << std::endl;
I get this (and I do move the view around):
Type 1:0:0
Type 2:0:0
Type 1:1:0
Type 2:1:0
Type 1:2:0
Type 2:2:0
Type 1:3:0
Type 2:3:0
Type 1:4:0
Type 2:4:0
Type 1:0:0
Type 2:0:0
Type 1:1:0
Type 2:1:0
Type 1:2:0
Type 2:2:0
Type 1:3:0
Type 2:3:0
Type 1:4:0
Type 2:4:0
I'm gonna try installing the SVN version now.
Williamson
-
Well, as far as I could tell, I only had to copy the new include file to the correct directory. I recompiled, and.... :
InterfaceGraphique.cpp:(.text+0x18b5): undefined reference to `sf::Unicode::Text::Text(char const*)'
InterfaceGraphique.cpp:(.text+0x18d3): undefined reference to `sf::String::String(sf::Unicode::Text const&, sf::Font const&, float)'
InterfaceGraphique.cpp:(.text+0x1901): undefined reference to `sf::Unicode::Text::Text(char const*)'
InterfaceGraphique.cpp:(.text+0x191f): undefined reference to `sf::String::String(sf::Unicode::Text const&, sf::Font const&, float)'
InterfaceGraphique.cpp:(.text+0x1b4b): undefined reference to `sf::Unicode::Text::Text(char const*)'
InterfaceGraphique.cpp:(.text+0x1b5d): undefined reference to `sf::String::SetText(sf::Unicode::Text const&)'
InterfaceGraphique.cpp:(.text+0x1bde): undefined reference to `sf::Unicode::Text::Text(char const*)'
InterfaceGraphique.cpp:(.text+0x1bf0): undefined reference to `sf::String::SetText(sf::Unicode::Text const&)'
InterfaceGraphique.cpp:(.text+0x1cde): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
InterfaceGraphique.cpp:(.text+0x1cf0): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
InterfaceGraphique.cpp:(.text+0x1d02): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
InterfaceGraphique.cpp:(.text+0x1d14): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
InterfaceGraphique.cpp:(.text+0x1f25): undefined reference to `sf::Unicode::Text::Text(char const*)'
InterfaceGraphique.cpp:(.text+0x1f37): undefined reference to `sf::String::SetText(sf::Unicode::Text const&)'
InterfaceGraphique.cpp:(.text+0x1fb4): undefined reference to `sf::Unicode::Text::Text(char const*)'
InterfaceGraphique.cpp:(.text+0x1fc6): undefined reference to `sf::String::SetText(sf::Unicode::Text const&)'
InterfaceGraphique.o: In function `InterfaceGraphique::InterfaceGraphique()':
InterfaceGraphique.cpp:(.text+0x3897): undefined reference to `sf::Font::ourDefaultCharset'
InterfaceGraphique.cpp:(.text+0x389f): undefined reference to `sf::Unicode::Text::Text(unsigned int const*)'
InterfaceGraphique.cpp:(.text+0x38da): undefined reference to `sf::Font::LoadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, sf::Unicode::Text const&)'
InterfaceGraphique.o: In function `InterfaceGraphique::InterfaceGraphique()':
InterfaceGraphique.cpp:(.text+0x5cef): undefined reference to `sf::Font::ourDefaultCharset'
InterfaceGraphique.cpp:(.text+0x5cf7): undefined reference to `sf::Unicode::Text::Text(unsigned int const*)'
InterfaceGraphique.cpp:(.text+0x5d32): undefined reference to `sf::Font::LoadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, sf::Unicode::Text const&)'
collect2: ld returned 1 exit status
:shock: ARGH!
Did I forget a step, cos this code worked fine before.
Williamson
-
You have to recompile SFML, you can't just use the new headers with the old binaries :roll:
-
Thanks!
Ok.
Errrrrr
This may sound like a stupid question, but...
How? :oops:
Williamson
-
Read the tutorial: "Getting started -- SFML and [your compiler]" :)
-
Thanks, hadnt seen that.
But I am using linux(gcc), and when I do make install, it tells me the libs are missing.
I tried using the old ones, but no cigar.
Should the .so s be on the SVN?
Thanks for the help so far!
Williamson
-
I think you should "make" first to build the binary, then "make install"
-
Thanks, but I guess thi s just isnt my week! :(
In file included from SoundFile.cpp:29:
../../SFML/Audio/SoundFileDefault.hpp:32:21: error: sndfile.h: No such file or directory
In file included from SoundFile.cpp:29:
../../SFML/Audio/SoundFileDefault.hpp:128: error: ‘sf_count_t’ does not name a type
../../SFML/Audio/SoundFileDefault.hpp:129: error: ‘sf_count_t’ does not name a type
../../SFML/Audio/SoundFileDefault.hpp:130: error: ‘sf_count_t’ does not name a type
../../SFML/Audio/SoundFileDefault.hpp:131: error: ‘sf_count_t’ does not name a type
../../SFML/Audio/SoundFileDefault.hpp:132: error: ‘sf_count_t’ does not name a type
../../SFML/Audio/SoundFileDefault.hpp:141: error: ‘sf_count_t’ does not name a type
../../SFML/Audio/SoundFileDefault.hpp:147: error: ISO C++ forbids declaration of ‘SNDFILE’ with no type
../../SFML/Audio/SoundFileDefault.hpp:147: error: expected ‘;’ before ‘*’ token
make[2]: *** [SoundFile.o] Error 1
make[2]: Leaving directory `/home/thomas/Desktop/SFMLSVNcheckout/src/SFML/Audio'
make[1]: *** [sfml-audio] Error 2
make[1]: Leaving directory `/home/thomas/Desktop/SFMLSVNcheckout/src/SFML'
make: *** [sfml] Error 2
I'll try redownloading it, to see if that make a difference
Williamson
[EDIT: Nope, still same problem]
-
You forget 'sudo apt-get install libsndfile-dev' (or something like that). :wink:
-
Thanks everyone!
It works great now
Williamson
-
Well...
This cant be good...
I recompiled, the same code as before, and got the same result.
The convertCoordinates function doesnt appear to do anything:
Type 1:5:5
Type 2:5:5
Type 1:11:3
Type 2:11:3
Type 1:10:6
Type 2:10:6
Type 1:6:4
Type 2:6:4
Type 1:5:6
Type 2:5:6
Type 1:9:4
Type 2:9:4
Type 1:7:2
Type 2:7:2
Type 1:7:5
Type 2:7:5
Type 1:13:5
Type 2:13:5
Type 1:12:2
Type 2:12:2
Type 1:11:2
Type 2:11:2
Type 1:10:5
Type 2:10:5
Type 1:14:6
Type 2:14:6
Is this an error caused by me?
Williamson
-
I found what was wrong!
It was a REALLY stupid mistake!
I put :
sf::Vector2f MousePosAbsolute = displayWindow.ConvertCoords(displayWindow.GetInput().GetMouseX(), displayWindow.GetInput().GetMouseY());
Instead of :
sf::Vector2f MousePosAbsolute = displayWindow.ConvertCoords(displayWindow.GetInput().GetMouseX(), displayWindow.GetInput().GetMouseY(), &view);
It does exactly what I want now :)
Thanks to all for your help and patience
Williamson