Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Using ofNode to build an L-System

$
0
0

I think that the problem is in the copy of the ofNode. I've edited the previous code as follow, removing the pre-translation and using directly ofNode.

    ofNode root = ofNode();
    root.setPosition(450, 700, 0);
    auto branch = ofNode();
    branch.setParent(root);

    bool branching = false;

    string _instruction = "F+F+F";
    mesh.clear();

    for (int i = 0; i < _instruction.length(); i++) {
        char c = _instruction[i];
        if (c == 'F') {
            branching = true;
        }else if (c == '+') {
            branch.roll(25.0);
        }

        if(branching){
            if(mesh.getNumVertices() == 0){
                //add the first branch to the root
                branch.move(ofVec3f(0, -100, 0));
                cout << branch.getGlobalPosition().y << endl;
                mesh.addVertex(branch.getGlobalPosition());
                mesh.addColor(ofFloatColor(1.0, 1.0, 0.0));
                branching = false;
            }else{
                //add a new branch
                auto oldBranch = ofNode(branch);
                auto branch = ofNode();
                branch.setParent(oldBranch);
                branch.move(ofVec3f(0, -100,0));
                mesh.addVertex(branch.getGlobalPosition());
                mesh.addColor(ofFloatColor(1.0, 1.0, 0.0));
                branching = false;
            };
        }
    }

I think the problem is here

auto oldBranch = ofNode(branch);
auto branch = ofNode();
branch.setParent(oldBranch);

What I would like to do is that oldBranch save the position of branch accumulated until now, and auto branch = ofNode() create a new ofNode, re-assigning the value of branch. What is happening is that branch it is not re-assigned. It remains the same as at the beginning.
Some ideas?


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>