Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

trying to graph a mathematical function using a sf::vertexArray that contains sf::Quads, but my quads do not display correctly

In my constructor I have:

function.setPrimitiveType(sf::Quads);
numOfPoints = ((XUpperLimit - XLowerLimit) / .001) * 4;
function.resize(numOfPoints);

and my graph function:

void Window::graphFunction() {
    double YVal;

    for (double XVal = XLowerLimit, index = 0.0; XVal < XUpperLimit; XVal += 0.001, index += 4) {
        YVal = tan(XVal);
        if (YVal > YUpperLimit || YVal < YLowerLimit) {
            continue;
        }

        function[index].position = sf::Vector2f((XOrigin + XVal * 20) - 3.f, (YOrigin - YVal * 20) - 3.f);
        function[index + 1].position = sf::Vector2f((XOrigin + XVal * 20) + 3.f, (YOrigin - YVal * 20) - 3.f);
        function[index + 2].position = sf::Vector2f((XOrigin + XVal * 20) - 3.f, (YOrigin - YVal * 20) + 3.f);
        function[index + 3].position = sf::Vector2f((XOrigin + XVal * 20) + 3.f, (YOrigin - YVal * 20) + 3.f);
    }
}

And it looks like this: Output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can see each Quad has a triangle cut out of it on the right side instead of it looking like a regular square.

>Solution :

From the documentation:

The 4 points of each quad must be defined consistently, either in clockwise or counter-clockwise order.

The ordering of your points do not satisfy this requirement.

Swapping your first two coordinates would fix this.

Alternately, swapping the last two coordinates would also fix this.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading