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

Pages: [1]
1
Graphics / Re: How does sf::Shape work?
« on: January 27, 2016, 07:54:53 pm »
Hi, Thanks but I'm not trying to create any new shape, my class does not inherits from sf::Shape but from sf::Drawable only and I want it to stay this way. I render with RenderTarget.draw(vertices[]...). I just wonder for what  the center and the repeated point is, my shape seems to work fine without them but I don't want to have any problems later

2
Graphics / How does sf::Shape work?
« on: January 27, 2016, 07:42:48 pm »
Hi guys I'm trying to create my own version of sf::Shape for more specific needs.

I had a look at the source and I don't understand the following:
void sf::Shape::update()
 [...]
    m_vertices.resize(count + 2); // + 2 for center and repeated first point

    // Position
    for (std::size_t i = 0; i < count; ++i)
        m_vertices[i + 1].position = getPoint(i);
    m_vertices[count + 1].position = m_vertices[1].position;

    // Update the bounding rectangle
    m_vertices[0] = m_vertices[1]; // so that the result of getBounds() is correct
    m_insideBounds = m_vertices.getBounds();

    // Compute the center and make it the first vertex
    m_vertices[0].position.x = m_insideBounds.left + m_insideBounds.width / 2;
    m_vertices[0].position.y = m_insideBounds.top + m_insideBounds.height / 2;
[...]
 
In my shape class I have the bounding rect already calculated but I guess it's here for texture mapping and other features, what I want to ask is why you need the point in the center? Is it required? I've played with my raw vertices and it seems to work fine without it. Same with the "first repeated point" why do you need it? Can I have a polygon or circle just from "raw" vertices and render it with sf::PrimitiveType::TriangleFan and have it work fine?

Pages: [1]
anything