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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Jerome96

Pages: [1]
1
Graphics / Re: Problem with shapes
« on: July 28, 2014, 01:09:25 pm »
Why not using a sf::VertexArray, which inherits from sf::Transformable and sf::Drawable, like shown here or just use a sf::Transform like shown above?

I am not sure which sf::PrimitiveType I should use for my
arrow. Any suggestions?

Have you checked with a debugger what the coordinates are, and why they are wrong?

I will check that and send you the coordinates and some pictures.

Thank you anyway :)

2
Graphics / Problem with shapes
« on: July 27, 2014, 06:39:55 pm »
Hello everyone  :)

I am trying too create an arrow. I could not create it with sf::ConvexShape because it is not a convex shape. So I decided to split it up in a head part and a end part.
For the head part I chose sf::ConvexShape and for the end part sf:RectangleShape.

I tried to put them together and rotated them but I didn't get the right solution.

Here is the code:

void Interaction::createArrow(Object *from_object, Object *to_object)
{
        float x_from = from_object->getX();
        float y_from = from_object->getY();
        float x_to = to_object->getX();
        float y_to = to_object->getY();
        float x_dif = x_to - x_from;
        float y_dif = y_to - y_from;
        float length = sqrt(x_dif * x_dif + y_dif * y_dif);
        float angle = atan2(y_dif,x_dif) * 180 / PI;
       
        shape_end = sf::RectangleShape(sf::Vector2f(length-10,4));
        sf::Rect<float> rect = shape_end.getLocalBounds();
        shape_end.setOrigin(rect.left,rect.top);

        shape_head.setPointCount(7);
        shape_head.setOrigin(0,0);
        shape_head.setPoint(0,sf::Vector2f(10,10));
        shape_head.setPoint(1,sf::Vector2f(17,25));
        shape_head.setPoint(2,sf::Vector2f(12,15));
        shape_head.setPoint(3,sf::Vector2f(12,30));
        shape_head.setPoint(4,sf::Vector2f(8,30));
        shape_head.setPoint(5,sf::Vector2f(8,15));
        shape_head.setPoint(6,sf::Vector2f(3,25));
        shape_head.rotate(90);

        float x_origin = -(shape_head.getLocalBounds().left + shape_head.getLocalBounds().width+x_dif);
        float y_origin = -(shape_head.getLocalBounds().top + shape_head.getLocalBounds().height/2+y_dif);
        shape_head.setOrigin(x_origin,y_origin);
        shape_head.rotate(angle);
        shape_end.rotate(angle);

        shape_head.setOrigin(7,10);
        shape_end.setPosition(x_from,y_from);
        shape_head.setPosition(x_to,y_to);
}

I try to rotate the arrow so that it is pointing from the (x_from|y_from) to the (x_to|y_to) point. But the arrow head is always a little bit deferred.
What did I miss?

Thank you for your help :D

Pages: [1]
anything