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

Author Topic: different results on several compiles with same code  (Read 5251 times)

0 Members and 1 Guest are viewing this topic.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: different results on several compiles with same code
« Reply #15 on: November 30, 2013, 10:03:59 pm »
You still dont use the mouse position from the event. The stale, old position data from the superfluous getPosition call outside the event loop is wrong. If on arch linux the frequency of mouse events is lower or the OS settings allow moving the mouse pointer faster, you will get a higher error from this.

Btw., I would still suggest using mapPixelToCoords.

metulburr

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: different results on several compiles with same code
« Reply #16 on: December 01, 2013, 01:20:21 pm »
@binary1248
In the past 3 years of programming , i have never used a debugger.  I have always used print statements to determine a value. I attempted to figure out how to use the debugger in Geany IDE, but i couldnt figure the process out.

@windertime
are you referring to:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

int main(){
    sf::RenderWindow window(sf::VideoMode(600,400), "Title", sf::Style::Titlebar | sf::Style::Close);
   
    sf::Vector2f position;
    sf::RectangleShape rect;
    float width, height;
   
    rect.setFillColor(sf::Color(200,200,200));
    width = 100.0;
    height = 20.0;
    position = {100.0,100.0};
    rect.setSize(sf::Vector2f(width, height));
    rect.setPosition(position);
   
    sf::Vector2i mouse;

    while (window.isOpen()){
        sf::Event event;
        while(window.pollEvent(event)){
            if (event.type == sf::Event::Closed)
                window.close();
            else if(event.type == sf::Event::MouseMoved){
                int mousex = event.mouseMove.x;
                int mousey = event.mouseMove.y;
               
                if (mousex > position.x &&
                mousex < (position.x + width) &&
                mousey > position.y &&
                mousey < position.y + height){
                    rect.setFillColor(sf::Color(50,50,50));
                }
                else{
                    rect.setFillColor(sf::Color(200,200,200));
                }
            }
        }
        window.clear(sf::Color::Black);
        window.draw(rect);
        window.display();
    }
}
because i still get the same problem.

And regarding mapPixelToCoors. What does this even do? Yes i read the docs. but "Convert a point from target coordinates to world coordinates. " doesn't make sense to me. Trying to read the SFML documentation in the eyes of a newbie is like trying to learn Greek. 

Quote
This function finds the pixel of the render-target that matches the given 2D point. In other words, it goes through the same process as the graphics card, to compute the final position of a rendered point.

Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render-target, this assertion is not true anymore, ie. a point located at (150, 75) in your 2D world may map to the pixel (10, 50) of your render-target – if the view is translated by (140, 25).

This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render-target.
I dont know if this is just me or not, but i read this over like 10 times and still i am like WTF?

EDIT:
ok i think you mean this?
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

int main(){
    sf::RenderWindow window(sf::VideoMode(600,400), "Title", sf::Style::Titlebar | sf::Style::Close);
   
    sf::Vector2f mouse;
    sf::Vector2f position;
    sf::RectangleShape rect;
    float width, height;
   
    rect.setFillColor(sf::Color(200,200,200));
    width = 100.0;
    height = 20.0;
    position = {100.0,100.0};
    rect.setSize(sf::Vector2f(width, height));
    rect.setPosition(position);
   

    while (window.isOpen()){
        sf::Event event;
        while(window.pollEvent(event)){
            if (event.type == sf::Event::Closed)
                window.close();
            else if(event.type == sf::Event::MouseMoved){
                mouse = window.mapPixelToCoords(sf::Vector2i(event.mouseMove.x,event.mouseMove.y));
            }
               
            if (mouse.x > position.x &&
            mouse.x < (position.x + width) &&
            mouse.y > position.y &&
            mouse.y < position.y + height){
                rect.setFillColor(sf::Color(50,50,50));
            }
            else{
                rect.setFillColor(sf::Color(200,200,200));
            }
           
        }
        window.clear(sf::Color::Black);
        window.draw(rect);
        window.display();
    }
}
if so even after using mappixeltocoords, i stll have the same problem.
« Last Edit: December 01, 2013, 01:49:08 pm by metulburr »
OS Ubuntu 13.04, Arch Linux, Gentoo, Windows 7/8
SFML 2.1
Ati Radeon HD 6770

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: different results on several compiles with same code
« Reply #17 on: December 01, 2013, 03:31:10 pm »
@binary1248
In the past 3 years of programming , i have never used a debugger.  I have always used print statements to determine a value. I attempted to figure out how to use the debugger in Geany IDE, but i couldnt figure the process out.
Well then... it's about time you started to use one ;). These things can be solved so easily if you use one. Never used Geany's debugger, but Code::Blocks has nice gdb integration, so you can try that if Geany doesn't work for you.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).