2

基本的なL-Systemが機能するようになり、アプリケーションのレンダリングを最適化することにしました。以前は、スイッチケースと描画を使用してL-Systemの文字列全体をループしていました。さらに良いことに、私が何をしていたかをお見せします。

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;
        };

}

文字通りすべてのフレームでツリーを解決していたため、これらすべてを削除しました。このループを変更して、すべての頂点をstdベクトルに保存するようにしました。

    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;
        };
}

次に、レンダリングループを変更したので、ベクトル配列から直接読み取ります。

    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();

ここでの問題は、ベクトル配列を使用していてLine Stipを使用すると、余分なアーティファクトが発生することです。

最初の画像は最適化されていない元のレンダリングであり、2番目はより高速に実行される新しいレンダリングであり、3番目は最初の2つが使用しているようにプッシュとポップを使用しないドラゴン曲線のレンダリングです(私はかなりですプッシュアンドポップが問題の発生源であることを確認してください)。

ここでの頂点の保存のロジックに問題がありますか、それともラインストリップを使用しているためですか?線を使用するだけですが、実際にはまったく機能せず、line_stippleのように見えてしまいます。

この投稿の長さについても申し訳ありません。

代替テキストhttp://img197.imageshack.us/img197/8030/bettera.jpg 代替テキストhttp://img23.imageshack.us/img23/3924/buggyrender.jpg 代替テキストhttp://img8.imageshack.us/ img8 / 627 / dragoncurve.jpg

4

1 に答える 1

3

LINE_STRIPを使用しているため、これらの余分な行を取得しています。

'F'の場合、線の両端をベクトルに押し込みます(最初に行っていたように)。

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

また、描画するときは、代わりにLINE_LISTを使用してください。

于 2009-06-22T00:22:46.380 に答える