SFML community forums
Help => Window => Topic started by: chrisciscoioio on September 29, 2012, 08:19:44 pm
-
I am going to start this off with I am sure I am missing something, but I am not sure what.
sf::Vector2i pos = sf::Mouse::getPosition(*window); doesnt seem to be returning the correct y value, the x value appears right however, I have attached an image that shows where my mouse is when clicked compared with where the point appears.
[attachment deleted by admin]
-
The image tells nothing..I don't get your problem, remember that it returns pixels not coords and that y is positive the lower cursor is.
-
The top left corner is at (0, 0).
-
If I click on the black dot it creates a point at the green dot.
I guess this is because I am rendering in OpenGL, and just using SFML for windows and input.
How can I transform the one set of coords into the other?
-
I think its because of the confusion between local coordinates vs world coordinates. If you are using sf::Sprite, you can use Sprite.TransformToGlobal or Sprite.TransformToLocal to convert your coordinates.
-
I am not using sf::Sprite.
I think that is the issue, I am just not sure how to fix it, sf::Sprite is not an option.
-
what are you using then, if not sf::Sprite?
if you are using opengl, then I guess you have to apply the right transformations to your GL_MODELVIEW matrix at the right place i.e before you issue your draw commands. you can refer to the documentation of glLoadMatrix(), glLoadIdentity(), glPushMatrix() and glPopMatrix(). These methods will come handy.
-
Drawing is fine, this is an issue I am having integrating SFML with OpenGL to get world coords.
What I don't have is converting the sf::mouse position to world coords. Everything else already works as long as I can get the correct coords.
Right now on my screen, the x works fine, because I am not moving the camera, but the y value is off, if I am above the mid line of the screen it is below it, and if I am below the mid line it is above it.
-
aha ok.
so the coordinate system is reversed I guess. you have to apply correction to your y-value. If I understood correctly, it seems like the mid line is somehow corresponds to the center of the screen. If your x-value is good, then simply negating the y-value should solve the problem. Otherwise, may be you can try the following:
SFML- top-left = (0, 0). mouse position should be relative to this.
w, h = screen width, screen height
assuming your (0, 0) is (w/2, h/2). screen center = your camera center. (this is my assumption).
you can apply correction to your mouse_x and mouse_y
mouse_x = mouse_x - w/2
mouse_y = mouse_y - h/2
if your center is different you can apply correction to your received mouse coordinates accordingly.
-
That doesn't actually work but I played with a variety of systems, and I found one that solves this, baring any camera movement which I would have to adjust by.
But if I take the screenHeight and minus the pos.y it will work.