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 - z7x

Pages: [1]
1
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 16, 2024, 06:30:36 pm »


I have almost finished my polygon class. Actually, when I first looked at the ear clipping code in SelbaWard, I didn't understand anything. However, after watching the video in the link above, I realized how simple it actually is, and I tried to code it myself. The result was quite successful, and now I can draw shapes using both ear clipping and scanline algorithms. However, when the edges of the polygon overlap, the expected result is not achieved when drawn with ear clipping. In such cases, I have a few shapes where I compare the results of drawing with ear clipping and scanline algorithms. For example, when I try to draw some shapes with ear clipping, due to the overlapping edges, I exit the loop without fully filling the shape. I also checked if overlapping edges can be drawn with the scanline algorithm, but even though the scanline fills the interior most of the time, there can still be minor glitches. Additionally, I thought it would be silly to draw a simple square with the scanline, so adding ear clipping seemed quite logical, and now both of them work (except for the exceptions I mentioned). Furthermore, I have shared some visuals below regarding this matter. For instance, when you want to draw a crescent shape, you don't need to send 30-40 points to the polygon. I achieved this with just 3 points. To explain how it works, only 3 key points are sent, which determine the real identity of the polygon. Between these points, arcs are drawn at the angle you specify, and by sending only 3 points, we can draw based on the angles of the arcs between these 3 points. Features like this can be added, and instead of asking the user to reverse the corners based on whether they are clockwise or not, the polygon should calculate it based on the points sent. For example, if your calculations work counterclockwise, then let there be a function that calculates this, and if your calculations work counterclockwise and the polygon is calculated clockwise, then you can reverse the corners. Allowing the user to do this might result in a runtime error for novice coders like me. Other than that, that's all I have to say. I'll be closely following your developments.

https://drive.google.com/file/d/1FdalzQlJhhzCmc5OnFjEc7UAzxvsNkfg/view?usp=sharing

"Here is the visual representation. The shapes in the top row are drawn with the ear clipping algorithm, while the shapes in the bottom row are drawn with the scanline algorithm. The shapes are exactly the same; the only difference is the drawing methods. Take a close look at the differences between them."

2
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 14, 2024, 02:47:37 pm »
Yes, I'm aware of your spline feature, but I tend to think more about polygons when considering these features. Currently, I needed a polygon for my own GUI library, and since SelbaWard didn't fully meet my requirements, I created my own class. Now, I understand why there were two issues. Normally, when drawing scanline lines, I was shifting them by 1 pixel, but the scaling along the y-axis was messing it up. The reason was that I was drawing the corners with sf::Lines, and when scaling, the line size probably remained 1 pixel. So, instead of using lines to be filled during the drawing stage, I used sf::RectangleShape, and both issues were resolved. The difference is that when you create triangles, the scaling is probably automatically handled in pixels, but I had issues since I used 1-pixel sf::Lines. It seems it would be more appropriate to write the code in OpenGL for better performance anyway. Also, you mentioned that all complex shapes can be created with triangles, so I did a test. I set the points of the polygon to resemble a shape reminiscent of a butterfly, meaning imagine a 4-sided polygon with the second and fourth sides intersecting. Your code doesn't seem to handle such cases, or maybe you've addressed this separately. I'm still a novice in these matters. :)

I must say that SelbaWard is really good, but still, the polygon part didn't fully meet my needs. For example, the sent corner points are the essence of the polygon, and I needed features like rounding these corners inward and outward, as well as making the edges go by drawing arcs instead of straight lines between the corners. You probably understand what I mean; it's just that my requirements didn't quite align with the library's features. ;)

3
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 13, 2024, 04:35:38 pm »
Yes, as you mentioned, it worked when I tried it counterclockwise. However, I don't understand why I can't send the points clockwise. Also, since there is no outline and texture mapping, I had to do it myself, and since I'm not very familiar with the ear clipping method, I used the scanline algorithm, which seemed easier for me. The ear clipping algorithm creates shapes using triangles. So, is it possible to create all complex shapes using triangles? Currently, everything is progressing smoothly with the scanline, but I encounter some minor issues such as the lines appearing when changing the size of the screen along the y-axis and a slight color tone shift that I mentioned earlier. Besides these two issues, when I send points both clockwise and counterclockwise, it works, and since I've also managed the outline and texture mapping parts, I feel a bit relieved. Is it possible to configure Polygon to work both clockwise and counterclockwise? If possible, I would like to use the relevant code part of the algorithm in my own code. :)

