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

Author Topic: Promlem with sf::Shape  (Read 1254 times)

0 Members and 1 Guest are viewing this topic.

JoseMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Promlem with sf::Shape
« 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:


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:


But what I expect and want is this:


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 :)
« Last Edit: July 15, 2016, 10:31:16 am by JoseMan »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Promlem with sf::Shape
« Reply #1 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...
Laurent Gomila - SFML developer

JoseMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Promlem with sf::Shape
« Reply #2 on: July 15, 2016, 11:01:42 am »

damn!! Okay. Thanks :)
But what can I do to get the result I want to have.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Promlem with sf::Shape
« Reply #3 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)
Laurent Gomila - SFML developer

JoseMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Promlem with sf::Shape
« Reply #4 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