Loading...
Logo
Processing Forum
Hi!

Which is the best way to draw a nurbs landscape?

drawing it using vertex or using igeo-library? have done mostly stuff in 2D so far in processing ... which would be the easisest and best way to get going building nurbslandscapes and surfaces?

Replies(2)

I tried to edit this from Daniel Shiffmans example from nature of code.

But is it any way of smoothing out the the colors in the nurb? so it doesnt appears so pixelated?


Copy code
  1. Landscape land;   
  2. float theta = 0.5;
  3. void setup() {
  4.   size(400, 400, P3D);
  5.   // Create a landscape object
  6.   land = new Landscape(20, 400, 400);
  7. }
  8. void draw() {
  9.   background(255);
  10.   pushMatrix();
  11.   translate(width/2, height/2+20, -160);
  12.   lights();
  13.   //  rotateX(PI/3);
  14.   rotateZ(theta);
  15.   land.render();
  16.   popMatrix();
  17.   land.calculate();
  18. }

  19. class Landscape {
  20.   int scl;           // size of each cell
  21.   int w, h;           // width and height of thingie
  22.   int rows, cols;    // number of rows and columns
  23.   float zoff = 0.0;  // perlin noise argument
  24.   float[][] z;       // using an array to store all the height values
  25.   Landscape(int scl_, int w_, int h_) {
  26.     scl = scl_;
  27.     w = w_;
  28.     h = h_;
  29.     cols = w/scl;
  30.     rows = h/scl;
  31.     z = new float[cols][rows];
  32.   }
  33.   // Calculate height values (based off a neural netork)
  34.   void calculate() {
  35.     float xoff = 0;
  36.     for (int i = 0; i < cols; i++)
  37.     {
  38.       float yoff = 0;
  39.       for (int j = 0; j < rows; j++)
  40.       {
  41.         z[i][j] = map(noise(xoff, yoff, zoff), 0, 1, -120, 120);
  42.         yoff += 0.1;
  43.       }
  44.       xoff += 0.1;
  45.     }
  46.     zoff+=0.01;
  47.   }
  48.   // Render landscape as grid of quads
  49.   void render() {
  50.     // Every cell is an individual quad
  51.     // (could use quad_strip here, but produces funny results, investigate this)
  52.     for (int x = 0; x < z.length-1; x++)
  53.     {
  54.       for (int y = 0; y < z[x].length-1; y++)
  55.       {
  56.         // one quad at a time
  57.         // each quad's color is determined by the height value at each vertex
  58.         // (clean this part up)
  59.         noStroke();
  60.         pushMatrix();
  61.         beginShape(QUADS);
  62.         fill(255, 0, 0);
  63.         // translate sprider ut quad med x * storleken
  64.         translate(x*scl-w/2, y*scl-h/2, 0);
  65.         vertex(0, 0, z[x][y]);
  66.         vertex(scl, 0, z[x+1][y]);
  67.         vertex(scl, scl, z[x+1][y+1]);
  68.         vertex(0, scl, z[x][y+1]);
  69.         endShape();
  70.         popMatrix();
  71.       }
  72.     }
  73.   }
  74. }





those colours, i think, are a function of the lighting. there's nothing in the code other than the one fill command (red) so the shades are to do with the angle of the tiny planes that make up the surface and the limited range of angles of these planes that are possible given the movement.

not sure of a way around this. play around with type and positioning of lights?