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

Author Topic: ConvexShape and its getPosition  (Read 1800 times)

0 Members and 1 Guest are viewing this topic.

Demir

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
ConvexShape and its getPosition
« on: May 28, 2013, 10:23:05 am »
Hello

I'm trying to make this:

draw(convexshape with 4 points)
getBounds
getPosition
draw(rectangle) //frame arround convex sahpe
 

If convexshape's first coordinate is different from "0" then getPosition returns (pos - firstCoord).

is it normal behaviour ?

rect.setPosition(shape.getPosition());


[/code]


#include <SFML/Graphics.hpp>

int main ()
{
    sf::ConvexShape shape(4);
    shape.setFillColor(sf::Color::Red);

    sf::RectangleShape rect;
    rect.setFillColor(sf::Color::Green);

    shape.setPoint(0, sf::Vector2f(40,50));
    //shape.setPoint(0, sf::Vector2f(0,0));
    shape.setPoint(1, sf::Vector2f(140,60));
    shape.setPoint(2, sf::Vector2f(150,250));
    shape.setPoint(3, sf::Vector2f(30,240));

    shape.setPosition(200, 200);

    rect.setSize(sf::Vector2f(shape.getGlobalBounds().width, shape.getGlobalBounds().height));
    rect.setPosition(shape.getPosition());

    sf::RenderWindow window(sf::VideoMode(800, 600), "ConvexShape");
    sf::Event event;

    while (window.isOpen()) {
        while (window.pollEvent(event)) {
            switch (event.type) {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::KeyPressed:
                window.close();
                break;
            }
        }

        window.clear();
        window.draw(rect);
        window.draw(shape);
        window.display();
    }
}
« Last Edit: May 28, 2013, 12:16:30 pm by Demir »

Demir

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: ConvexShape and its getPosition
« Reply #1 on: May 28, 2013, 12:03:01 pm »
I think this way is right ... :-\

    rect.setPosition(
                     sf::Vector2f(
                                  shape.getGlobalBounds().left,
                                  shape.getGlobalBounds().top
//                                  shape.getPosition().x + shape.getLocalBounds().left,
//                                  shape.getPosition().y + shape.getLocalBounds().top
                                  )
                     );
 
« Last Edit: May 28, 2013, 12:04:57 pm by Demir »