4
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 09, 2024, 02:58:54 pm »
I solved this problem using the scan line algorithm, and everything is progressing as it should now. However, I encountered some minor issues. I tried drawing a few shapes of the same color, and while the shapes were drawn correctly, there was a difference in color tones. For example, I applied white color to both shapes, and while one shape appeared as it should, the other shape appeared as a darker shade of white. I realized that this was due to antialiasing. I had set the value to 4, and when I changed it back to 0, I got rid of this color tone difference, but then I encountered rough edges, of course. Is the scan line algorithm insufficient? I'm exploring other techniques for this, but the scan line seemed to be the easiest for me. What I'm curious about is, can I eliminate this problem with different polygon filling techniques?

5
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 03, 2024, 01:09:21 pm »
What I'm trying to do is allowing the user to input corner information as a percentage, and then I scale these percentage points using setSize() by multiplying each point with a scalar value. I want to draw inner and outer arcs between these scaled corners based on user preferences. Additionally, I'm rounding each corner both inward and outward, and I've handled all of this using trigonometric calculations. Everything is actually working fine; the only issue arises when drawing inner concave arcs. The problem occurs as the apex of the arc approaches the center of the shape. Interestingly, this problem is specific to inner concave arcs. Moreover, when I tried the code from GitHub, I encountered a runtime error. I wanted to provide more details, but I believe you've already understood the situation. :)

6
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 03, 2024, 12:57:33 pm »
I took the code from GitHub and tried it, but while there is no issue with the points used in the GitHub example, I encountered a runtime error when using the points in my own code. Does anyone have a better suggestion or solution for this?

7
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 02, 2024, 09:35:51 am »
Why doesn't SFML provide support for drawing both concave and convex shapes in a single entity, like a complex shape, instead of using convex shape? Is this related to the ear clipping algorithm you mentioned? It might be challenging for me to implement, and frankly, I don't have such an intention. Do you know of any other library that provides this support, and should I share this situation in the feature request section of SFML, or is there another appropriate channel for such requests

8
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 01, 2024, 02:52:18 pm »
What I'm trying to do here is to draw an inward-curved arc on the top edge of a square, but it seems I can't achieve this using convex shape. Is there another way to do this?

9
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 01, 2024, 02:46:19 pm »
I forgot to make the link public, it should be accessible now.
https://drive.google.com/file/d/1NQ3TmGzIDqNzuf2F6pHVJbfp4BtOjAMj/view?usp=sharing

10
Graphics / LineStrip VertexArray and ConvexShape problem
« on: February 01, 2024, 01:01:32 pm »
https://drive.google.com/file/d/1NQ3TmGzIDqNzuf2F6pHVJbfp4BtOjAMj/view?usp=sharing 
Hello, as you can see in the png file, I am creating a shape using 21 points with vertexarray as linestrip, and drawing it on the screen. The shape comes out exactly as I want when using linestrip, but when I apply the same points with convexShape, the shape doesn't come out as I expect. What could be the reason for this? Am I making a mistake somewhere? Here is my code.

int main()
{
    sf::RenderWindow window(sf::VideoMode(1366, 768), "testing",sf::Style::Default, sf::ContextSettings(0, 0, 8));

    std::vector<sf::Vector2f> points = style.getPoints();

    points.emplace_back(0, 0);
    points.emplace_back(0.851345, 9.18748);
    points.emplace_back(3.37638, 18.0621);
    points.emplace_back(7.48914, 26.3216);
    points.emplace_back(13.0495, 33.6848);
    points.emplace_back(19.8683, 39.9009);
    points.emplace_back(27.7131, 44.7582);
    points.emplace_back(36.3168, 48.0913);
    points.emplace_back(45.3866, 49.7867);
    points.emplace_back(54.6134, 49.7867);
    points.emplace_back(63.6831, 48.0913);
    points.emplace_back(72.2869, 44.7582);
    points.emplace_back(80.1317, 39.9009);
    points.emplace_back(86.9504, 33.6848);
    points.emplace_back(92.5109, 26.3216);
    points.emplace_back(96.6236, 18.0621);
    points.emplace_back(99.1487, 9.18748);
    points.emplace_back(100, 0);
    points.emplace_back(100, 100);
    points.emplace_back(0, 100);
    points.emplace_back(0, 0);

    sf::VertexArray va;
    va.setPrimitiveType(sf::PrimitiveType::LineStrip);
    va.resize(points.size());

    for (std::size_t i = 0; i < va.getVertexCount(); i++)
    {
        va[i].position = points[i];
    }

    sf::Transform ts1;
    ts1.translate(100, 200);

    sf::ConvexShape shape;
    shape.setPointCount(points.size());

    for (std::size_t i = 0; i < shape.getPointCount(); i++)
    {
        shape.setPoint(i, points[i]);
    }

    shape.setPosition(300, 200);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

       
        window.clear();

        window.draw(va, ts1);
        window.draw(shape);
       
        window.display();
    }

    return 0;
   
}

Pages: [1]
anything