SFML community forums

Help => Graphics => Topic started by: MenosGrandes on July 07, 2015, 07:13:33 pm

Title: L-System drawer
Post by: MenosGrandes on July 07, 2015, 07:13:33 pm
Hallo I have problem with drawing a L-System.
I have created a class that implementing base L-System, but I don't know how to draw it.
I have tried using sf::VertexArray with sf::LineStrip and sf::RectangleShape. In VertexArray I don't know how to rotate next line.

Any sugesstions?
Title: Re: L-System drawer
Post by: eXpl0it3r on July 07, 2015, 07:55:09 pm
How far did you actually "try"? I mean if you use vertices you obviously have to calculate the proper rotation yourself (maybe with use of an sf::Transform?). And what was the issue with rectangle shapes?

Since we don't know your system, all we can tell you is to draw something somehow. Maybe if you provide more information someone might be able to help further. Also don't assume that everybody just knows what an L-System is. ;)
Title: Re: L-System drawer
Post by: MenosGrandes on July 07, 2015, 10:03:52 pm
I have something like this:

float currentRotation=0;
float rotate=90;

sf::Vector2f currentPosition(0,0);

        m_vertices.setPrimitiveType(sf::LinesStrip);
        m_vertices.resize(initializer.length());
       // sf::Vertex* quad2 = &m_vertices[0];
        //m_vertices[0].position = currentPosition;

for(int i=0;i<initializer.length();i++)
{


    char sign=initializer[i];
    switch(sign)
    {
        case '+' :
            //std::cout<<" + ";
/* Rotate left*/
currentRotation+=rotate;

            break;
        case '-' :
            /* Rotate right*/
           // std::cout<<" - ";
currentRotation-=rotate;
            break;
        case 'F' :
           // std::cout<<" F ";
currentPosition.x+=1;
currentPosition.y+=1;
m_vertices[i].position = sf::Vector2f((currentPosition.x), (currentPosition.y));
//std::cout<<quad[i].position.x<<" "<<quad[i].position.y<<"\n";
            break;

    }

}
 

and I dont know how to calulate the rotation..
Title: Re: L-System drawer
Post by: kitteh-warrior on July 07, 2015, 11:18:23 pm
and I dont know how to calulate the rotation..

*cough* This (https://www.google.ca/search?q=calculate+rotation) may help you.
Title: Re: L-System drawer
Post by: MenosGrandes on July 08, 2015, 06:01:36 pm
I'm so dumb... thank you;)