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

Author Topic: sf::Line(int x1, int y1, int x2, int y2)  (Read 21581 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3364
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Line(int x1, int y1, int x2, int y2)
« Reply #15 on: April 28, 2016, 01:05:32 am »
Alright... So you're saying that if I want to create a line (the most basic shape) in SFML (a library centered around GRAPHICS) I have to use another library or create the sf::LineShape class myself?
No.
Firstly, the "library" that I mentioned contains pretty much self-contained classes that can be used without the rest of the library; you can just copy and paste and use individual classes.
Secondly, I also mentioned that there are line classes in the SFML wiki that can just be copied directly.

[T]hey are just rotated rectangles.
[...]
[M]aybe a better option would be to provide alternative ways to build a rectangle?
This makes a lot of sense.
Why is a thick line called a line? It is because of the controls to manipulate it are different.
Creation of a line rectangle would require the positions of the centres of opposition sides and the width (or height) of the rectangle. However, just creation is not enough; it must be able to be moved in this way too (imagine moving one point of a line, for example).

The main issue with creating a line using sf::RectangleShape is that you can't define the start position and the end position. It's very arkward to rotate a sf::RectangleShape to do that.
...
This abstracts away the whole having to create a rectangle, get the right angle and length so it starts at 23, 74 and ends at 163, 293, then creating two other rectangles and rotating them at the right angle so they make an arrow. And then having to create two circles or something at the end of the rectangle so that it has smooth ends. This gets tedious and sf::LineShape is much quicker and easier. Otherwise using a sf::RectangleShape to create this would be bordering on impossible.
I don't think that using a rectangle shape to create a line is a lot of work.
See here.

One thing you mentioned here is that you think that lines should have rounded edges which is a completely new thing entirely (technically, a rounded rectangle, which, by the way, is also available in the SFML wiki).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

R23MJ

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: sf::Line(int x1, int y1, int x2, int y2)
« Reply #16 on: May 03, 2016, 03:36:34 pm »
I don't have much to add here; however a line class could be useful for something like raycasting, for arrows or the such, or as a tool to measure distance, (someLine.getLength()). This is a completely different topic though, implementing it like that would make it more of a utility then a shape, and I don't think that is what the OP really wanted. Anyways, just my two cents.

Zamadatix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: sf::Line(int x1, int y1, int x2, int y2)
« Reply #17 on: May 24, 2016, 10:20:29 pm »
So, to make it clear, the proposal is to add this:
sf::Line line(x1, y1, x2, y2);
line.setFillColor(color);
window.draw(line);

... to avoid writing this:
sf::Vertex line[] = {{{x1, y1}, color}, {{x2, y2}, color}};
window.draw(line, sf::Lines);

Is it really worth it? (real question, I personally don't know)

Just chiming in to say I think it has value. It shouldn't be about code golf or the difficultly to manually implement, the point is to provide consistency in SFML for the base set of shapes and if a line isn't included in the base set of shapes it's all quite arbitrary that anything is in my opinion.

If  I don't care much one way or the other on the line thickness debate, I think it leads into a "how many style options should we add to the base shapes" argument more than it leads to any added value on the "should there be a line shape" argument.