SFML community forums

Help => Graphics => Topic started by: JoseMan on July 15, 2016, 10:24:53 am

Title: Promlem with sf::Shape
Post by: JoseMan on July 15, 2016, 10:24:53 am
Hello SFML-People,

I've got a problem.
I want to make a sound-visualizer.
So I wrote a shape-class which derived from sf::Shape.
I want to get something like this:
(https://picload.org/image/rraggprp/pic2.png)

I filled my shape with 70 points. All points in one x-row and all y-value are 0. Except from the 35th.
This point the y-value I set on 100.
But what I get is this:
(https://picload.org/image/rraggpdc/pic1.png)

But what I expect and want is this:
(https://picload.org/image/rraggpog/pic3.png)

Whats wrong?

Do you need source code?
My "MyShape"-Class:
MyShape::MyShape(const std::size_t& pointCount)
        : mPointCount(pointCount)
{
        mPoints.resize(pointCount);
}

MyShape::~MyShape()
{
}

std::size_t MyShape::getPointCount() const
{
        return mPointCount;
}

sf::Vector2f MyShape::getPoint(std::size_t index) const
{
        return mPoints[index];
}

void MyShape::setPoint(const unsigned int& index, const sf::Vector2f& point)
{
        mPoints[index] = point;
}
 

The using:
        const int convexPointCount = 70;
        mMyShape = new MyShape(convexPointCount);

        sf::Vector2f pointFirst(0, 0);
        mMyShape->setPoint(0, pointFirst);

        for (int index(1); index < convexPointCount-1; ++index)
        {
                sf::Vector2f point(index * 10, 0);
                mMyShape->setPoint(index, point);
        }

        sf::Vector2f pointLast( 69 * 10, 0);
        mMyShape->setPoint(69, pointLast);

        mMyShape->setPoint(35, sf::Vector2f(mMyShape->getPoint(35).x,100));
 

I hope you understand my problem...

Best regards :)
Title: Re: Promlem with sf::Shape
Post by: Laurent on July 15, 2016, 10:53:18 am
sf::Shape is made for convex shapes, as mentioned in the documentation and tutorial. By the way, your MyShape class is an exact copy of sf::ConvexShape...
Title: Re: Promlem with sf::Shape
Post by: JoseMan on July 15, 2016, 11:01:42 am

damn!! Okay. Thanks :)
But what can I do to get the result I want to have.
Title: Re: Promlem with sf::Shape
Post by: Laurent on July 15, 2016, 11:59:14 am
I see 3 possible solutions:
- thor::ConcaveShape
- manual decomposition into convex shapes
- draw many vertical lines instead of a shape (at worst you'll have ~2000 lines, which is ok)
Title: Re: Promlem with sf::Shape
Post by: JoseMan on July 15, 2016, 12:02:57 pm
Okay.
I'll take a look at thor::ConcaveShape, I think.

The Idea with the lines isn't so good I think.
Cause I want to do some texturing on the shape...

Thank you very much