Model X/Y/Z problem?
in
Programming Questions
•
3 years ago
Hi there,
I'm working on a 3d sketch where I draw an L-system tree and am trying to save the locations of the points at the termination of each branch. I am trying to get these points by using modelX,Y,Z but the behavior seems very wrong. It appears that there is a bug, as described in issue 148:
anyway, is anyone here aware of a workaround for this? the drawing I am doing relies heavily on matrix transforms. I think I could try and find some way to keep track of the position as I go along, but that seems somewhat difficult. In the picture below, the red cubes are drawn where the modelX function *reports* the terminal points on the branches should be.
the above is a link to the processing file. my general code for drawing the tree is based on the L-system tree code from the examples:
- void branch(float h, float s) {
- // Each branch will be H* the size of the previous one
- h *= 0.66;
- s *= 0.75;
- strokeWeight(s);
- if (h > 30) {
- //branch 1
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotateX(thetaX); // Rotate by theta
- rotateY(thetaY);
- rotateZ(thetaZ);
- line(0, 0, 0, -h); // Draw the branch
- translate(0, -h); // Move to the end of the branch
- branch(h, s); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
- //branch 2
- strokeWeight(s);
- pushMatrix();
- rotateX(-thetaX);
- rotateY(-thetaY);
- rotateZ(thetaZ);
- line(0, 0, 0, -h);
- translate(0, -h);
- branch(h, s);
- popMatrix();
- //branch 3
- strokeWeight(s);
- pushMatrix();
- rotateX(thetaX);
- rotateY(-thetaY);
- rotateZ(-thetaZ);
- line(0, 0, 0, -h);
- translate(0, -h);
- branch(h, s);
- popMatrix();
- }
- else {
- fCount ++;
- flowersPos[fCount][0] = modelX(0,0,0);
- flowersPos[fCount][1] = modelY(0,0,0);
- flowersPos[fCount][2] = modelZ(0,0,0);
- rotateX(flowerRots[fCount]);
- strokeWeight(1);
- drawPolyFlower(flowerNums[fCount],h/2);
- if (fCount > hiFCount) {
- hiFCount = fCount;
- }
- }
- }
that is the tree drawing function, and in the else{} code, it saves the position of each terminal branch to an array.
Thanks much for any insight!
1