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

Author Topic: Shape vs. Window coordinates  (Read 3879 times)

0 Members and 1 Guest are viewing this topic.

sherlok

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shape vs. Window coordinates
« on: October 09, 2009, 10:15:36 pm »
I did some searching and didn't see anything that directly addressed this  - if I missed something obvious, sorry I'm new.

Basically I'm simply drawing a sprite on the screen (moving it around). However I'm noticing it's position looks off (I know I'm definitely missing something).

So I create a window
Code: [Select]
Win.Create(sf::VideoMode(600, 800, 32), "Test");

Then I basically loop and draw my shape:

Code: [Select]

//In the constructor
circle = sf::Shape::Circle(posX, posY, 5, sf::Color(255, 0, 0, 255));

//In my draw function
//...do some position calculations:
circle.SetPosition(posX, posY);


The problem here, is if I set the posX, posY to 0,0 - then it drops the sprite in the top left as expected.

However putting it at 600,800 moves it off the screen.

In fact, drawing it at 300,400 puts it at the bottom right of my window.

Now I wouldn't be so weirded out about this if it didn't display a 600x800 background image entirely. So I'd expect the coordinates to line up.

I was just wondering why? Can this be fixed with a view? If I move the view out so that 600x800 is indeed the bottom right, won't that mess up my background image (since it fits teh window perfectly now)?

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Shape vs. Window coordinates
« Reply #1 on: October 10, 2009, 01:05:09 am »
Quote from: "sherlok"
In fact, drawing it at 300,400 puts it at the bottom right of my window.

That should not happen. Can you post a screenshot?

sherlok

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shape vs. Window coordinates
« Reply #2 on: October 10, 2009, 01:22:24 am »
Thanks for the response

Hopefully this is what you're asking for. I shrunk the images down and removed everything except for a red dot which you can see at either location and blacked out the background to make it more visible. The code given is done on creation of the shape object and then I just use shape.SetPosition(posX, posY) in my update loop (posX and posY are currently constant values).

I confirmed that the image is indeed 600x800.

Here's my window initialization stuff:
Code: [Select]

DEBUG_PRINT("Initializing Test...")
    DEBUG_PRINT("Loading Images...")
    m_ImageManager.addImage("background", "../assets/see/scenery/mock_test.png");
    m_ImageManager.addImage("pointer", "../assets/see/scenery/Pointer.png");
    m_testBack.SetImage(*m_ImageManager.getImage("background"));
    m_testPointer.SetImage(*m_ImageManager.getImage("pointer"));
    DEBUG_PRINT("Initing Window...")
    Win.Create(sf::VideoMode(600, 800, 32), "Test");
    Win.ShowMouseCursor(false);


Code: [Select]

posX = 300;
posY = 400;
circle = sf::Shape::Circle(posX, posY, 5, sf::Color(255, 0, 0, 255));



Code: [Select]

posX = 0;
posY = 0;
circle = sf::Shape::Circle(posX, posY, 5, sf::Color(255, 0, 0, 255));


Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Shape vs. Window coordinates
« Reply #3 on: October 10, 2009, 03:29:07 am »
Yep, that's exactly what I was asking for. :)

Indeed you're doing nothing wrong so far. It looks like a bug. Or do you use an sf::View anywhere?

Without changing the origin or viewpoint, the circle should be at exactly 300, 400 like you specified.

sherlok

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shape vs. Window coordinates
« Reply #4 on: October 10, 2009, 04:17:50 am »
Nothing crazy with views, although I did mess with them in an attempt to fix things - didn't seem to work.

This is unfortunate, I'm not really doing anything crazy. Maybe I'll regrab and re-install, see if that does anything.

Thanks for the help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Shape vs. Window coordinates
« Reply #5 on: October 10, 2009, 11:01:03 am »
Can you show a complete and minimal example that reproduces this problem?
Laurent Gomila - SFML developer

sherlok

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shape vs. Window coordinates
« Reply #6 on: October 10, 2009, 02:37:57 pm »
Right, that would make sense, here you go.

The issue seems to be with setPosition(). If that gets commented out it works like it should. Maybe I'm misunderstanding how setposition works?

Code: [Select]

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

using namespace std;

int main()
{
    sf::RenderWindow Win;
    sf::Event m_event;
    bool running = true;
    sf::Shape circle = sf::Shape::Circle(300, 400, 5, sf::Color(255, 0, 0, 255));
    Win.Create(sf::VideoMode(600, 800, 32), "Debug");

    while(running)
    {
        while ( Win.GetEvent(m_event) )
        {
            if ( m_event.Type == sf::Event::Closed )
            {
                running = false;
            }
        }
        circle.SetPosition(300, 400);

        Win.Clear();
        Win.Draw(circle);
        Win.Display();

    }
    return 0;
}

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Shape vs. Window coordinates
« Reply #7 on: October 10, 2009, 03:42:01 pm »
You're creating the circle at 300, 400 and are moving it then to 300, 400, which makes an absolute position of 600, 800.

Code: [Select]
sf::Shape circle = sf::Shape::Circle(0, 0, 5, sf::Color(255, 0, 0, 255));

...should do the trick. ;)

sherlok

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shape vs. Window coordinates
« Reply #8 on: October 10, 2009, 03:51:24 pm »
Quote from: "Tank"
You're creating the circle at 300, 400 and are moving it then to 300, 400, which makes an absolute position of 600, 800.

Code: [Select]
sf::Shape circle = sf::Shape::Circle(0, 0, 5, sf::Color(255, 0, 0, 255));

...should do the trick. ;)


So it does, thanks a lot. It seem extremely obvious now.

I guess I expected it to set the position absolutely as opposed to using it as an offset.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Shape vs. Window coordinates
« Reply #9 on: October 10, 2009, 04:28:22 pm »
The positions used when creating shapes can be treated as offsets inside of a "canvas". It's not the sf::Drawable position, but the position of the points.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Shape vs. Window coordinates
« Reply #10 on: October 10, 2009, 06:37:43 pm »
The first two float in the Circle constructor define the center of your circle. ;)