Loading...
Logo
Processing Forum
goldenmaster's Profile
2 Posts
1 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    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:

    1. void branch(float h, float s) {
    2.   // Each branch will be H* the size of the previous one
    3.   h *= 0.66;
    4.   s *= 0.75;
    5.   strokeWeight(s);

    6.   if (h > 30) {
    7.     //branch 1
    8.     pushMatrix();    // Save the current state of transformation (i.e. where are we now)
    9.     rotateX(thetaX);   // Rotate by theta
    10.     rotateY(thetaY);
    11.     rotateZ(thetaZ);

    12.     line(0, 0, 0, -h);  // Draw the branch
    13.     translate(0, -h); // Move to the end of the branch
    14.     branch(h, s);       // Ok, now call myself to draw two new branches!!
    15.     popMatrix();     // Whenever we get back here, we "pop" in order to restore the previous matrix state

    16.     //branch 2
    17.     strokeWeight(s);
    18.     pushMatrix();
    19.     rotateX(-thetaX);
    20.     rotateY(-thetaY);
    21.     rotateZ(thetaZ);

    22.     line(0, 0, 0, -h);
    23.     translate(0, -h);
    24.     branch(h, s);
    25.     popMatrix();

    26.     //branch 3
    27.     strokeWeight(s);
    28.     pushMatrix();
    29.     rotateX(thetaX);
    30.     rotateY(-thetaY);
    31.     rotateZ(-thetaZ);

    32.     line(0, 0, 0, -h);
    33.     translate(0, -h);
    34.     branch(h, s);
    35.     popMatrix();
    36.   }
    37.   else {
    38.     fCount ++;
    39.     
    40.     flowersPos[fCount][0] = modelX(0,0,0);
    41.     flowersPos[fCount][1] = modelY(0,0,0);
    42.     flowersPos[fCount][2] = modelZ(0,0,0);

    43.     rotateX(flowerRots[fCount]);
    44.     strokeWeight(1);
    45.     drawPolyFlower(flowerNums[fCount],h/2);
    46.     if (fCount > hiFCount) {
    47.       hiFCount = fCount;
    48.     }
    49.   }
    50. }

    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!
    Hi everyone, this is my first post here. 

    I've been working on a project where I have a bunch of geometric objects in 3d space that are made up of groups of polygons kind of mashed together.  I got everything working fine, and wanted to take the next step and start playing with texture maps, but I was unable to get the texture mapping to work.  The color of the object would change but the texture would just not show up.

    any ideas?

    Here's the code, thanks!

    PImage tmap;

    void setup() {
      size(640, 360, P3D);
      tmap = loadImage("texture1.jpg");
      noStroke();
    }

    void draw() {
      background(0);
      translate(width / 2, height / 2);
      rotateY(map(mouseX, 0, width, -PI, PI));
      rotateZ(PI/6);
      drawPoly(5,200);
    }

    void drawPoly(int numSides, float radius){
      float angle = 2*PI/numSides;
      float[][] pointArray = new float[numSides][2];
      for(int i=0; i<numSides; i++){
        pointArray[i][0] = radius * sin(angle*i);
      }
        for(int i=0; i<numSides; i++){
        pointArray[i][1] = radius * cos(angle*i);
      }
      beginShape();
      for(int i=0; i<numSides; i++){
        texture(tmap);
        vertex(pointArray[i][0], pointArray[i][1]);
      }
      endShape();
    }