Question

Hey guys, i have gotten my basic L-System working and i decided to try and optimize the rendering of the application. Previous i was looping through the whole string of the L-System with a switch case and drawing...better yet i will show you what i was doing.

for(unsigned int stringLoop = 0; stringLoop < _buildString.length(); stringLoop++)
{

        switch(_buildString.at(stringLoop))
        {
        case'X':
            //Do Nothing
            //X is there just to facilitate the Curve of the plant
            break;
        case'F':

            _prevState = _currState;
            _currState.position += _currState.direction * stdBranchLength; 
            //Set the previous state to the current state
            _graphics.SetColour3f(0.0f, 1.0f, 0.0f);

            _graphics.Begin(OGLFlags::LINE_STRIP);
                _graphics.Vertex3f(_prevState.position.X(), _prevState.position.Y(), _prevState.position.Z());
                _graphics.Vertex3f(_currState.position.X(), _currState.position.Y(), _currState.position.Z());
            _graphics.End();

            break;
        case'[':
            _prevStack.push(_currState);
            break;
        case']':
            _prevState = _currState;
            _currState = _prevStack.top();
            _prevStack.pop();               
            break;
        case'-':

            _currState.direction = _currState.direction.RotatedAboutZ(-(ROTATION) * Math::DegreesToRadians);

            break;
        case'+':
            _currState.direction = _currState.direction.RotatedAboutZ(ROTATION * Math::DegreesToRadians);

            break;
        };

}

I removed all of this because i was literally resolving the tree every single Frame, i changed this loop so that it would save all of the verticies in a std vector.

    for(unsigned int stringLoop = 0; stringLoop < _buildString.length(); stringLoop++)
{

        switch(_buildString.at(stringLoop))
        {
        case'X':
            break;
        case'F':

            //_prevState = _currState;
            _currState.position += _currState.direction * stdBranchLength;
            _vertexVector.push_back(_currState.position);

            break;
        case'[':
            _prevStack.push(_currState);
            break;
        case']':
            _currState = _prevStack.top();
            _prevStack.pop();               
            break;
        case'-':            
            _currState.direction = _currState.direction.RotatedAboutZ(-(ROTATION) * Math::DegreesToRadians);
            break;
        case'+':
            _currState.direction = _currState.direction.RotatedAboutZ(ROTATION * Math::DegreesToRadians);
            break;
        };
}

Now i changed my render loop so i just read straight from the vector array.

    DesignPatterns::Facades::OpenGLFacade _graphics = DesignPatterns::Facades::openGLFacade::Instance();

_graphics.Begin(OGLFlags::LINE_STRIP);
    for(unsigned int i = 0; i < _vertexVector.size(); i++)
    {
        _graphics.Vertex3f(_vertexVector.at(i).X(), _vertexVector.at(i).Y(), _vertexVector.at(i).Z());
    }
_graphics.End();

Now my problem is that when i am using a vector array and i use Line Stip i get extra artifact. The first image is the original render that is the unoptimized one, then the second is the newer render which runs faster, and the thirds is a render of a dragon curve which uses no push and pops like the first two are using (I am pretty sure the push and pop is where the problems are coming in). Is the problem with my logic here of storing verticies, or is it because i am using a line strip? I would just use lines, but it doesn't really work at all, it ends up looking more of a line_stipple. Also sorry about the length of this post.

alt text http://img197.imageshack.us/img197/8030/bettera.jpg alt text http://img23.imageshack.us/img23/3924/buggyrender.jpg alt text http://img8.imageshack.us/img8/627/dragoncurve.jpg

Was it helpful?

Solution

You are getting those extra lines because you are using a LINE_STRIP.

In your 'F' case, push both end points of your line into the vector (like you were doing originally).

_vertexVector.push_back(_prevState.position);
_vertexVector.push_back(_currState.position);

And when you draw, use LINE_LIST instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top