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

Author Topic: [SOLVED] Drawing an Arrow  (Read 5403 times)

0 Members and 1 Guest are viewing this topic.

danthebeliever

  • Newbie
  • *
  • Posts: 10
    • View Profile
[SOLVED] Drawing an Arrow
« on: April 08, 2011, 05:11:58 pm »
Hello!

I am having trouble drawing an Arrow, mainly with the triangle.

This code draws a line and a Triangle between any two points, but the Triangle does not have the correct orientation (it is always the same). I thought that by rotating the Triangle it would fix this, but the rotation is not in place but about the origin.

Code: [Select]
sf::Shape Line = sf::Shape::Line(x1,y1,x2,y2,1,sf::Color::White);
sf::Shape Triangle;
float angle = 2 * PI/3;
float angle_rect = PI/2;
float d = 50;

for (int i = 0; i < 3; i++) {
Triangle.AddPoint(x2+d*sin(angle*i), y2+d*cos(angle*i), sf::Color::White);
}
App.Draw(Line);
sf::Vector2f av =Triangle.GetPosition();
App.Draw(Triangle);

(NOTE: this code does not have the rotation in it)
Any advice?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SOLVED] Drawing an Arrow
« Reply #1 on: April 08, 2011, 05:44:44 pm »
Quote
the rotation is not in place but about the origin

Yes, so there are two solutions:
- move the center of your triangle to make it match the geometrical center (SetCenter)
- create your triangle around the origin and set its position with SetPosition
Laurent Gomila - SFML developer

danthebeliever

  • Newbie
  • *
  • Posts: 10
    • View Profile
[SOLVED] Drawing an Arrow
« Reply #2 on: April 08, 2011, 06:28:17 pm »
Perfect, this works, thank you!